2 function openClose(theID) {
3 if(document.getElementById(theID).style.display == "block") {
4 document.getElementById(theID).style.display = "none"
7 document.getElementById(theID).style.display = "block"
11 function openMenu(theID) {
12 document.getElementById(theID).style.display = "block"
15 function closeMenu(theID) {
16 document.getElementById(theID).style.display = "none"
26 var totStopped = false;
30 var in_progress = false;
31 var langSelect = false;
32 var commentBusy = false;
33 var last_popup_menu = null;
34 var last_popup_button = null;
37 $j.ajaxSetup({cache: false});
39 msie = $j.browser.msie ;
41 /* setup tooltips *//*
42 $j("a,.tt").each(function(){
45 if (e.hasClass("tttop")) pos="top";
46 if (e.hasClass("ttbottom")) pos="bottom";
47 if (e.hasClass("ttleft")) pos="left";
48 if (e.hasClass("ttright")) pos="right";
49 e.tipTip({defaultPosition: pos, edgeOffset: 8});
54 /* setup onoff widgets */
55 $j(".onoff input").each(function(){
57 id = $j(this).attr("id");
58 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
61 $j(".onoff > a").click(function(event){
62 event.preventDefault();
63 var input = $j(this).siblings("input");
64 var val = 1-input.val();
65 var id = input.attr("id");
66 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
67 $j("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
72 /* setup field_richtext */
76 function close_last_popup_menu(e) {
78 if( last_popup_menu ) {
79 if( '#' + last_popup_menu.attr('id') !== $j(e.target).attr('rel')) {
80 last_popup_menu.hide();
81 last_popup_button.removeClass("selected");
82 last_popup_menu = null;
83 last_popup_button = null;
87 $j('a[rel^=#]').click(function(e){
89 close_last_popup_menu(e);
90 menu = $j( $j(this).attr('rel') );
94 if (menu.attr('popup')=="false") return false;
96 $j(this).parent().toggleClass("selected");
97 menu.slideToggle('fast');
99 if (menu.css("display") == "none") {
100 last_popup_menu = null;
101 last_popup_button = null;
103 last_popup_menu = menu;
104 last_popup_button = $j(this).parent();
108 $j('html').click(function(e) {
109 close_last_popup_menu(e);
113 $j("a.popupbox").fancybox({
114 'transitionIn' : 'none',
115 'transitionOut' : 'none'
119 /* notifications template */
120 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
121 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
122 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
123 var notifications_empty = unescape($j("#nav-notifications-menu").html());
125 /* nav update event */
126 $j('nav').bind('nav-update', function(e,data){;
127 var invalid = $j(data).find('invalid').text();
128 if(invalid == 1) { window.location.href=window.location.href }
130 var net = $j(data).find('net').text();
131 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
132 $j('#net-update').html(net);
134 var home = $j(data).find('home').text();
135 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
136 $j('#home-update').html(home);
138 var intro = $j(data).find('intro').text();
139 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
140 $j('#intro-update').html(intro);
142 var mail = $j(data).find('mail').text();
143 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
144 $j('#mail-update').html(mail);
146 var intro = $j(data).find('intro').text();
147 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
148 $j('#intro-update-li').html(intro);
150 var mail = $j(data).find('mail').text();
151 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
152 $j('#mail-update-li').html(mail);
154 var eNotif = $j(data).find('notif')
156 if (eNotif.children("note").length==0){
157 $j("#nav-notifications-menu").html(notifications_empty);
159 nnm = $j("#nav-notifications-menu");
160 nnm.html(notifications_all + notifications_mark);
161 //nnm.attr('popup','true');
162 eNotif.children("note").each(function(){
164 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
165 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
169 notif = eNotif.attr('count');
171 $j("#nav-notifications-linkmenu").addClass("on");
173 $j("#nav-notifications-linkmenu").removeClass("on");
175 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
176 $j('#notify-update').html(notif);
178 var eSysmsg = $j(data).find('sysmsgs');
179 eSysmsg.children("notice").each(function(){
180 text = $j(this).text();
181 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 2000 }); // originally: sticky: true,
183 eSysmsg.children("info").each(function(){
184 text = $j(this).text();
185 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1500 });
192 // Allow folks to stop the ajax page updates with the pause/break key
193 $j(document).keydown(function(event) {
194 if(event.keyCode == '8') {
195 var target = event.target || event.srcElement;
196 if (!/input|textarea/i.test(target.nodeName)) {
200 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
201 event.preventDefault();
202 if(stopped == false) {
207 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
221 function NavUpdate() {
224 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
225 $j.get(pingCmd,function(data) {
226 $j(data).find('result').each(function() {
227 // send nav-update event
228 $j('nav').trigger('nav-update', this);
235 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
236 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
237 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
238 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
239 if($j('#live-display').length) {
242 window.location.href=window.location.href
245 if($j('#live-photos').length) {
248 window.location.href=window.location.href
258 timer = setTimeout(NavUpdate,updateInterval);
261 function liveUpdate() {
262 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
263 if(($j('.comment-edit-text-full').length) || (in_progress)) {
265 clearTimeout(livetime);
267 livetime = setTimeout(liveUpdate, 10000);
273 prev = 'live-' + src;
276 var udargs = ((netargs.length) ? '/' + netargs : '');
277 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
279 $j.get(update_url,function(data) {
281 // $j('.collapsed-comments',data).each(function() {
282 // var ident = $j(this).attr('id');
283 // var is_hidden = $j('#' + ident).is(':hidden');
284 // if($j('#' + ident).length) {
285 // $j('#' + ident).replaceWith($j(this));
287 // $j('#' + ident).hide();
293 $j('.toplevel_item',data).each(function() {
294 var ident = $j(this).attr('id');
296 if($j('#' + ident).length == 0 && profile_page == 1) {
297 $j('img',this).each(function() {
298 $j(this).attr('src',$j(this).attr('dst'));
300 $j('#' + prev).after($j(this));
303 $j('img',this).each(function() {
304 $j(this).attr('src',$j(this).attr('dst'));
306 $j('#' + ident).replaceWith($j(this));
311 // reset vars for inserting individual items
313 /*prev = 'live-' + src;
315 $j('.wall-item-outside-wrapper',data).each(function() {
316 var ident = $j(this).attr('id');
318 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
319 $j('img',this).each(function() {
320 $j(this).attr('src',$j(this).attr('dst'));
322 $j('#' + prev).after($j(this));
325 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
326 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
327 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
328 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
329 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
330 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
331 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
332 $j(this).attr('src',$j(this).attr('dst'));
338 $j('.like-rotator').hide();
341 $j('body').css('cursor', 'auto');
343 /* autocomplete @nicknames */
344 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
346 var bimgs = $j(".wall-item-body > img").not(function() { return this.complete; });
347 var bimgcount = bimgs.length;
350 bimgs.load(function() {
364 function collapseHeight() {
365 $j(".wall-item-body").each(function() {
366 if($j(this).height() > 410) {
367 if(! $j(this).hasClass('divmore')) {
368 $j(this).divgrow({ initialHeight: 400, showBrackets: false, speed: 300 });
369 $j(this).addClass('divmore');
375 function imgbright(node) {
376 $j(node).removeClass("drophide").addClass("drop");
379 function imgdull(node) {
380 $j(node).removeClass("drop").addClass("drophide");
383 // Since our ajax calls are asynchronous, we will give a few
384 // seconds for the first ajax call (setting like/dislike), then
385 // run the updater to pick up any changes and display on the page.
386 // The updater will turn any rotators off when it's done.
387 // This function will have returned long before any of these
388 // events have completed and therefore there won't be any
389 // visible feedback that anything changed without all this
390 // trickery. This still could cause confusion if the "like" ajax call
391 // is delayed and NavUpdate runs before it completes.
393 function dolike(ident,verb) {
395 $j('#like-rotator-' + ident.toString()).show();
396 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
397 // if(timer) clearTimeout(timer);
398 // timer = setTimeout(NavUpdate,3000);
402 function dostar(ident) {
403 ident = ident.toString();
404 // $j('#like-rotator-' + ident).show();
405 $j.get('starred/' + ident, function(data) {
406 if(data.match(/1/)) {
407 $j('#starred-' + ident).addClass('starred');
408 $j('#starred-' + ident).removeClass('unstarred');
409 $j('#star-' + ident).addClass('hidden');
410 $j('#unstar-' + ident).removeClass('hidden');
413 $j('#starred-' + ident).addClass('unstarred');
414 $j('#starred-' + ident).removeClass('starred');
415 $j('#star-' + ident).removeClass('hidden');
416 $j('#unstar-' + ident).addClass('hidden');
418 // $j('#like-rotator-' + ident).hide();
422 function getPosition(e) {
423 var cursor = {x:0, y:0};
424 if ( e.pageX || e.pageY ) {
429 if( e.clientX || e.clientY ) {
430 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
431 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
443 var lockvisible = false;
445 function lockview(event,id) {
446 event = event || window.event;
447 cursor = getPosition(event);
453 $j.get('lockview/' + id, function(data) {
454 $j('#panel').html(data);
455 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
461 function lockviewhide() {
466 function post_comment(id) {
469 $j('body').css('cursor', 'wait');
470 $j("#comment-preview-inp-" + id).val("0");
473 $j("#comment-edit-form-" + id).serialize(),
476 $j("#comment-edit-wrapper-" + id).hide();
477 $j("#comment-edit-text-" + id).val('');
478 var tarea = document.getElementById("comment-edit-text-" + id);
480 commentClose(tarea,id);
481 if(timer) clearTimeout(timer);
482 timer = setTimeout(NavUpdate,10);
485 window.location.href=data.reload;
494 function preview_comment(id) {
495 $j("#comment-preview-inp-" + id).val("1");
496 $j("#comment-edit-preview-" + id).show();
499 $j("#comment-edit-form-" + id).serialize(),
503 $j("#comment-edit-preview-" + id).html(data.preview);
504 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
514 function preview_post() {
515 $j("#jot-preview").val("1");
516 $j("#jot-preview-content").show();
517 tinyMCE.triggerSave();
520 $j("#profile-jot-form").serialize(),
523 $j("#jot-preview-content").html(data.preview);
524 $j("#jot-preview-content" + " a").click(function() { return false; });
529 $j("#jot-preview").val("0");
535 // unpause auto reloads if they are currently stopped
538 $j('#pause').html('');
543 // Converts the binary representation of data to hex
546 // discuss at: http://phpjs.org/functions/bin2hex
547 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
548 // + bugfixed by: Onno Marsman
549 // + bugfixed by: Linuxworld
550 // * example 1: bin2hex('Kev');
551 // * returns 1: '4b6576'
552 // * example 2: bin2hex(String.fromCharCode(0x00));
554 var v,i, f = 0, a = [];
558 for (i = 0; i<f; i++) {
559 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
565 function groupChangeMember(gid, cid, sec_token) {
566 $j('body .fakelink').css('cursor', 'wait');
567 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
568 $j('#group-update-wrapper').html(data);
569 $j('body .fakelink').css('cursor', 'auto');
573 function profChangeMember(gid,cid) {
574 $j('body .fakelink').css('cursor', 'wait');
575 $j.get('profperm/' + gid + '/' + cid, function(data) {
576 $j('#prof-update-wrapper').html(data);
577 $j('body .fakelink').css('cursor', 'auto');
581 function contactgroupChangeMember(gid,cid) {
582 $j('body').css('cursor', 'wait');
583 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
584 $j('body').css('cursor', 'auto');
589 function checkboxhighlight(box) {
590 if($j(box).is(':checked')) {
591 $j(box).addClass('checkeditem');
594 $j(box).removeClass('checkeditem');
598 function notifyMarkAll() {
599 $j.get('notify/mark/all', function(data) {
600 if(timer) clearTimeout(timer);
601 timer = setTimeout(NavUpdate,1000);
606 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
607 function fcFileBrowser (field_name, url, type, win) {
608 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
609 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
610 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
613 var cmsURL = baseurl+"/fbrowser/"+type+"/";
615 tinyMCE.activeEditor.windowManager.open({
617 title : 'File Browser',
618 width : 420, // Your dimensions may differ - toy around with them!
621 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
622 close_previous : "no"
630 function setupFieldRichtext(){
633 mode : "specific_textareas",
634 editor_selector: "fieldRichtext",
635 plugins : "bbcode,paste, inlinepopups",
636 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
637 theme_advanced_buttons2 : "",
638 theme_advanced_buttons3 : "",
639 theme_advanced_toolbar_location : "top",
640 theme_advanced_toolbar_align : "center",
641 theme_advanced_blockformats : "blockquote,code",
642 paste_text_sticky : true,
643 entity_encoding : "raw",
644 add_unload_trigger : false,
645 remove_linebreaks : false,
646 force_p_newlines : false,
647 force_br_newlines : true,
648 forced_root_block : '',
650 content_css: baseurl+"/view/custom_tinymce.css",
651 theme_advanced_path : false,
652 file_browser_callback : "fcFileBrowser",
658 * sprintf in javascript
659 * "{0} and {1}".format('zero','uno');
661 String.prototype.format = function() {
662 var formatted = this;
663 for (var i = 0; i < arguments.length; i++) {
664 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
665 formatted = formatted.replace(regexp, arguments[i]);
670 Array.prototype.remove = function(item) {
671 to=undefined; from=this.indexOf(item);
672 var rest = this.slice((to || from) + 1 || this.length);
673 this.length = from < 0 ? this.length + from : from;
674 return this.push.apply(this, rest);
677 function previewTheme(elm) {
678 theme = $j(elm).val();
679 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
680 $j('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div><a href="' + data.img + '"><img src="' + data.img + '" width="320" height="240" alt="' + theme + '" /></a>');