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 ;
43 /* setup tooltips *//*
44 $j("a,.tt").each(function(){
47 if (e.hasClass("tttop")) pos="top";
48 if (e.hasClass("ttbottom")) pos="bottom";
49 if (e.hasClass("ttleft")) pos="left";
50 if (e.hasClass("ttright")) pos="right";
51 e.tipTip({defaultPosition: pos, edgeOffset: 8});
56 /* setup onoff widgets */
57 $j(".onoff input").each(function(){
59 id = $j(this).attr("id");
60 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
63 $j(".onoff > a").click(function(event){
64 event.preventDefault();
65 var input = $j(this).siblings("input");
66 var val = 1-input.val();
67 var id = input.attr("id");
68 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
69 $j("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
74 /* setup field_richtext */
75 /*setupFieldRichtext();*/
78 function close_last_popup_menu(e) {
80 if( last_popup_menu ) {
81 if( '#' + last_popup_menu.attr('id') !== $j(e.target).attr('rel')) {
82 last_popup_menu.hide();
83 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
84 last_popup_button.removeClass("selected");
85 last_popup_menu = null;
86 last_popup_button = null;
90 $j('img[rel^=#]').click(function(e){
92 close_last_popup_menu(e);
93 menu = $j( $j(this).attr('rel') );
97 if (menu.attr('popup')=="false") return false;
99 // $j(this).parent().toggleClass("selected");
102 if (menu.css("display") == "none") {
103 $j(this).parent().addClass("selected");
105 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').hide();
106 last_popup_menu = menu;
107 last_popup_button = $j(this).parent();
109 $j(this).parent().removeClass("selected");
111 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
112 last_popup_menu = null;
113 last_popup_button = null;
117 $j('html').click(function(e) {
118 close_last_popup_menu(e);
122 /*$j("a.popupbox").fancybox({
123 'transitionIn' : 'elastic',
124 'transitionOut' : 'elastic'
128 /* notifications template */
129 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
130 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
131 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
132 var notifications_empty = unescape($j("#nav-notifications-menu").html());
134 /* nav update event */
135 $j('nav').bind('nav-update', function(e,data){;
136 var invalid = $j(data).find('invalid').text();
137 if(invalid == 1) { window.location.href=window.location.href }
139 var net = $j(data).find('net').text();
140 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
141 $j('#net-update').html(net);
143 var home = $j(data).find('home').text();
144 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
145 $j('#home-update').html(home);
147 var intro = $j(data).find('intro').text();
148 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
149 $j('#intro-update').html(intro);
151 var mail = $j(data).find('mail').text();
152 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
153 $j('#mail-update').html(mail);
155 var intro = $j(data).find('intro').text();
156 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
157 $j('#intro-update-li').html(intro);
159 var mail = $j(data).find('mail').text();
160 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
161 $j('#mail-update-li').html(mail);
163 var eNotif = $j(data).find('notif')
165 if (eNotif.children("note").length==0){
166 $j("#nav-notifications-menu").html(notifications_empty);
168 nnm = $j("#nav-notifications-menu");
169 nnm.html(notifications_all + notifications_mark);
170 //nnm.attr('popup','true');
171 eNotif.children("note").each(function(){
173 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
174 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
178 notif = eNotif.attr('count');
180 $j("#nav-notifications-linkmenu").addClass("on");
182 $j("#nav-notifications-linkmenu").removeClass("on");
184 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
185 $j('#notify-update').html(notif);
187 var eSysmsg = $j(data).find('sysmsgs');
188 eSysmsg.children("notice").each(function(){
189 text = $j(this).text();
190 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
192 eSysmsg.children("info").each(function(){
193 text = $j(this).text();
194 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
201 // Allow folks to stop the ajax page updates with the pause/break key
202 /* $j(document).keydown(function(event) {
203 if(event.keyCode == '8') {
204 var target = event.target || event.srcElement;
205 if (!/input|textarea/i.test(target.nodeName)) {
209 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
210 event.preventDefault();
211 if(stopped == false) {
216 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
230 function NavUpdate() {
233 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
234 $j.get(pingCmd,function(data) {
235 $j(data).find('result').each(function() {
236 // send nav-update event
237 $j('nav').trigger('nav-update', this);
244 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
245 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
246 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
247 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
248 if($j('#live-display').length) { src = 'display'; liveUpdate(); }
249 /*if($j('#live-display').length) {
252 window.location.href=window.location.href
255 if($j('#live-photos').length) {
258 window.location.href=window.location.href
268 timer = setTimeout(NavUpdate,updateInterval);
271 function liveUpdate() {
272 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
273 if(($j('.comment-edit-text-full').length) || (in_progress)) {
275 clearTimeout(livetime);
277 livetime = setTimeout(liveUpdate, 10000);
283 prev = 'live-' + src;
286 var udargs = ((netargs.length) ? '/' + netargs : '');
287 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
289 $j.get(update_url,function(data) {
291 // $j('.collapsed-comments',data).each(function() {
292 // var ident = $j(this).attr('id');
293 // var is_hidden = $j('#' + ident).is(':hidden');
294 // if($j('#' + ident).length) {
295 // $j('#' + ident).replaceWith($j(this));
297 // $j('#' + ident).hide();
303 $j('.toplevel_item',data).each(function() {
304 var ident = $j(this).attr('id');
306 if($j('#' + ident).length == 0 && profile_page == 1) {
307 $j('img',this).each(function() {
308 $j(this).attr('src',$j(this).attr('dst'));
310 $j('#' + prev).after($j(this));
313 // Find out if the hidden comments are open, so we can keep it that way
314 // if a new comment has been posted
315 var id = $j('.hide-comments-total', this).attr('id');
316 if(typeof id != 'undefined') {
317 id = id.split('-')[3];
318 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
321 $j('img',this).each(function() {
322 $j(this).attr('src',$j(this).attr('dst'));
324 //vScroll = $j(document).scrollTop();
325 $j('html').height($j('html').height());
326 $j('#' + ident).replaceWith($j(this));
328 if(typeof id != 'undefined') {
329 if(commentsOpen) showHideComments(id);
331 $j('html').height('auto');
332 //$j(document).scrollTop(vScroll);
340 // reset vars for inserting individual items
342 /*prev = 'live-' + src;
344 $j('.wall-item-outside-wrapper',data).each(function() {
345 var ident = $j(this).attr('id');
347 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
348 $j('img',this).each(function() {
349 $j(this).attr('src',$j(this).attr('dst'));
351 $j('#' + prev).after($j(this));
354 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
355 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
356 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
357 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
358 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
359 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
360 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
361 $j(this).attr('src',$j(this).attr('dst'));
367 $j('.like-rotator').hide();
370 $j('body').css('cursor', 'auto');
372 /* autocomplete @nicknames */
373 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
377 function collapseHeight(elems) {
378 var elemName = '.wall-item-body:not(.divmore)';
379 if(typeof elems != 'undefined') {
380 elemName = elems + ' ' + elemName;
382 $j(elemName).each(function() {
383 if($j(this).height() > 350) {
384 $j('html').height($j('html').height());
385 $j(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
386 $j(this).addClass('divmore');
387 $j('html').height('auto');
392 function imgbright(node) {
393 $j(node).removeClass("drophide").addClass("drop");
396 function imgdull(node) {
397 $j(node).removeClass("drop").addClass("drophide");
400 // Since our ajax calls are asynchronous, we will give a few
401 // seconds for the first ajax call (setting like/dislike), then
402 // run the updater to pick up any changes and display on the page.
403 // The updater will turn any rotators off when it's done.
404 // This function will have returned long before any of these
405 // events have completed and therefore there won't be any
406 // visible feedback that anything changed without all this
407 // trickery. This still could cause confusion if the "like" ajax call
408 // is delayed and NavUpdate runs before it completes.
410 function dolike(ident,verb) {
412 $j('#like-rotator-' + ident.toString()).show();
413 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
414 // if(timer) clearTimeout(timer);
415 // timer = setTimeout(NavUpdate,3000);
419 function dostar(ident) {
420 ident = ident.toString();
421 //$j('#like-rotator-' + ident).show();
422 $j.get('starred/' + ident, function(data) {
423 if(data.match(/1/)) {
424 $j('#starred-' + ident).addClass('starred');
425 $j('#starred-' + ident).removeClass('unstarred');
426 $j('#star-' + ident).addClass('hidden');
427 $j('#unstar-' + ident).removeClass('hidden');
430 $j('#starred-' + ident).addClass('unstarred');
431 $j('#starred-' + ident).removeClass('starred');
432 $j('#star-' + ident).removeClass('hidden');
433 $j('#unstar-' + ident).addClass('hidden');
435 //$j('#like-rotator-' + ident).hide();
439 function getPosition(e) {
440 var cursor = {x:0, y:0};
441 if ( e.touches[0].pageX || e.touches[0].pageY ) {
442 cursor.x = e.touches[0].pageX;
443 cursor.y = e.touches[0].pageY;
446 if( e.touches[0].clientX || e.touches[0].clientY ) {
447 cursor.x = e.touches[0].clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
448 cursor.y = e.touches[0].clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
451 if( e.touches[0].x || e.touches[0].y ) {
452 cursor.touches[0].x = e.touches[0].x;
453 cursor.touches[0].y = e.touches[0].y;
460 var lockvisible = false;
462 function lockview(event,id) {
463 event = event || window.event;
464 cursor = getPosition(event);
470 $j.get('lockview/' + id, function(data) {
471 $j('#panel').html(data);
472 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
478 function lockviewhide() {
483 function post_comment(id) {
486 $j('body').css('cursor', 'wait');
487 $j("#comment-preview-inp-" + id).val("0");
490 $j("#comment-edit-form-" + id).serialize(),
493 $j("#comment-edit-wrapper-" + id).hide();
494 $j("#comment-edit-text-" + id).val('');
495 var tarea = document.getElementById("comment-edit-text-" + id);
497 commentClose(tarea,id);
498 if(timer) clearTimeout(timer);
499 timer = setTimeout(NavUpdate,10);
502 window.location.href=data.reload;
511 function preview_comment(id) {
512 $j("#comment-preview-inp-" + id).val("1");
513 $j("#comment-edit-preview-" + id).show();
516 $j("#comment-edit-form-" + id).serialize(),
520 $j("#comment-edit-preview-" + id).html(data.preview);
521 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
530 function showHideComments(id) {
531 if( $j("#collapsed-comments-" + id).is(":visible")) {
532 $j("#collapsed-comments-" + id).hide();
533 $j("#hide-comments-" + id).html(window.showMore);
536 $j("#collapsed-comments-" + id).show();
537 $j("#hide-comments-" + id).html(window.showFewer);
538 collapseHeight("#collapsed-comments-" + id);
543 function preview_post() {
544 $j("#jot-preview").val("1");
545 $j("#jot-preview-content").show();
546 tinyMCE.triggerSave();
549 $j("#profile-jot-form").serialize(),
552 $j("#jot-preview-content").html(data.preview);
553 $j("#jot-preview-content" + " a").click(function() { return false; });
558 $j("#jot-preview").val("0");
564 // unpause auto reloads if they are currently stopped
567 $j('#pause').html('');
572 // Converts the binary representation of data to hex
575 // discuss at: http://phpjs.org/functions/bin2hex
576 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
577 // + bugfixed by: Onno Marsman
578 // + bugfixed by: Linuxworld
579 // * example 1: bin2hex('Kev');
580 // * returns 1: '4b6576'
581 // * example 2: bin2hex(String.fromCharCode(0x00));
583 var v,i, f = 0, a = [];
587 for (i = 0; i<f; i++) {
588 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
594 function groupChangeMember(gid, cid, sec_token) {
595 $j('body .fakelink').css('cursor', 'wait');
596 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
597 $j('#group-update-wrapper').html(data);
598 $j('body .fakelink').css('cursor', 'auto');
602 function profChangeMember(gid,cid) {
603 $j('body .fakelink').css('cursor', 'wait');
604 $j.get('profperm/' + gid + '/' + cid, function(data) {
605 $j('#prof-update-wrapper').html(data);
606 $j('body .fakelink').css('cursor', 'auto');
610 function contactgroupChangeMember(gid,cid) {
611 $j('body').css('cursor', 'wait');
612 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
613 $j('body').css('cursor', 'auto');
618 function checkboxhighlight(box) {
619 if($j(box).is(':checked')) {
620 $j(box).addClass('checkeditem');
623 $j(box).removeClass('checkeditem');
627 function notifyMarkAll() {
628 $j.get('notify/mark/all', function(data) {
629 if(timer) clearTimeout(timer);
630 timer = setTimeout(NavUpdate,1000);
635 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
636 function fcFileBrowser (field_name, url, type, win) {
637 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
638 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
639 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
642 var cmsURL = baseurl+"/fbrowser/"+type+"/";
644 tinyMCE.activeEditor.windowManager.open({
646 title : 'File Browser',
647 width : 420, // Your dimensions may differ - toy around with them!
650 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
651 close_previous : "no"
659 function setupFieldRichtext(){
662 mode : "specific_textareas",
663 editor_selector: "fieldRichtext",
664 plugins : "bbcode,paste, inlinepopups",
665 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
666 theme_advanced_buttons2 : "",
667 theme_advanced_buttons3 : "",
668 theme_advanced_toolbar_location : "top",
669 theme_advanced_toolbar_align : "center",
670 theme_advanced_blockformats : "blockquote,code",
671 paste_text_sticky : true,
672 entity_encoding : "raw",
673 add_unload_trigger : false,
674 remove_linebreaks : false,
675 force_p_newlines : false,
676 force_br_newlines : true,
677 forced_root_block : '',
679 content_css: baseurl+"/view/custom_tinymce.css",
680 theme_advanced_path : false,
681 file_browser_callback : "fcFileBrowser",
687 * sprintf in javascript
688 * "{0} and {1}".format('zero','uno');
690 String.prototype.format = function() {
691 var formatted = this;
692 for (var i = 0; i < arguments.length; i++) {
693 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
694 formatted = formatted.replace(regexp, arguments[i]);
699 Array.prototype.remove = function(item) {
700 to=undefined; from=this.indexOf(item);
701 var rest = this.slice((to || from) + 1 || this.length);
702 this.length = from < 0 ? this.length + from : from;
703 return this.push.apply(this, rest);
706 function previewTheme(elm) {
707 theme = $j(elm).val();
708 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
709 $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>');