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 ;
43 /* setup tooltips *//*
44 $j("a,.tt").each(function(){
47 if (e.hasClass("tttop")) pos="top";
48 if (e.hasClass("ttbottom")) pos="bottom";
49 if (e.hasClass("ttleft")) pos="left";
50 if (e.hasClass("ttright")) pos="right";
51 e.tipTip({defaultPosition: pos, edgeOffset: 8});
56 /* setup onoff widgets */
57 $j(".onoff input").each(function(){
59 id = $j(this).attr("id");
60 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
63 $j(".onoff > a").click(function(event){
64 event.preventDefault();
65 var input = $j(this).siblings("input");
66 var val = 1-input.val();
67 var id = input.attr("id");
68 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
69 $j("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
74 /* setup field_richtext */
78 function close_last_popup_menu(e) {
80 if( last_popup_menu ) {
81 if( '#' + last_popup_menu.attr('id') !== $j(e.target).attr('rel')) {
82 last_popup_menu.hide();
83 last_popup_button.removeClass("selected");
84 last_popup_menu = null;
85 last_popup_button = null;
89 $j('a[rel^=#]').click(function(e){
91 close_last_popup_menu(e);
92 menu = $j( $j(this).attr('rel') );
96 if (menu.attr('popup')=="false") return false;
98 $j(this).parent().toggleClass("selected");
99 menu.slideToggle('fast');
101 if (menu.css("display") == "none") {
102 last_popup_menu = null;
103 last_popup_button = null;
105 last_popup_menu = menu;
106 last_popup_button = $j(this).parent();
110 $j('html').click(function(e) {
111 close_last_popup_menu(e);
115 $j("a.popupbox").fancybox({
116 'transitionIn' : 'none',
117 'transitionOut' : 'none'
121 /* notifications template */
122 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
123 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
124 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
125 var notifications_empty = unescape($j("#nav-notifications-menu").html());
127 /* nav update event */
128 $j('nav').bind('nav-update', function(e,data){;
129 var invalid = $j(data).find('invalid').text();
130 if(invalid == 1) { window.location.href=window.location.href }
132 var net = $j(data).find('net').text();
133 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
134 $j('#net-update').html(net);
136 var home = $j(data).find('home').text();
137 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
138 $j('#home-update').html(home);
140 var intro = $j(data).find('intro').text();
141 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
142 $j('#intro-update').html(intro);
144 var mail = $j(data).find('mail').text();
145 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
146 $j('#mail-update').html(mail);
148 var intro = $j(data).find('intro').text();
149 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
150 $j('#intro-update-li').html(intro);
152 var mail = $j(data).find('mail').text();
153 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
154 $j('#mail-update-li').html(mail);
156 var eNotif = $j(data).find('notif')
158 if (eNotif.children("note").length==0){
159 $j("#nav-notifications-menu").html(notifications_empty);
161 nnm = $j("#nav-notifications-menu");
162 nnm.html(notifications_all + notifications_mark);
163 //nnm.attr('popup','true');
164 eNotif.children("note").each(function(){
166 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
167 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
171 notif = eNotif.attr('count');
173 $j("#nav-notifications-linkmenu").addClass("on");
175 $j("#nav-notifications-linkmenu").removeClass("on");
177 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
178 $j('#notify-update').html(notif);
180 var eSysmsg = $j(data).find('sysmsgs');
181 eSysmsg.children("notice").each(function(){
182 text = $j(this).text();
183 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 3000 }); // originally: sticky: true,
185 eSysmsg.children("info").each(function(){
186 text = $j(this).text();
187 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
194 // Allow folks to stop the ajax page updates with the pause/break key
195 $j(document).keydown(function(event) {
196 if(event.keyCode == '8') {
197 var target = event.target || event.srcElement;
198 if (!/input|textarea/i.test(target.nodeName)) {
202 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
203 event.preventDefault();
204 if(stopped == false) {
209 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
223 function NavUpdate() {
226 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
227 $j.get(pingCmd,function(data) {
228 $j(data).find('result').each(function() {
229 // send nav-update event
230 $j('nav').trigger('nav-update', this);
237 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
238 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
239 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
240 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
241 if($j('#live-display').length) { src = 'display'; liveUpdate(); }
242 /*if($j('#live-display').length) {
245 window.location.href=window.location.href
248 if($j('#live-photos').length) {
251 window.location.href=window.location.href
261 timer = setTimeout(NavUpdate,updateInterval);
264 function liveUpdate() {
265 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
266 if(($j('.comment-edit-text-full').length) || (in_progress)) {
268 clearTimeout(livetime);
270 livetime = setTimeout(liveUpdate, 10000);
276 prev = 'live-' + src;
279 var udargs = ((netargs.length) ? '/' + netargs : '');
280 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
282 $j.get(update_url,function(data) {
284 // $j('.collapsed-comments',data).each(function() {
285 // var ident = $j(this).attr('id');
286 // var is_hidden = $j('#' + ident).is(':hidden');
287 // if($j('#' + ident).length) {
288 // $j('#' + ident).replaceWith($j(this));
290 // $j('#' + ident).hide();
296 $j('.toplevel_item',data).each(function() {
297 var ident = $j(this).attr('id');
299 if($j('#' + ident).length == 0 && profile_page == 1) {
300 $j('img',this).each(function() {
301 $j(this).attr('src',$j(this).attr('dst'));
303 $j('#' + prev).after($j(this));
306 // Find out if the hidden comments are open, so we can keep it that way
307 // if a new comment has been posted
308 var id = $j('.hide-comments-total', this).attr('id');
309 if(typeof id != 'undefined') {
310 id = id.split('-')[3];
311 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
314 $j('img',this).each(function() {
315 $j(this).attr('src',$j(this).attr('dst'));
317 //vScroll = $j(document).scrollTop();
318 $j('html').height($j('html').height());
319 $j('#' + ident).replaceWith($j(this));
321 if(typeof id != 'undefined') {
322 if(commentsOpen) showHideComments(id);
324 $j('html').height('auto');
325 //$j(document).scrollTop(vScroll);
330 // reset vars for inserting individual items
332 /*prev = 'live-' + src;
334 $j('.wall-item-outside-wrapper',data).each(function() {
335 var ident = $j(this).attr('id');
337 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
338 $j('img',this).each(function() {
339 $j(this).attr('src',$j(this).attr('dst'));
341 $j('#' + prev).after($j(this));
344 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
345 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
346 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
347 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
348 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
349 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
350 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
351 $j(this).attr('src',$j(this).attr('dst'));
357 $j('.like-rotator').hide();
360 $j('body').css('cursor', 'auto');
362 /* autocomplete @nicknames */
363 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
370 function collapseHeight(elems) {
371 var elemName = '.wall-item-body:not(.divmore)';
372 if(typeof elems != 'undefined') {
373 elemName = elems + ' ' + elemName;
375 $j(elemName).each(function() {
376 if($j(this).height() > 450) {
377 $j('html').height($j('html').height());
378 $j(this).divgrow({ initialHeight: 400, showBrackets: false, speed: 0 });
379 $j(this).addClass('divmore');
380 $j('html').height('auto');
385 function imgbright(node) {
386 $j(node).removeClass("drophide").addClass("drop");
389 function imgdull(node) {
390 $j(node).removeClass("drop").addClass("drophide");
393 // Since our ajax calls are asynchronous, we will give a few
394 // seconds for the first ajax call (setting like/dislike), then
395 // run the updater to pick up any changes and display on the page.
396 // The updater will turn any rotators off when it's done.
397 // This function will have returned long before any of these
398 // events have completed and therefore there won't be any
399 // visible feedback that anything changed without all this
400 // trickery. This still could cause confusion if the "like" ajax call
401 // is delayed and NavUpdate runs before it completes.
403 function dolike(ident,verb) {
405 $j('#like-rotator-' + ident.toString()).show();
406 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
407 // if(timer) clearTimeout(timer);
408 // timer = setTimeout(NavUpdate,3000);
412 function dostar(ident) {
413 ident = ident.toString();
414 // $j('#like-rotator-' + ident).show();
415 $j.get('starred/' + ident, function(data) {
416 if(data.match(/1/)) {
417 $j('#starred-' + ident).addClass('starred');
418 $j('#starred-' + ident).removeClass('unstarred');
419 $j('#star-' + ident).addClass('hidden');
420 $j('#unstar-' + ident).removeClass('hidden');
423 $j('#starred-' + ident).addClass('unstarred');
424 $j('#starred-' + ident).removeClass('starred');
425 $j('#star-' + ident).removeClass('hidden');
426 $j('#unstar-' + ident).addClass('hidden');
428 // $j('#like-rotator-' + ident).hide();
432 function getPosition(e) {
433 var cursor = {x:0, y:0};
434 if ( e.pageX || e.pageY ) {
439 if( e.clientX || e.clientY ) {
440 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
441 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
453 var lockvisible = false;
455 function lockview(event,id) {
456 event = event || window.event;
457 cursor = getPosition(event);
463 $j.get('lockview/' + id, function(data) {
464 $j('#panel').html(data);
465 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
471 function lockviewhide() {
476 function post_comment(id) {
479 $j('body').css('cursor', 'wait');
480 $j("#comment-preview-inp-" + id).val("0");
483 $j("#comment-edit-form-" + id).serialize(),
486 $j("#comment-edit-wrapper-" + id).hide();
487 $j("#comment-edit-text-" + id).val('');
488 var tarea = document.getElementById("comment-edit-text-" + id);
490 commentClose(tarea,id);
491 if(timer) clearTimeout(timer);
492 timer = setTimeout(NavUpdate,10);
495 window.location.href=data.reload;
504 function preview_comment(id) {
505 $j("#comment-preview-inp-" + id).val("1");
506 $j("#comment-edit-preview-" + id).show();
509 $j("#comment-edit-form-" + id).serialize(),
513 $j("#comment-edit-preview-" + id).html(data.preview);
514 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
523 function showHideComments(id) {
524 if( $j("#collapsed-comments-" + id).is(":visible")) {
525 $j("#collapsed-comments-" + id).hide();
526 $j("#hide-comments-" + id).html(window.showMore);
529 $j("#collapsed-comments-" + id).show();
530 $j("#hide-comments-" + id).html(window.showFewer);
531 collapseHeight("#collapsed-comments-" + id);
536 function preview_post() {
537 $j("#jot-preview").val("1");
538 $j("#jot-preview-content").show();
539 tinyMCE.triggerSave();
542 $j("#profile-jot-form").serialize(),
545 $j("#jot-preview-content").html(data.preview);
546 $j("#jot-preview-content" + " a").click(function() { return false; });
551 $j("#jot-preview").val("0");
557 // unpause auto reloads if they are currently stopped
560 $j('#pause').html('');
565 // Converts the binary representation of data to hex
568 // discuss at: http://phpjs.org/functions/bin2hex
569 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
570 // + bugfixed by: Onno Marsman
571 // + bugfixed by: Linuxworld
572 // * example 1: bin2hex('Kev');
573 // * returns 1: '4b6576'
574 // * example 2: bin2hex(String.fromCharCode(0x00));
576 var v,i, f = 0, a = [];
580 for (i = 0; i<f; i++) {
581 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
587 function groupChangeMember(gid, cid, sec_token) {
588 $j('body .fakelink').css('cursor', 'wait');
589 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
590 $j('#group-update-wrapper').html(data);
591 $j('body .fakelink').css('cursor', 'auto');
595 function profChangeMember(gid,cid) {
596 $j('body .fakelink').css('cursor', 'wait');
597 $j.get('profperm/' + gid + '/' + cid, function(data) {
598 $j('#prof-update-wrapper').html(data);
599 $j('body .fakelink').css('cursor', 'auto');
603 function contactgroupChangeMember(gid,cid) {
604 $j('body').css('cursor', 'wait');
605 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
606 $j('body').css('cursor', 'auto');
611 function checkboxhighlight(box) {
612 if($j(box).is(':checked')) {
613 $j(box).addClass('checkeditem');
616 $j(box).removeClass('checkeditem');
620 function notifyMarkAll() {
621 $j.get('notify/mark/all', function(data) {
622 if(timer) clearTimeout(timer);
623 timer = setTimeout(NavUpdate,1000);
628 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
629 function fcFileBrowser (field_name, url, type, win) {
630 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
631 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
632 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
635 var cmsURL = baseurl+"/fbrowser/"+type+"/";
637 tinyMCE.activeEditor.windowManager.open({
639 title : 'File Browser',
640 width : 420, // Your dimensions may differ - toy around with them!
643 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
644 close_previous : "no"
652 function setupFieldRichtext(){
655 mode : "specific_textareas",
656 editor_selector: "fieldRichtext",
657 plugins : "bbcode,paste, inlinepopups",
658 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
659 theme_advanced_buttons2 : "",
660 theme_advanced_buttons3 : "",
661 theme_advanced_toolbar_location : "top",
662 theme_advanced_toolbar_align : "center",
663 theme_advanced_blockformats : "blockquote,code",
664 paste_text_sticky : true,
665 entity_encoding : "raw",
666 add_unload_trigger : false,
667 remove_linebreaks : false,
668 force_p_newlines : false,
669 force_br_newlines : true,
670 forced_root_block : '',
672 content_css: baseurl+"/view/custom_tinymce.css",
673 theme_advanced_path : false,
674 file_browser_callback : "fcFileBrowser",
680 * sprintf in javascript
681 * "{0} and {1}".format('zero','uno');
683 String.prototype.format = function() {
684 var formatted = this;
685 for (var i = 0; i < arguments.length; i++) {
686 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
687 formatted = formatted.replace(regexp, arguments[i]);
692 Array.prototype.remove = function(item) {
693 to=undefined; from=this.indexOf(item);
694 var rest = this.slice((to || from) + 1 || this.length);
695 this.length = from < 0 ? this.length + from : from;
696 return this.push.apply(this, rest);
699 function previewTheme(elm) {
700 theme = $j(elm).val();
701 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
702 $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>');