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'
112 /* notifications template */
113 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
114 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
115 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
116 var notifications_empty = unescape($("#nav-notifications-menu").html());
118 /* nav update event */
119 $('nav').bind('nav-update', function(e,data){;
120 var invalid = $(data).find('invalid').text();
121 if(invalid == 1) { window.location.href=window.location.href }
123 var net = $(data).find('net').text();
124 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
125 $('#net-update').html(net);
127 var home = $(data).find('home').text();
128 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
129 $('#home-update').html(home);
131 var intro = $(data).find('intro').text();
132 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
133 $('#intro-update').html(intro);
135 var mail = $(data).find('mail').text();
136 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
137 $('#mail-update').html(mail);
139 var intro = $(data).find('intro').text();
140 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
141 $('#intro-update-li').html(intro);
143 var mail = $(data).find('mail').text();
144 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
145 $('#mail-update-li').html(mail);
148 var allevents = $(data).find('all-events').text();
149 if(allevents == 0) { allevents = ''; $('#allevents-update').removeClass('show') } else { $('#allevents-update').addClass('show') }
150 $('#allevents-update').html(allevents);
152 var alleventstoday = $(data).find('all-events-today').text();
153 if(alleventstoday == 0) { $('#allevents-update').removeClass('notif-allevents-today') } else { $('#allevents-update').addClass('notif-allevents-today') }
155 var events = $(data).find('events').text();
156 if(events == 0) { events = ''; $('#events-update').removeClass('show') } else { $('#events-update').addClass('show') }
157 $('#events-update').html(events);
159 var eventstoday = $(data).find('events-today').text();
160 if(eventstoday == 0) { $('#events-update').removeClass('notif-events-today') } else { $('#events-update').addClass('notif-events-today') }
162 var birthdays = $(data).find('birthdays').text();
163 if(birthdays == 0) {birthdays = ''; $('#birthdays-update').removeClass('show') } else { $('#birthdays-update').addClass('show') }
164 $('#birthdays-update').html(birthdays);
166 var birthdaystoday = $(data).find('birthdays-today').text();
167 if(birthdaystoday == 0) { $('#birthdays-update').removeClass('notif-birthdays-today') } else { $('#birthdays-update').addClass('notif-birthdays-today') }
170 var eNotif = $(data).find('notif')
172 if (eNotif.children("note").length==0){
173 $("#nav-notifications-menu").html(notifications_empty);
175 nnm = $("#nav-notifications-menu");
176 nnm.html(notifications_all + notifications_mark);
177 //nnm.attr('popup','true');
178 eNotif.children("note").each(function(){
180 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
181 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
185 notif = eNotif.attr('count');
187 $("#nav-notifications-linkmenu").addClass("on");
189 $("#nav-notifications-linkmenu").removeClass("on");
191 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
192 $('#notify-update').html(notif);
194 var eSysmsg = $(data).find('sysmsgs');
195 eSysmsg.children("notice").each(function(){
196 text = $(this).text();
197 $.jGrowl(text, { sticky: true, theme: 'notice' });
199 eSysmsg.children("info").each(function(){
200 text = $(this).text();
201 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
208 // Allow folks to stop the ajax page updates with the pause/break key
209 $(document).keydown(function(event) {
210 if(event.keyCode == '8') {
211 var target = event.target || event.srcElement;
212 if (!/input|textarea/i.test(target.nodeName)) {
216 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
217 event.preventDefault();
218 if(stopped == false) {
223 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
237 function NavUpdate() {
240 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
241 $.get(pingCmd,function(data) {
242 $(data).find('result').each(function() {
243 // send nav-update event
244 $('nav').trigger('nav-update', this);
249 if($('#live-network').length) { src = 'network'; liveUpdate(); }
250 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
251 if($('#live-community').length) { src = 'community'; liveUpdate(); }
252 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
253 if($('#live-display').length) {
256 window.location.href=window.location.href
259 if($('#live-photos').length) {
262 window.location.href=window.location.href
272 timer = setTimeout(NavUpdate,updateInterval);
275 function liveUpdate() {
276 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
277 if(($('.comment-edit-text-full').length) || (in_progress)) {
279 clearTimeout(livetime);
281 livetime = setTimeout(liveUpdate, 10000);
287 prev = 'live-' + src;
290 var udargs = ((netargs.length) ? '/' + netargs : '');
291 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
293 $.get(update_url,function(data) {
295 // $('.collapsed-comments',data).each(function() {
296 // var ident = $(this).attr('id');
297 // var is_hidden = $('#' + ident).is(':hidden');
298 // if($('#' + ident).length) {
299 // $('#' + ident).replaceWith($(this));
301 // $('#' + ident).hide();
306 $('.toplevel_item',data).each(function() {
307 var ident = $(this).attr('id');
309 if($('#' + ident).length == 0 && profile_page == 1) {
310 $('img',this).each(function() {
311 $(this).attr('src',$(this).attr('dst'));
313 $('#' + prev).after($(this));
316 $('img',this).each(function() {
317 $(this).attr('src',$(this).attr('dst'));
319 $('#' + ident).replaceWith($(this));
324 // reset vars for inserting individual items
326 /* prev = 'live-' + src;
328 $('.wall-item-outside-wrapper',data).each(function() {
329 var ident = $(this).attr('id');
331 if($('#' + ident).length == 0 && prev != 'live-' + src) {
332 $('img',this).each(function() {
333 $(this).attr('src',$(this).attr('dst'));
335 $('#' + prev).after($(this));
338 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
339 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
340 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
341 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
342 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
343 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
344 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
345 $(this).attr('src',$(this).attr('dst'));
351 $('.like-rotator').hide();
354 $('body').css('cursor', 'auto');
356 /* autocomplete @nicknames */
357 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
361 function imgbright(node) {
362 $(node).removeClass("drophide").addClass("drop");
365 function imgdull(node) {
366 $(node).removeClass("drop").addClass("drophide");
369 // Since our ajax calls are asynchronous, we will give a few
370 // seconds for the first ajax call (setting like/dislike), then
371 // run the updater to pick up any changes and display on the page.
372 // The updater will turn any rotators off when it's done.
373 // This function will have returned long before any of these
374 // events have completed and therefore there won't be any
375 // visible feedback that anything changed without all this
376 // trickery. This still could cause confusion if the "like" ajax call
377 // is delayed and NavUpdate runs before it completes.
379 function dolike(ident,verb) {
381 $('#like-rotator-' + ident.toString()).show();
382 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
383 // if(timer) clearTimeout(timer);
384 // timer = setTimeout(NavUpdate,3000);
388 function dostar(ident) {
389 ident = ident.toString();
390 $('#like-rotator-' + ident).show();
391 $.get('starred/' + ident, function(data) {
392 if(data.match(/1/)) {
393 $('#starred-' + ident).addClass('starred');
394 $('#starred-' + ident).removeClass('unstarred');
395 $('#star-' + ident).addClass('hidden');
396 $('#unstar-' + ident).removeClass('hidden');
399 $('#starred-' + ident).addClass('unstarred');
400 $('#starred-' + ident).removeClass('starred');
401 $('#star-' + ident).removeClass('hidden');
402 $('#unstar-' + ident).addClass('hidden');
404 $('#like-rotator-' + ident).hide();
408 function getPosition(e) {
409 var cursor = {x:0, y:0};
410 if ( e.pageX || e.pageY ) {
415 if( e.clientX || e.clientY ) {
416 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
417 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
429 var lockvisible = false;
431 function lockview(event,id) {
432 event = event || window.event;
433 cursor = getPosition(event);
439 $.get('lockview/' + id, function(data) {
440 $('#panel').html(data);
441 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
447 function lockviewhide() {
452 function post_comment(id) {
455 $('body').css('cursor', 'wait');
456 $("#comment-preview-inp-" + id).val("0");
459 $("#comment-edit-form-" + id).serialize(),
462 $("#comment-edit-wrapper-" + id).hide();
463 $("#comment-edit-text-" + id).val('');
464 var tarea = document.getElementById("comment-edit-text-" + id);
466 commentClose(tarea,id);
467 if(timer) clearTimeout(timer);
468 timer = setTimeout(NavUpdate,10);
471 window.location.href=data.reload;
480 function preview_comment(id) {
481 $("#comment-preview-inp-" + id).val("1");
482 $("#comment-edit-preview-" + id).show();
485 $("#comment-edit-form-" + id).serialize(),
489 $("#comment-edit-preview-" + id).html(data.preview);
490 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
500 function preview_post() {
501 $("#jot-preview").val("1");
502 $("#jot-preview-content").show();
503 tinyMCE.triggerSave();
506 $("#profile-jot-form").serialize(),
509 $("#jot-preview-content").html(data.preview);
510 $("#jot-preview-content" + " a").click(function() { return false; });
515 $("#jot-preview").val("0");
521 // unpause auto reloads if they are currently stopped
524 $('#pause').html('');
529 // Converts the binary representation of data to hex
532 // discuss at: http://phpjs.org/functions/bin2hex
533 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
534 // + bugfixed by: Onno Marsman
535 // + bugfixed by: Linuxworld
536 // * example 1: bin2hex('Kev');
537 // * returns 1: '4b6576'
538 // * example 2: bin2hex(String.fromCharCode(0x00));
540 var v,i, f = 0, a = [];
544 for (i = 0; i<f; i++) {
545 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
551 function groupChangeMember(gid, cid, sec_token) {
552 $('body .fakelink').css('cursor', 'wait');
553 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
554 $('#group-update-wrapper').html(data);
555 $('body .fakelink').css('cursor', 'auto');
559 function profChangeMember(gid,cid) {
560 $('body .fakelink').css('cursor', 'wait');
561 $.get('profperm/' + gid + '/' + cid, function(data) {
562 $('#prof-update-wrapper').html(data);
563 $('body .fakelink').css('cursor', 'auto');
567 function contactgroupChangeMember(gid,cid) {
568 $('body').css('cursor', 'wait');
569 $.get('contactgroup/' + gid + '/' + cid, function(data) {
570 $('body').css('cursor', 'auto');
575 function checkboxhighlight(box) {
576 if($(box).is(':checked')) {
577 $(box).addClass('checkeditem');
580 $(box).removeClass('checkeditem');
584 function notifyMarkAll() {
585 $.get('notify/mark/all', function(data) {
586 if(timer) clearTimeout(timer);
587 timer = setTimeout(NavUpdate,1000);
592 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
593 function fcFileBrowser (field_name, url, type, win) {
594 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
595 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
596 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
599 var cmsURL = baseurl+"/fbrowser/"+type+"/";
601 tinyMCE.activeEditor.windowManager.open({
603 title : 'File Browser',
604 width : 420, // Your dimensions may differ - toy around with them!
607 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
608 close_previous : "no"
616 function setupFieldRichtext(){
619 mode : "specific_textareas",
620 editor_selector: "fieldRichtext",
621 plugins : "bbcode,paste, inlinepopups",
622 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
623 theme_advanced_buttons2 : "",
624 theme_advanced_buttons3 : "",
625 theme_advanced_toolbar_location : "top",
626 theme_advanced_toolbar_align : "center",
627 theme_advanced_blockformats : "blockquote,code",
628 paste_text_sticky : true,
629 entity_encoding : "raw",
630 add_unload_trigger : false,
631 remove_linebreaks : false,
632 force_p_newlines : false,
633 force_br_newlines : true,
634 forced_root_block : '',
636 content_css: baseurl+"/view/custom_tinymce.css",
637 theme_advanced_path : false,
638 file_browser_callback : "fcFileBrowser",
644 * sprintf in javascript
645 * "{0} and {1}".format('zero','uno');
647 String.prototype.format = function() {
648 var formatted = this;
649 for (var i = 0; i < arguments.length; i++) {
650 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
651 formatted = formatted.replace(regexp, arguments[i]);
656 Array.prototype.remove = function(item) {
657 to=undefined; from=this.indexOf(item);
658 var rest = this.slice((to || from) + 1 || this.length);
659 this.length = from < 0 ? this.length + from : from;
660 return this.push.apply(this, rest);
663 function previewTheme(elm) {
664 theme = $(elm).val();
665 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
666 $('#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>');