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 $.ajaxSetup({cache: false});
39 msie = $.browser.msie ;
41 /* setup tooltips *//*
42 $("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 $(".onoff input").each(function(){
57 id = $(this).attr("id");
58 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
61 $(".onoff > a").click(function(event){
62 event.preventDefault();
63 var input = $(this).siblings("input");
64 var val = 1-input.val();
65 var id = input.attr("id");
66 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
67 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
72 /* setup field_richtext */
76 function close_last_popup_menu() {
78 last_popup_menu.hide();
79 last_popup_button.removeClass("selected");
80 last_popup_menu = null;
81 last_popup_button = null;
84 $('a[rel^=#]').click(function(e){
85 close_last_popup_menu();
86 menu = $( $(this).attr('rel') );
89 if (menu.attr('popup')=="false") return false;
90 $(this).parent().toggleClass("selected");
92 if (menu.css("display") == "none") {
93 last_popup_menu = null;
94 last_popup_button = null;
96 last_popup_menu = menu;
97 last_popup_button = $(this).parent();
101 $('html').click(function() {
102 close_last_popup_menu();
106 /*$("a.popupbox").fancybox({
107 'transitionIn' : 'elastic',
108 'transitionOut' : 'elastic'
110 $("a.popupbox").colorbox({
112 'transition' : 'elastic'
116 /* notifications template */
117 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
118 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
119 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
120 var notifications_empty = unescape($("#nav-notifications-menu").html());
122 /* nav update event */
123 $('nav').bind('nav-update', function(e,data){;
124 var invalid = $(data).find('invalid').text();
125 if(invalid == 1) { window.location.href=window.location.href }
127 var net = $(data).find('net').text();
128 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
129 $('#net-update').html(net);
131 var home = $(data).find('home').text();
132 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
133 $('#home-update').html(home);
135 var intro = $(data).find('intro').text();
136 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
137 $('#intro-update').html(intro);
139 var mail = $(data).find('mail').text();
140 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
141 $('#mail-update').html(mail);
143 var intro = $(data).find('intro').text();
144 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
145 $('#intro-update-li').html(intro);
147 var mail = $(data).find('mail').text();
148 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
149 $('#mail-update-li').html(mail);
152 var allevents = $(data).find('all-events').text();
153 if(allevents == 0) { allevents = ''; $('#allevents-update').removeClass('show') } else { $('#allevents-update').addClass('show') }
154 $('#allevents-update').html(allevents);
156 var alleventstoday = $(data).find('all-events-today').text();
157 if(alleventstoday == 0) { $('#allevents-update').removeClass('notif-allevents-today') } else { $('#allevents-update').addClass('notif-allevents-today') }
159 var events = $(data).find('events').text();
160 if(events == 0) { events = ''; $('#events-update').removeClass('show') } else { $('#events-update').addClass('show') }
161 $('#events-update').html(events);
163 var eventstoday = $(data).find('events-today').text();
164 if(eventstoday == 0) { $('#events-update').removeClass('notif-events-today') } else { $('#events-update').addClass('notif-events-today') }
166 var birthdays = $(data).find('birthdays').text();
167 if(birthdays == 0) {birthdays = ''; $('#birthdays-update').removeClass('show') } else { $('#birthdays-update').addClass('show') }
168 $('#birthdays-update').html(birthdays);
170 var birthdaystoday = $(data).find('birthdays-today').text();
171 if(birthdaystoday == 0) { $('#birthdays-update').removeClass('notif-birthdays-today') } else { $('#birthdays-update').addClass('notif-birthdays-today') }
174 var eNotif = $(data).find('notif')
176 if (eNotif.children("note").length==0){
177 $("#nav-notifications-menu").html(notifications_empty);
179 nnm = $("#nav-notifications-menu");
180 nnm.html(notifications_all + notifications_mark);
181 //nnm.attr('popup','true');
182 eNotif.children("note").each(function(){
184 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
185 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
189 $("img[data-src]", nnm).each(function(i, el){
190 // Add src attribute for images with a data-src attribute
191 $(el).attr('src', $(el).data("src"));
195 notif = eNotif.attr('count');
197 $("#nav-notifications-linkmenu").addClass("on");
199 $("#nav-notifications-linkmenu").removeClass("on");
201 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
202 $('#notify-update').html(notif);
204 var eSysmsg = $(data).find('sysmsgs');
205 eSysmsg.children("notice").each(function(){
206 text = $(this).text();
207 $.jGrowl(text, { sticky: true, theme: 'notice' });
209 eSysmsg.children("info").each(function(){
210 text = $(this).text();
211 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
217 // Allow folks to stop the ajax page updates with the pause/break key
218 $(document).keydown(function(event) {
219 if(event.keyCode == '8') {
220 var target = event.target || event.srcElement;
221 if (!/input|textarea/i.test(target.nodeName)) {
225 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
226 event.preventDefault();
227 if(stopped == false) {
232 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
246 function NavUpdate() {
249 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
250 $.get(pingCmd,function(data) {
251 $(data).find('result').each(function() {
252 // send nav-update event
253 $('nav').trigger('nav-update', this);
258 if($('#live-network').length) { src = 'network'; liveUpdate(); }
259 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
260 if($('#live-community').length) { src = 'community'; liveUpdate(); }
261 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
262 if($('#live-display').length) { src = 'display'; liveUpdate(); }
263 /* if($('#live-display').length) {
266 window.location.href=window.location.href
269 if($('#live-photos').length) {
272 window.location.href=window.location.href
282 timer = setTimeout(NavUpdate,updateInterval);
285 function liveUpdate() {
286 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
287 if(($('.comment-edit-text-full').length) || (in_progress)) {
289 clearTimeout(livetime);
291 livetime = setTimeout(liveUpdate, 10000);
297 prev = 'live-' + src;
300 var udargs = ((netargs.length) ? '/' + netargs : '');
301 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
303 $.get(update_url,function(data) {
305 // $('.collapsed-comments',data).each(function() {
306 // var ident = $(this).attr('id');
307 // var is_hidden = $('#' + ident).is(':hidden');
308 // if($('#' + ident).length) {
309 // $('#' + ident).replaceWith($(this));
311 // $('#' + ident).hide();
316 $('.toplevel_item',data).each(function() {
317 var ident = $(this).attr('id');
319 if($('#' + ident).length == 0 && profile_page == 1) {
320 $('img',this).each(function() {
321 $(this).attr('src',$(this).attr('dst'));
323 $('#' + prev).after($(this));
326 // Find out if the hidden comments are open, so we can keep it that way
327 // if a new comment has been posted
328 var id = $('.hide-comments-total', this).attr('id');
329 if(typeof id != 'undefined') {
330 id = id.split('-')[3];
331 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
334 $('img',this).each(function() {
335 $(this).attr('src',$(this).attr('dst'));
337 //vScroll = $(document).scrollTop();
338 $('html').height($('html').height());
339 $('#' + ident).replaceWith($(this));
341 if(typeof id != 'undefined') {
342 if(commentsOpen) showHideComments(id);
344 $('html').height('auto');
345 //$(document).scrollTop(vScroll);
350 // reset vars for inserting individual items
352 /* prev = 'live-' + src;
354 $('.wall-item-outside-wrapper',data).each(function() {
355 var ident = $(this).attr('id');
357 if($('#' + ident).length == 0 && prev != 'live-' + src) {
358 $('img',this).each(function() {
359 $(this).attr('src',$(this).attr('dst'));
361 $('#' + prev).after($(this));
364 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
365 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
366 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
367 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
368 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
369 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
370 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
371 $(this).attr('src',$(this).attr('dst'));
377 $('.like-rotator').hide();
380 $('body').css('cursor', 'auto');
382 /* autocomplete @nicknames */
383 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
387 function imgbright(node) {
388 $(node).removeClass("drophide").addClass("drop");
391 function imgdull(node) {
392 $(node).removeClass("drop").addClass("drophide");
395 // Since our ajax calls are asynchronous, we will give a few
396 // seconds for the first ajax call (setting like/dislike), then
397 // run the updater to pick up any changes and display on the page.
398 // The updater will turn any rotators off when it's done.
399 // This function will have returned long before any of these
400 // events have completed and therefore there won't be any
401 // visible feedback that anything changed without all this
402 // trickery. This still could cause confusion if the "like" ajax call
403 // is delayed and NavUpdate runs before it completes.
405 function dolike(ident,verb) {
407 $('#like-rotator-' + ident.toString()).show();
408 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
412 function dosubthread(ident) {
414 $('#like-rotator-' + ident.toString()).show();
415 $.get('subthread/' + ident.toString(), NavUpdate );
420 function dostar(ident) {
421 ident = ident.toString();
422 $('#like-rotator-' + ident).show();
423 $.get('starred/' + ident, function(data) {
424 if(data.match(/1/)) {
425 $('#starred-' + ident).addClass('starred');
426 $('#starred-' + ident).removeClass('unstarred');
427 $('#star-' + ident).addClass('hidden');
428 $('#unstar-' + ident).removeClass('hidden');
431 $('#starred-' + ident).addClass('unstarred');
432 $('#starred-' + ident).removeClass('starred');
433 $('#star-' + ident).removeClass('hidden');
434 $('#unstar-' + ident).addClass('hidden');
436 $('#like-rotator-' + ident).hide();
440 function getPosition(e) {
441 var cursor = {x:0, y:0};
442 if ( e.pageX || e.pageY ) {
447 if( e.clientX || e.clientY ) {
448 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
449 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
461 var lockvisible = false;
463 function lockview(event,id) {
464 event = event || window.event;
465 cursor = getPosition(event);
471 $.get('lockview/' + id, function(data) {
472 $('#panel').html(data);
473 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
479 function lockviewhide() {
484 function post_comment(id) {
487 $('body').css('cursor', 'wait');
488 $("#comment-preview-inp-" + id).val("0");
491 $("#comment-edit-form-" + id).serialize(),
494 $("#comment-edit-wrapper-" + id).hide();
495 $("#comment-edit-text-" + id).val('');
496 var tarea = document.getElementById("comment-edit-text-" + id);
498 commentClose(tarea,id);
499 if(timer) clearTimeout(timer);
500 timer = setTimeout(NavUpdate,10);
503 window.location.href=data.reload;
512 function preview_comment(id) {
513 $("#comment-preview-inp-" + id).val("1");
514 $("#comment-edit-preview-" + id).show();
517 $("#comment-edit-form-" + id).serialize(),
521 $("#comment-edit-preview-" + id).html(data.preview);
522 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
532 function showHideComments(id) {
533 if( $("#collapsed-comments-" + id).is(":visible")) {
534 $("#collapsed-comments-" + id).hide();
535 $("#hide-comments-" + id).html(window.showMore);
538 $("#collapsed-comments-" + id).show();
539 $("#hide-comments-" + id).html(window.showFewer);
545 function preview_post() {
546 $("#jot-preview").val("1");
547 $("#jot-preview-content").show();
548 tinyMCE.triggerSave();
551 $("#profile-jot-form").serialize(),
554 $("#jot-preview-content").html(data.preview);
555 $("#jot-preview-content" + " a").click(function() { return false; });
560 $("#jot-preview").val("0");
566 // unpause auto reloads if they are currently stopped
569 $('#pause').html('');
574 // Converts the binary representation of data to hex
577 // discuss at: http://phpjs.org/functions/bin2hex
578 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
579 // + bugfixed by: Onno Marsman
580 // + bugfixed by: Linuxworld
581 // * example 1: bin2hex('Kev');
582 // * returns 1: '4b6576'
583 // * example 2: bin2hex(String.fromCharCode(0x00));
585 var v,i, f = 0, a = [];
589 for (i = 0; i<f; i++) {
590 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
596 function groupChangeMember(gid, cid, sec_token) {
597 $('body .fakelink').css('cursor', 'wait');
598 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
599 $('#group-update-wrapper').html(data);
600 $('body .fakelink').css('cursor', 'auto');
604 function profChangeMember(gid,cid) {
605 $('body .fakelink').css('cursor', 'wait');
606 $.get('profperm/' + gid + '/' + cid, function(data) {
607 $('#prof-update-wrapper').html(data);
608 $('body .fakelink').css('cursor', 'auto');
612 function contactgroupChangeMember(gid,cid) {
613 $('body').css('cursor', 'wait');
614 $.get('contactgroup/' + gid + '/' + cid, function(data) {
615 $('body').css('cursor', 'auto');
620 function checkboxhighlight(box) {
621 if($(box).is(':checked')) {
622 $(box).addClass('checkeditem');
625 $(box).removeClass('checkeditem');
629 function notifyMarkAll() {
630 $.get('notify/mark/all', function(data) {
631 if(timer) clearTimeout(timer);
632 timer = setTimeout(NavUpdate,1000);
637 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
638 function fcFileBrowser (field_name, url, type, win) {
639 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
640 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
641 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
644 var cmsURL = baseurl+"/fbrowser/"+type+"/";
646 tinyMCE.activeEditor.windowManager.open({
648 title : 'File Browser',
649 width : 420, // Your dimensions may differ - toy around with them!
652 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
653 close_previous : "no"
661 function setupFieldRichtext(){
664 mode : "specific_textareas",
665 editor_selector: "fieldRichtext",
666 plugins : "bbcode,paste, inlinepopups",
667 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
668 theme_advanced_buttons2 : "",
669 theme_advanced_buttons3 : "",
670 theme_advanced_toolbar_location : "top",
671 theme_advanced_toolbar_align : "center",
672 theme_advanced_blockformats : "blockquote,code",
673 paste_text_sticky : true,
674 entity_encoding : "raw",
675 add_unload_trigger : false,
676 remove_linebreaks : false,
677 //force_p_newlines : false,
678 //force_br_newlines : true,
679 forced_root_block : 'div',
681 content_css: baseurl+"/view/custom_tinymce.css",
682 theme_advanced_path : false,
683 file_browser_callback : "fcFileBrowser",
689 * sprintf in javascript
690 * "{0} and {1}".format('zero','uno');
692 String.prototype.format = function() {
693 var formatted = this;
694 for (var i = 0; i < arguments.length; i++) {
695 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
696 formatted = formatted.replace(regexp, arguments[i]);
701 Array.prototype.remove = function(item) {
702 to=undefined; from=this.indexOf(item);
703 var rest = this.slice((to || from) + 1 || this.length);
704 this.length = from < 0 ? this.length + from : from;
705 return this.push.apply(this, rest);
708 function previewTheme(elm) {
709 theme = $(elm).val();
710 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
711 $('#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>');