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: 3000 }); // originally: sticky: true,
183 eSysmsg.children("info").each(function(){
184 text = $j(this).text();
185 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
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) { src = 'display'; liveUpdate(); }
240 /*if($j('#live-display').length) {
243 window.location.href=window.location.href
246 if($j('#live-photos').length) {
249 window.location.href=window.location.href
259 timer = setTimeout(NavUpdate,updateInterval);
262 function liveUpdate() {
263 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
264 if(($j('.comment-edit-text-full').length) || (in_progress)) {
266 clearTimeout(livetime);
268 livetime = setTimeout(liveUpdate, 10000);
274 prev = 'live-' + src;
277 var udargs = ((netargs.length) ? '/' + netargs : '');
278 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
280 $j.get(update_url,function(data) {
282 // $j('.collapsed-comments',data).each(function() {
283 // var ident = $j(this).attr('id');
284 // var is_hidden = $j('#' + ident).is(':hidden');
285 // if($j('#' + ident).length) {
286 // $j('#' + ident).replaceWith($j(this));
288 // $j('#' + ident).hide();
294 $j('.toplevel_item',data).each(function() {
295 var ident = $j(this).attr('id');
297 if($j('#' + ident).length == 0 && profile_page == 1) {
298 $j('img',this).each(function() {
299 $j(this).attr('src',$j(this).attr('dst'));
301 $j('#' + prev).after($j(this));
304 // Find out if the hidden comments are open, so we can keep it that way
305 // if a new comment has been posted
306 var id = $j('.hide-comments-total', this).attr('id');
307 if(typeof id != 'undefined') {
308 id = id.split('-')[3];
309 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
312 $j('img',this).each(function() {
313 $j(this).attr('src',$j(this).attr('dst'));
315 //vScroll = $j(document).scrollTop();
316 $j('html').height($j('html').height());
317 $j('#' + ident).replaceWith($j(this));
319 if(typeof id != 'undefined') {
320 if(commentsOpen) showHideComments(id);
322 $j('html').height('auto');
323 //$j(document).scrollTop(vScroll);
328 // reset vars for inserting individual items
330 /*prev = 'live-' + src;
332 $j('.wall-item-outside-wrapper',data).each(function() {
333 var ident = $j(this).attr('id');
335 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
336 $j('img',this).each(function() {
337 $j(this).attr('src',$j(this).attr('dst'));
339 $j('#' + prev).after($j(this));
342 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
343 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
344 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
345 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
346 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
347 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
348 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
349 $j(this).attr('src',$j(this).attr('dst'));
355 $j('.like-rotator').hide();
358 $j('body').css('cursor', 'auto');
360 /* autocomplete @nicknames */
361 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
363 var bimgs = $j(".wall-item-body > img").not(function() { return this.complete; });
364 var bimgcount = bimgs.length;
367 bimgs.load(function() {
381 function collapseHeight() {
382 $j(".wall-item-body").each(function() {
383 if($j(this).height() > 410) {
384 if(! $j(this).hasClass('divmore')) {
385 $j(this).divgrow({ initialHeight: 400, showBrackets: false, speed: 300 });
386 $j(this).addClass('divmore');
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.pageX || e.pageY ) {
446 if( e.clientX || e.clientY ) {
447 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
448 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
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);
542 function preview_post() {
543 $j("#jot-preview").val("1");
544 $j("#jot-preview-content").show();
545 tinyMCE.triggerSave();
548 $j("#profile-jot-form").serialize(),
551 $j("#jot-preview-content").html(data.preview);
552 $j("#jot-preview-content" + " a").click(function() { return false; });
557 $j("#jot-preview").val("0");
563 // unpause auto reloads if they are currently stopped
566 $j('#pause').html('');
571 // Converts the binary representation of data to hex
574 // discuss at: http://phpjs.org/functions/bin2hex
575 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
576 // + bugfixed by: Onno Marsman
577 // + bugfixed by: Linuxworld
578 // * example 1: bin2hex('Kev');
579 // * returns 1: '4b6576'
580 // * example 2: bin2hex(String.fromCharCode(0x00));
582 var v,i, f = 0, a = [];
586 for (i = 0; i<f; i++) {
587 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
593 function groupChangeMember(gid, cid, sec_token) {
594 $j('body .fakelink').css('cursor', 'wait');
595 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
596 $j('#group-update-wrapper').html(data);
597 $j('body .fakelink').css('cursor', 'auto');
601 function profChangeMember(gid,cid) {
602 $j('body .fakelink').css('cursor', 'wait');
603 $j.get('profperm/' + gid + '/' + cid, function(data) {
604 $j('#prof-update-wrapper').html(data);
605 $j('body .fakelink').css('cursor', 'auto');
609 function contactgroupChangeMember(gid,cid) {
610 $j('body').css('cursor', 'wait');
611 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
612 $j('body').css('cursor', 'auto');
617 function checkboxhighlight(box) {
618 if($j(box).is(':checked')) {
619 $j(box).addClass('checkeditem');
622 $j(box).removeClass('checkeditem');
626 function notifyMarkAll() {
627 $j.get('notify/mark/all', function(data) {
628 if(timer) clearTimeout(timer);
629 timer = setTimeout(NavUpdate,1000);
634 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
635 function fcFileBrowser (field_name, url, type, win) {
636 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
637 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
638 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
641 var cmsURL = baseurl+"/fbrowser/"+type+"/";
643 tinyMCE.activeEditor.windowManager.open({
645 title : 'File Browser',
646 width : 420, // Your dimensions may differ - toy around with them!
649 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
650 close_previous : "no"
658 function setupFieldRichtext(){
661 mode : "specific_textareas",
662 editor_selector: "fieldRichtext",
663 plugins : "bbcode,paste, inlinepopups",
664 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
665 theme_advanced_buttons2 : "",
666 theme_advanced_buttons3 : "",
667 theme_advanced_toolbar_location : "top",
668 theme_advanced_toolbar_align : "center",
669 theme_advanced_blockformats : "blockquote,code",
670 paste_text_sticky : true,
671 entity_encoding : "raw",
672 add_unload_trigger : false,
673 remove_linebreaks : false,
674 force_p_newlines : false,
675 force_br_newlines : true,
676 forced_root_block : '',
678 content_css: baseurl+"/view/custom_tinymce.css",
679 theme_advanced_path : false,
680 file_browser_callback : "fcFileBrowser",
686 * sprintf in javascript
687 * "{0} and {1}".format('zero','uno');
689 String.prototype.format = function() {
690 var formatted = this;
691 for (var i = 0; i < arguments.length; i++) {
692 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
693 formatted = formatted.replace(regexp, arguments[i]);
698 Array.prototype.remove = function(item) {
699 to=undefined; from=this.indexOf(item);
700 var rest = this.slice((to || from) + 1 || this.length);
701 this.length = from < 0 ? this.length + from : from;
702 return this.push.apply(this, rest);
705 function previewTheme(elm) {
706 theme = $j(elm).val();
707 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
708 $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>');