2 function openClose(listID) {
3 /* if(document.getElementById(theID).style.display == "block") {
4 document.getElementById(theID).style.display = "none"
7 document.getElementById(theID).style.display = "block"
9 listID = "#" + listID.replace(/:/g, "\\:");
10 listID = listID.replace(/\./g, "\\.");
11 listID = listID.replace(/@/g, "\\@");
13 if($j(listID).is(":visible")) {
15 $j(listID+"-wrapper").show();
16 alert($j(listID+"-wrapper").attr("id"));
20 $j(listID+"-wrapper").hide();
24 function openMenu(theID) {
25 document.getElementById(theID).style.display = "block"
28 function closeMenu(theID) {
29 document.getElementById(theID).style.display = "none"
39 var totStopped = false;
43 var in_progress = false;
44 var langSelect = false;
45 var commentBusy = false;
46 var last_popup_menu = null;
47 var last_popup_button = null;
50 $j.ajaxSetup({cache: false});
52 msie = $j.browser.msie ;
56 /* setup tooltips *//*
57 $j("a,.tt").each(function(){
60 if (e.hasClass("tttop")) pos="top";
61 if (e.hasClass("ttbottom")) pos="bottom";
62 if (e.hasClass("ttleft")) pos="left";
63 if (e.hasClass("ttright")) pos="right";
64 e.tipTip({defaultPosition: pos, edgeOffset: 8});
69 /* setup onoff widgets */
70 $j(".onoff input").each(function(){
72 id = $j(this).attr("id");
73 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
76 $j(".onoff > a").click(function(event){
77 event.preventDefault();
78 var input = $j(this).siblings("input");
79 var val = 1-input.val();
80 var id = input.attr("id");
81 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
82 $j("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
87 /* setup field_richtext */
88 /*setupFieldRichtext();*/
91 function close_last_popup_menu(e) {
93 if( last_popup_menu ) {
94 if( '#' + last_popup_menu.attr('id') !== $j(e.target).attr('rel')) {
95 last_popup_menu.hide();
96 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
97 last_popup_button.removeClass("selected");
98 last_popup_menu = null;
99 last_popup_button = null;
103 $j('img[rel^=#]').click(function(e){
105 close_last_popup_menu(e);
106 menu = $j( $j(this).attr('rel') );
110 if (menu.attr('popup')=="false") return false;
112 // $j(this).parent().toggleClass("selected");
115 if (menu.css("display") == "none") {
116 $j(this).parent().addClass("selected");
118 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').hide();
119 last_popup_menu = menu;
120 last_popup_button = $j(this).parent();
122 $j(this).parent().removeClass("selected");
124 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
125 last_popup_menu = null;
126 last_popup_button = null;
130 $j('html').click(function(e) {
131 close_last_popup_menu(e);
135 /*$j("a.popupbox").colorbox({
137 'transition' : 'none'
141 /* notifications template */
142 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
143 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
144 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
145 var notifications_empty = unescape($j("#nav-notifications-menu").html());
147 /* nav update event */
148 $j('nav').bind('nav-update', function(e,data){;
149 var invalid = $j(data).find('invalid').text();
150 if(invalid == 1) { window.location.href=window.location.href }
152 var net = $j(data).find('net').text();
153 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
154 $j('#net-update').html(net);
156 var home = $j(data).find('home').text();
157 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
158 $j('#home-update').html(home);
160 var intro = $j(data).find('intro').text();
161 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
162 $j('#intro-update').html(intro);
164 var mail = $j(data).find('mail').text();
165 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
166 $j('#mail-update').html(mail);
168 var intro = $j(data).find('intro').text();
169 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
170 $j('#intro-update-li').html(intro);
172 var mail = $j(data).find('mail').text();
173 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
174 $j('#mail-update-li').html(mail);
176 var eNotif = $j(data).find('notif')
178 if (eNotif.children("note").length==0){
179 $j("#nav-notifications-menu").html(notifications_empty);
181 nnm = $j("#nav-notifications-menu");
182 nnm.html(notifications_all + notifications_mark);
183 //nnm.attr('popup','true');
184 eNotif.children("note").each(function(){
186 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
187 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
191 $j("img[data-src]", nnm).each(function(i, el){
192 // Add src attribute for images with a data-src attribute
193 $j(el).attr('src', $j(el).data("src"));
196 notif = eNotif.attr('count');
198 $j("#nav-notifications-linkmenu").addClass("on");
200 $j("#nav-notifications-linkmenu").removeClass("on");
202 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
203 $j('#notify-update').html(notif);
205 var eSysmsg = $j(data).find('sysmsgs');
206 eSysmsg.children("notice").each(function(){
207 text = $j(this).text();
208 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
210 eSysmsg.children("info").each(function(){
211 text = $j(this).text();
212 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
219 // Allow folks to stop the ajax page updates with the pause/break key
220 /* $j(document).keydown(function(event) {
221 if(event.keyCode == '8') {
222 var target = event.target || event.srcElement;
223 if (!/input|textarea/i.test(target.nodeName)) {
227 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
228 event.preventDefault();
229 if(stopped == false) {
234 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
248 function NavUpdate() {
251 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
252 $j.get(pingCmd,function(data) {
253 $j(data).find('result').each(function() {
254 // send nav-update event
255 $j('nav').trigger('nav-update', this);
262 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
263 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
264 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
265 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
266 if($j('#live-display').length) { src = 'display'; liveUpdate(); }
267 /*if($j('#live-display').length) {
270 window.location.href=window.location.href
273 if($j('#live-photos').length) {
276 window.location.href=window.location.href
286 timer = setTimeout(NavUpdate,updateInterval);
289 function liveUpdate() {
290 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $j('.like-rotator').hide(); return; }
291 if(($j('.comment-edit-text-full').length) || (in_progress)) {
293 clearTimeout(livetime);
295 livetime = setTimeout(liveUpdate, 10000);
301 prev = 'live-' + src;
304 var udargs = ((netargs.length) ? '/' + netargs : '');
305 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
307 $j.get(update_url,function(data) {
309 // $j('.collapsed-comments',data).each(function() {
310 // var ident = $j(this).attr('id');
311 // var is_hidden = $j('#' + ident).is(':hidden');
312 // if($j('#' + ident).length) {
313 // $j('#' + ident).replaceWith($j(this));
315 // $j('#' + ident).hide();
321 $j('.toplevel_item',data).each(function() {
322 var ident = $j(this).attr('id');
324 if($j('#' + ident).length == 0 && profile_page == 1) {
325 $j('img',this).each(function() {
326 $j(this).attr('src',$j(this).attr('dst'));
328 $j('#' + prev).after($j(this));
331 // Find out if the hidden comments are open, so we can keep it that way
332 // if a new comment has been posted
333 var id = $j('.hide-comments-total', this).attr('id');
334 if(typeof id != 'undefined') {
335 id = id.split('-')[3];
336 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
339 $j('img',this).each(function() {
340 $j(this).attr('src',$j(this).attr('dst'));
342 //vScroll = $j(document).scrollTop();
343 $j('html').height($j('html').height());
344 $j('#' + ident).replaceWith($j(this));
346 if(typeof id != 'undefined') {
347 if(commentsOpen) showHideComments(id);
349 $j('html').height('auto');
350 //$j(document).scrollTop(vScroll);
358 // reset vars for inserting individual items
360 /*prev = 'live-' + src;
362 $j('.wall-item-outside-wrapper',data).each(function() {
363 var ident = $j(this).attr('id');
365 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
366 $j('img',this).each(function() {
367 $j(this).attr('src',$j(this).attr('dst'));
369 $j('#' + prev).after($j(this));
372 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
373 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
374 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
375 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
376 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
377 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
378 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
379 $j(this).attr('src',$j(this).attr('dst'));
385 $j('.like-rotator').hide();
388 $j('body').css('cursor', 'auto');
390 /* autocomplete @nicknames */
391 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
393 // setup videos, since VideoJS won't take care of any loaded via AJAX
398 function collapseHeight(elems) {
399 var elemName = '.wall-item-body:not(.divmore)';
400 if(typeof elems != 'undefined') {
401 elemName = elems + ' ' + elemName;
403 $j(elemName).each(function() {
404 if($j(this).height() > 350) {
405 $j('html').height($j('html').height());
406 $j(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
407 $j(this).addClass('divmore');
408 $j('html').height('auto');
413 /* function imgbright(node) {
414 $j(node).removeClass("drophide").addClass("drop");
417 function imgdull(node) {
418 $j(node).removeClass("drop").addClass("drophide");
421 // Since our ajax calls are asynchronous, we will give a few
422 // seconds for the first ajax call (setting like/dislike), then
423 // run the updater to pick up any changes and display on the page.
424 // The updater will turn any rotators off when it's done.
425 // This function will have returned long before any of these
426 // events have completed and therefore there won't be any
427 // visible feedback that anything changed without all this
428 // trickery. This still could cause confusion if the "like" ajax call
429 // is delayed and NavUpdate runs before it completes.
431 function dolike(ident,verb) {
433 $j('#like-rotator-' + ident.toString()).show();
434 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
435 // if(timer) clearTimeout(timer);
436 // timer = setTimeout(NavUpdate,3000);
440 function dostar(ident) {
441 ident = ident.toString();
442 //$j('#like-rotator-' + ident).show();
443 $j.get('starred/' + ident, function(data) {
444 if(data.match(/1/)) {
445 $j('#starred-' + ident).addClass('starred');
446 $j('#starred-' + ident).removeClass('unstarred');
447 $j('#star-' + ident).addClass('hidden');
448 $j('#unstar-' + ident).removeClass('hidden');
451 $j('#starred-' + ident).addClass('unstarred');
452 $j('#starred-' + ident).removeClass('starred');
453 $j('#star-' + ident).removeClass('hidden');
454 $j('#unstar-' + ident).addClass('hidden');
456 //$j('#like-rotator-' + ident).hide();
460 function getPosition(e) {
461 var cursor = {x:0, y:0};
462 if ( e.pageX || e.pageY ) {
467 if( e.clientX || e.clientY ) {
468 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
469 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
481 var lockvisible = false;
483 function lockview(event,id) {
484 event = event || window.event;
485 cursor = getPosition(event);
491 $j.get('lockview/' + id, function(data) {
492 $j('#panel').html(data);
493 $j('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
499 function lockviewhide() {
504 function post_comment(id) {
507 $j('body').css('cursor', 'wait');
508 $j("#comment-preview-inp-" + id).val("0");
511 $j("#comment-edit-form-" + id).serialize(),
514 $j("#comment-edit-wrapper-" + id).hide();
515 $j("#comment-edit-text-" + id).val('');
516 var tarea = document.getElementById("comment-edit-text-" + id);
518 commentClose(tarea,id);
519 if(timer) clearTimeout(timer);
520 timer = setTimeout(NavUpdate,10);
523 window.location.href=data.reload;
532 function preview_comment(id) {
533 $j("#comment-preview-inp-" + id).val("1");
534 $j("#comment-edit-preview-" + id).show();
537 $j("#comment-edit-form-" + id).serialize(),
541 $j("#comment-edit-preview-" + id).html(data.preview);
542 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
551 function showHideComments(id) {
552 if( $j("#collapsed-comments-" + id).is(":visible")) {
553 $j("#collapsed-comments-" + id).hide();
554 $j("#hide-comments-" + id).html(window.showMore);
557 $j("#collapsed-comments-" + id).show();
558 $j("#hide-comments-" + id).html(window.showFewer);
559 collapseHeight("#collapsed-comments-" + id);
564 function preview_post() {
565 $j("#jot-preview").val("1");
566 $j("#jot-preview-content").show();
567 tinyMCE.triggerSave();
570 $j("#profile-jot-form").serialize(),
573 $j("#jot-preview-content").html(data.preview);
574 $j("#jot-preview-content" + " a").click(function() { return false; });
579 $j("#jot-preview").val("0");
585 // unpause auto reloads if they are currently stopped
588 $j('#pause').html('');
593 // Converts the binary representation of data to hex
596 // discuss at: http://phpjs.org/functions/bin2hex
597 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
598 // + bugfixed by: Onno Marsman
599 // + bugfixed by: Linuxworld
600 // * example 1: bin2hex('Kev');
601 // * returns 1: '4b6576'
602 // * example 2: bin2hex(String.fromCharCode(0x00));
604 var v,i, f = 0, a = [];
608 for (i = 0; i<f; i++) {
609 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
615 function groupChangeMember(gid, cid, sec_token) {
616 $j('body .fakelink').css('cursor', 'wait');
617 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
618 $j('#group-update-wrapper').html(data);
619 $j('body .fakelink').css('cursor', 'auto');
623 function profChangeMember(gid,cid) {
624 $j('body .fakelink').css('cursor', 'wait');
625 $j.get('profperm/' + gid + '/' + cid, function(data) {
626 $j('#prof-update-wrapper').html(data);
627 $j('body .fakelink').css('cursor', 'auto');
631 function contactgroupChangeMember(gid,cid) {
632 $j('body').css('cursor', 'wait');
633 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
634 $j('body').css('cursor', 'auto');
639 function checkboxhighlight(box) {
640 if($j(box).is(':checked')) {
641 $j(box).addClass('checkeditem');
644 $j(box).removeClass('checkeditem');
648 function notifyMarkAll() {
649 $j.get('notify/mark/all', function(data) {
650 if(timer) clearTimeout(timer);
651 timer = setTimeout(NavUpdate,1000);
656 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
657 function fcFileBrowser (field_name, url, type, win) {
658 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
659 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
660 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
663 var cmsURL = baseurl+"/fbrowser/"+type+"/";
665 tinyMCE.activeEditor.windowManager.open({
667 title : 'File Browser',
668 width : 420, // Your dimensions may differ - toy around with them!
671 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
672 close_previous : "no"
680 function setupFieldRichtext(){
683 mode : "specific_textareas",
684 editor_selector: "fieldRichtext",
685 plugins : "bbcode,paste, inlinepopups",
686 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
687 theme_advanced_buttons2 : "",
688 theme_advanced_buttons3 : "",
689 theme_advanced_toolbar_location : "top",
690 theme_advanced_toolbar_align : "center",
691 theme_advanced_blockformats : "blockquote,code",
692 paste_text_sticky : true,
693 entity_encoding : "raw",
694 add_unload_trigger : false,
695 remove_linebreaks : false,
696 //force_p_newlines : false,
697 //force_br_newlines : true,
698 forced_root_block : 'div',
700 content_css: baseurl+"/view/custom_tinymce.css",
701 theme_advanced_path : false,
702 file_browser_callback : "fcFileBrowser",
708 * sprintf in javascript
709 * "{0} and {1}".format('zero','uno');
711 String.prototype.format = function() {
712 var formatted = this;
713 for (var i = 0; i < arguments.length; i++) {
714 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
715 formatted = formatted.replace(regexp, arguments[i]);
720 Array.prototype.remove = function(item) {
721 to=undefined; from=this.indexOf(item);
722 var rest = this.slice((to || from) + 1 || this.length);
723 this.length = from < 0 ? this.length + from : from;
724 return this.push.apply(this, rest);
727 function previewTheme(elm) {
728 theme = $j(elm).val();
729 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
730 $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>');