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 */
73 /*setupFieldRichtext();*/
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 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
82 last_popup_button.removeClass("selected");
83 last_popup_menu = null;
84 last_popup_button = null;
88 $j('img[rel^=#]').click(function(e){
90 close_last_popup_menu(e);
91 menu = $j( $j(this).attr('rel') );
95 if (menu.attr('popup')=="false") return false;
97 // $j(this).parent().toggleClass("selected");
100 if (menu.css("display") == "none") {
101 $j(this).parent().addClass("selected");
103 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').hide();
104 last_popup_menu = menu;
105 last_popup_button = $j(this).parent();
107 $j(this).parent().removeClass("selected");
109 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
110 last_popup_menu = null;
111 last_popup_button = null;
115 $j('html').click(function(e) {
116 close_last_popup_menu(e);
120 /*$j("a.popupbox").fancybox({
121 'transitionIn' : 'elastic',
122 'transitionOut' : 'elastic'
126 /* notifications template */
127 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
128 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
129 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
130 var notifications_empty = unescape($j("#nav-notifications-menu").html());
132 /* nav update event */
133 $j('nav').bind('nav-update', function(e,data){;
134 var invalid = $j(data).find('invalid').text();
135 if(invalid == 1) { window.location.href=window.location.href }
137 var net = $j(data).find('net').text();
138 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
139 $j('#net-update').html(net);
141 var home = $j(data).find('home').text();
142 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
143 $j('#home-update').html(home);
145 var intro = $j(data).find('intro').text();
146 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
147 $j('#intro-update').html(intro);
149 var mail = $j(data).find('mail').text();
150 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
151 $j('#mail-update').html(mail);
153 var intro = $j(data).find('intro').text();
154 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
155 $j('#intro-update-li').html(intro);
157 var mail = $j(data).find('mail').text();
158 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
159 $j('#mail-update-li').html(mail);
161 var eNotif = $j(data).find('notif')
163 if (eNotif.children("note").length==0){
164 $j("#nav-notifications-menu").html(notifications_empty);
166 nnm = $j("#nav-notifications-menu");
167 nnm.html(notifications_all + notifications_mark);
168 //nnm.attr('popup','true');
169 eNotif.children("note").each(function(){
171 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
172 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
176 notif = eNotif.attr('count');
178 $j("#nav-notifications-linkmenu").addClass("on");
180 $j("#nav-notifications-linkmenu").removeClass("on");
182 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
183 $j('#notify-update').html(notif);
185 var eSysmsg = $j(data).find('sysmsgs');
186 eSysmsg.children("notice").each(function(){
187 text = $j(this).text();
188 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
190 eSysmsg.children("info").each(function(){
191 text = $j(this).text();
192 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
199 // Allow folks to stop the ajax page updates with the pause/break key
200 /* $j(document).keydown(function(event) {
201 if(event.keyCode == '8') {
202 var target = event.target || event.srcElement;
203 if (!/input|textarea/i.test(target.nodeName)) {
207 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
208 event.preventDefault();
209 if(stopped == false) {
214 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
228 function NavUpdate() {
231 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
232 $j.get(pingCmd,function(data) {
233 $j(data).find('result').each(function() {
234 // send nav-update event
235 $j('nav').trigger('nav-update', this);
242 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
243 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
244 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
245 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
246 if($j('#live-display').length) { src = 'display'; liveUpdate(); }
247 /*if($j('#live-display').length) {
250 window.location.href=window.location.href
253 if($j('#live-photos').length) {
256 window.location.href=window.location.href
266 timer = setTimeout(NavUpdate,updateInterval);
269 function liveUpdate() {
270 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
271 if(($j('.comment-edit-text-full').length) || (in_progress)) {
273 clearTimeout(livetime);
275 livetime = setTimeout(liveUpdate, 10000);
281 prev = 'live-' + src;
284 var udargs = ((netargs.length) ? '/' + netargs : '');
285 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
287 $j.get(update_url,function(data) {
289 // $j('.collapsed-comments',data).each(function() {
290 // var ident = $j(this).attr('id');
291 // var is_hidden = $j('#' + ident).is(':hidden');
292 // if($j('#' + ident).length) {
293 // $j('#' + ident).replaceWith($j(this));
295 // $j('#' + ident).hide();
301 $j('.toplevel_item',data).each(function() {
302 var ident = $j(this).attr('id');
304 if($j('#' + ident).length == 0 && profile_page == 1) {
305 $j('img',this).each(function() {
306 $j(this).attr('src',$j(this).attr('dst'));
308 $j('#' + prev).after($j(this));
311 // Find out if the hidden comments are open, so we can keep it that way
312 // if a new comment has been posted
313 var id = $j('.hide-comments-total', this).attr('id');
314 if(typeof id != 'undefined') {
315 id = id.split('-')[3];
316 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
319 $j('img',this).each(function() {
320 $j(this).attr('src',$j(this).attr('dst'));
322 //vScroll = $j(document).scrollTop();
323 $j('html').height($j('html').height());
324 $j('#' + ident).replaceWith($j(this));
326 if(typeof id != 'undefined') {
327 if(commentsOpen) showHideComments(id);
329 $j('html').height('auto');
330 //$j(document).scrollTop(vScroll);
336 var bimgs = $j(".wall-item-body > img").not(function() { return this.complete; });
337 var bimgcount = bimgs.length;
340 bimgs.load(function() {
351 // reset vars for inserting individual items
353 /*prev = 'live-' + src;
355 $j('.wall-item-outside-wrapper',data).each(function() {
356 var ident = $j(this).attr('id');
358 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
359 $j('img',this).each(function() {
360 $j(this).attr('src',$j(this).attr('dst'));
362 $j('#' + prev).after($j(this));
365 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
366 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
367 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
368 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
369 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
370 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
371 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
372 $j(this).attr('src',$j(this).attr('dst'));
378 $j('.like-rotator').hide();
381 $j('body').css('cursor', 'auto');
383 /* autocomplete @nicknames */
384 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
388 function collapseHeight() {
389 $j(".wall-item-body").each(function() {
390 if($j(this).height() > 310) {
391 if(! $j(this).hasClass('divmore')) {
392 $j(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
393 $j(this).addClass('divmore');
399 function imgbright(node) {
400 $j(node).removeClass("drophide").addClass("drop");
403 function imgdull(node) {
404 $j(node).removeClass("drop").addClass("drophide");
407 // Since our ajax calls are asynchronous, we will give a few
408 // seconds for the first ajax call (setting like/dislike), then
409 // run the updater to pick up any changes and display on the page.
410 // The updater will turn any rotators off when it's done.
411 // This function will have returned long before any of these
412 // events have completed and therefore there won't be any
413 // visible feedback that anything changed without all this
414 // trickery. This still could cause confusion if the "like" ajax call
415 // is delayed and NavUpdate runs before it completes.
417 function dolike(ident,verb) {
419 $j('#like-rotator-' + ident.toString()).show();
420 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
421 // if(timer) clearTimeout(timer);
422 // timer = setTimeout(NavUpdate,3000);
426 function dostar(ident) {
427 ident = ident.toString();
428 //$j('#like-rotator-' + ident).show();
429 $j.get('starred/' + ident, function(data) {
430 if(data.match(/1/)) {
431 $j('#starred-' + ident).addClass('starred');
432 $j('#starred-' + ident).removeClass('unstarred');
433 $j('#star-' + ident).addClass('hidden');
434 $j('#unstar-' + ident).removeClass('hidden');
437 $j('#starred-' + ident).addClass('unstarred');
438 $j('#starred-' + ident).removeClass('starred');
439 $j('#star-' + ident).removeClass('hidden');
440 $j('#unstar-' + ident).addClass('hidden');
442 //$j('#like-rotator-' + ident).hide();
446 function getPosition(e) {
447 var cursor = {x:0, y:0};
448 if ( e.touches[0].pageX || e.touches[0].pageY ) {
449 cursor.x = e.touches[0].pageX;
450 cursor.y = e.touches[0].pageY;
453 if( e.touches[0].clientX || e.touches[0].clientY ) {
454 cursor.x = e.touches[0].clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
455 cursor.y = e.touches[0].clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
458 if( e.touches[0].x || e.touches[0].y ) {
459 cursor.touches[0].x = e.touches[0].x;
460 cursor.touches[0].y = e.touches[0].y;
467 var lockvisible = false;
469 function lockview(event,id) {
470 event = event || window.event;
471 cursor = getPosition(event);
477 $j.get('lockview/' + id, function(data) {
478 $j('#panel').html(data);
479 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
485 function lockviewhide() {
490 function post_comment(id) {
493 $j('body').css('cursor', 'wait');
494 $j("#comment-preview-inp-" + id).val("0");
497 $j("#comment-edit-form-" + id).serialize(),
500 $j("#comment-edit-wrapper-" + id).hide();
501 $j("#comment-edit-text-" + id).val('');
502 var tarea = document.getElementById("comment-edit-text-" + id);
504 commentClose(tarea,id);
505 if(timer) clearTimeout(timer);
506 timer = setTimeout(NavUpdate,10);
509 window.location.href=data.reload;
518 function preview_comment(id) {
519 $j("#comment-preview-inp-" + id).val("1");
520 $j("#comment-edit-preview-" + id).show();
523 $j("#comment-edit-form-" + id).serialize(),
527 $j("#comment-edit-preview-" + id).html(data.preview);
528 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
537 function showHideComments(id) {
538 if( $j("#collapsed-comments-" + id).is(":visible")) {
539 $j("#collapsed-comments-" + id).hide();
540 $j("#hide-comments-" + id).html(window.showMore);
543 $j("#collapsed-comments-" + id).show();
544 $j("#hide-comments-" + id).html(window.showFewer);
549 function preview_post() {
550 $j("#jot-preview").val("1");
551 $j("#jot-preview-content").show();
552 tinyMCE.triggerSave();
555 $j("#profile-jot-form").serialize(),
558 $j("#jot-preview-content").html(data.preview);
559 $j("#jot-preview-content" + " a").click(function() { return false; });
564 $j("#jot-preview").val("0");
570 // unpause auto reloads if they are currently stopped
573 $j('#pause').html('');
578 // Converts the binary representation of data to hex
581 // discuss at: http://phpjs.org/functions/bin2hex
582 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
583 // + bugfixed by: Onno Marsman
584 // + bugfixed by: Linuxworld
585 // * example 1: bin2hex('Kev');
586 // * returns 1: '4b6576'
587 // * example 2: bin2hex(String.fromCharCode(0x00));
589 var v,i, f = 0, a = [];
593 for (i = 0; i<f; i++) {
594 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
600 function groupChangeMember(gid, cid, sec_token) {
601 $j('body .fakelink').css('cursor', 'wait');
602 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
603 $j('#group-update-wrapper').html(data);
604 $j('body .fakelink').css('cursor', 'auto');
608 function profChangeMember(gid,cid) {
609 $j('body .fakelink').css('cursor', 'wait');
610 $j.get('profperm/' + gid + '/' + cid, function(data) {
611 $j('#prof-update-wrapper').html(data);
612 $j('body .fakelink').css('cursor', 'auto');
616 function contactgroupChangeMember(gid,cid) {
617 $j('body').css('cursor', 'wait');
618 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
619 $j('body').css('cursor', 'auto');
624 function checkboxhighlight(box) {
625 if($j(box).is(':checked')) {
626 $j(box).addClass('checkeditem');
629 $j(box).removeClass('checkeditem');
633 function notifyMarkAll() {
634 $j.get('notify/mark/all', function(data) {
635 if(timer) clearTimeout(timer);
636 timer = setTimeout(NavUpdate,1000);
641 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
642 function fcFileBrowser (field_name, url, type, win) {
643 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
644 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
645 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
648 var cmsURL = baseurl+"/fbrowser/"+type+"/";
650 tinyMCE.activeEditor.windowManager.open({
652 title : 'File Browser',
653 width : 420, // Your dimensions may differ - toy around with them!
656 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
657 close_previous : "no"
665 function setupFieldRichtext(){
668 mode : "specific_textareas",
669 editor_selector: "fieldRichtext",
670 plugins : "bbcode,paste, inlinepopups",
671 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
672 theme_advanced_buttons2 : "",
673 theme_advanced_buttons3 : "",
674 theme_advanced_toolbar_location : "top",
675 theme_advanced_toolbar_align : "center",
676 theme_advanced_blockformats : "blockquote,code",
677 paste_text_sticky : true,
678 entity_encoding : "raw",
679 add_unload_trigger : false,
680 remove_linebreaks : false,
681 force_p_newlines : false,
682 force_br_newlines : true,
683 forced_root_block : '',
685 content_css: baseurl+"/view/custom_tinymce.css",
686 theme_advanced_path : false,
687 file_browser_callback : "fcFileBrowser",
693 * sprintf in javascript
694 * "{0} and {1}".format('zero','uno');
696 String.prototype.format = function() {
697 var formatted = this;
698 for (var i = 0; i < arguments.length; i++) {
699 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
700 formatted = formatted.replace(regexp, arguments[i]);
705 Array.prototype.remove = function(item) {
706 to=undefined; from=this.indexOf(item);
707 var rest = this.slice((to || from) + 1 || this.length);
708 this.length = from < 0 ? this.length + from : from;
709 return this.push.apply(this, rest);
712 function previewTheme(elm) {
713 theme = $j(elm).val();
714 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
715 $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>');