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 */
73 /*setupFieldRichtext();*/
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 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $j('section').show();
82 last_popup_button.removeClass("selected");
83 last_popup_menu = null;
84 last_popup_button = null;
88 $j('img[rel^=#]').click(function(e){
90 close_last_popup_menu(e);
91 menu = $j( $j(this).attr('rel') );
95 if (menu.attr('popup')=="false") return false;
97 // $j(this).parent().toggleClass("selected");
100 if (menu.css("display") == "none") {
101 $j(this).parent().addClass("selected");
103 if (menu.attr('id') == "nav-notifications-menu" ) $j('section').hide();
104 last_popup_menu = menu;
105 last_popup_button = $j(this).parent();
107 $j(this).parent().removeClass("selected");
109 if (menu.attr('id') == "nav-notifications-menu" ) $j('section').show();
110 last_popup_menu = null;
111 last_popup_button = null;
115 $j('html').click(function(e) {
116 close_last_popup_menu(e);
120 /*$j("a.popupbox").fancybox({
121 'transitionIn' : 'elastic',
122 'transitionOut' : 'elastic'
126 /* notifications template */
127 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
128 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
129 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
130 var notifications_empty = unescape($j("#nav-notifications-menu").html());
132 /* nav update event */
133 $j('nav').bind('nav-update', function(e,data){;
134 var invalid = $j(data).find('invalid').text();
135 if(invalid == 1) { window.location.href=window.location.href }
137 var net = $j(data).find('net').text();
138 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
139 $j('#net-update').html(net);
141 var home = $j(data).find('home').text();
142 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
143 $j('#home-update').html(home);
145 var intro = $j(data).find('intro').text();
146 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
147 $j('#intro-update').html(intro);
149 var mail = $j(data).find('mail').text();
150 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
151 $j('#mail-update').html(mail);
153 var intro = $j(data).find('intro').text();
154 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
155 $j('#intro-update-li').html(intro);
157 var mail = $j(data).find('mail').text();
158 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
159 $j('#mail-update-li').html(mail);
161 var eNotif = $j(data).find('notif')
163 if (eNotif.children("note").length==0){
164 $j("#nav-notifications-menu").html(notifications_empty);
166 nnm = $j("#nav-notifications-menu");
167 nnm.html(notifications_all + notifications_mark);
168 //nnm.attr('popup','true');
169 eNotif.children("note").each(function(){
171 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
172 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
176 notif = eNotif.attr('count');
178 $j("#nav-notifications-linkmenu").addClass("on");
180 $j("#nav-notifications-linkmenu").removeClass("on");
182 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
183 $j('#notify-update').html(notif);
185 var eSysmsg = $j(data).find('sysmsgs');
186 eSysmsg.children("notice").each(function(){
187 text = $j(this).text();
188 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 1500 });
190 eSysmsg.children("info").each(function(){
191 text = $j(this).text();
192 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
199 // Allow folks to stop the ajax page updates with the pause/break key
200 /* $j(document).keydown(function(event) {
201 if(event.keyCode == '8') {
202 var target = event.target || event.srcElement;
203 if (!/input|textarea/i.test(target.nodeName)) {
207 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
208 event.preventDefault();
209 if(stopped == false) {
214 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
228 function NavUpdate() {
231 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
232 $j.get(pingCmd,function(data) {
233 $j(data).find('result').each(function() {
234 // send nav-update event
235 $j('nav').trigger('nav-update', this);
242 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
243 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
244 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
245 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
246 if($j('#live-display').length) {
249 window.location.href=window.location.href
252 if($j('#live-photos').length) {
255 window.location.href=window.location.href
265 timer = setTimeout(NavUpdate,updateInterval);
268 function liveUpdate() {
269 if((src == null) || (stopped) || (! profile_uid)) { $j('.like-rotator').hide(); return; }
270 if(($j('.comment-edit-text-full').length) || (in_progress)) {
272 clearTimeout(livetime);
274 livetime = setTimeout(liveUpdate, 10000);
280 prev = 'live-' + src;
283 var udargs = ((netargs.length) ? '/' + netargs : '');
284 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
286 $j.get(update_url,function(data) {
288 // $j('.collapsed-comments',data).each(function() {
289 // var ident = $j(this).attr('id');
290 // var is_hidden = $j('#' + ident).is(':hidden');
291 // if($j('#' + ident).length) {
292 // $j('#' + ident).replaceWith($j(this));
294 // $j('#' + ident).hide();
300 $j('.tread-wrapper',data).each(function() {
301 var ident = $j(this).attr('id');
303 if($j('#' + ident).length == 0 && profile_page == 1) {
304 $j('img',this).each(function() {
305 $j(this).attr('src',$j(this).attr('dst'));
307 $j('#' + prev).after($j(this));
310 $j('img',this).each(function() {
311 $j(this).attr('src',$j(this).attr('dst'));
313 $j('#' + ident).replaceWith($j(this));
318 // reset vars for inserting individual items
320 /*prev = 'live-' + src;
322 $j('.wall-item-outside-wrapper',data).each(function() {
323 var ident = $j(this).attr('id');
325 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
326 $j('img',this).each(function() {
327 $j(this).attr('src',$j(this).attr('dst'));
329 $j('#' + prev).after($j(this));
332 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
333 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
334 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
335 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
336 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
337 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
338 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
339 $j(this).attr('src',$j(this).attr('dst'));
345 $j('.like-rotator').hide();
348 $j('body').css('cursor', 'auto');
350 /* autocomplete @nicknames */
351 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
355 function imgbright(node) {
356 $j(node).removeClass("drophide").addClass("drop");
359 function imgdull(node) {
360 $j(node).removeClass("drop").addClass("drophide");
363 // Since our ajax calls are asynchronous, we will give a few
364 // seconds for the first ajax call (setting like/dislike), then
365 // run the updater to pick up any changes and display on the page.
366 // The updater will turn any rotators off when it's done.
367 // This function will have returned long before any of these
368 // events have completed and therefore there won't be any
369 // visible feedback that anything changed without all this
370 // trickery. This still could cause confusion if the "like" ajax call
371 // is delayed and NavUpdate runs before it completes.
373 function dolike(ident,verb) {
375 $j('#like-rotator-' + ident.toString()).show();
376 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
377 // if(timer) clearTimeout(timer);
378 // timer = setTimeout(NavUpdate,3000);
382 function dostar(ident) {
383 ident = ident.toString();
384 //$j('#like-rotator-' + ident).show();
385 $j.get('starred/' + ident, function(data) {
386 if(data.match(/1/)) {
387 $j('#starred-' + ident).addClass('starred');
388 $j('#starred-' + ident).removeClass('unstarred');
389 $j('#star-' + ident).addClass('hidden');
390 $j('#unstar-' + ident).removeClass('hidden');
393 $j('#starred-' + ident).addClass('unstarred');
394 $j('#starred-' + ident).removeClass('starred');
395 $j('#star-' + ident).removeClass('hidden');
396 $j('#unstar-' + ident).addClass('hidden');
398 //$j('#like-rotator-' + ident).hide();
402 function getPosition(e) {
403 var cursor = {x:0, y:0};
404 if ( e.pageX || e.pageY ) {
409 if( e.clientX || e.clientY ) {
410 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
411 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
423 var lockvisible = false;
425 function lockview(event,id) {
426 event = event || window.event;
427 cursor = getPosition(event);
433 $j.get('lockview/' + id, function(data) {
434 $j('#panel').html(data);
435 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
441 function lockviewhide() {
446 function post_comment(id) {
449 $j('body').css('cursor', 'wait');
450 $j("#comment-preview-inp-" + id).val("0");
453 $j("#comment-edit-form-" + id).serialize(),
456 $j("#comment-edit-wrapper-" + id).hide();
457 $j("#comment-edit-text-" + id).val('');
458 var tarea = document.getElementById("comment-edit-text-" + id);
460 commentClose(tarea,id);
461 if(timer) clearTimeout(timer);
462 timer = setTimeout(NavUpdate,10);
465 window.location.href=data.reload;
474 function preview_comment(id) {
475 $j("#comment-preview-inp-" + id).val("1");
476 $j("#comment-edit-preview-" + id).show();
479 $j("#comment-edit-form-" + id).serialize(),
483 $j("#comment-edit-preview-" + id).html(data.preview);
484 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
494 function preview_post() {
495 $j("#jot-preview").val("1");
496 $j("#jot-preview-content").show();
497 tinyMCE.triggerSave();
500 $j("#profile-jot-form").serialize(),
503 $j("#jot-preview-content").html(data.preview);
504 $j("#jot-preview-content" + " a").click(function() { return false; });
509 $j("#jot-preview").val("0");
515 // unpause auto reloads if they are currently stopped
518 $j('#pause').html('');
523 // Converts the binary representation of data to hex
526 // discuss at: http://phpjs.org/functions/bin2hex
527 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
528 // + bugfixed by: Onno Marsman
529 // + bugfixed by: Linuxworld
530 // * example 1: bin2hex('Kev');
531 // * returns 1: '4b6576'
532 // * example 2: bin2hex(String.fromCharCode(0x00));
534 var v,i, f = 0, a = [];
538 for (i = 0; i<f; i++) {
539 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
545 function groupChangeMember(gid, cid, sec_token) {
546 $j('body .fakelink').css('cursor', 'wait');
547 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
548 $j('#group-update-wrapper').html(data);
549 $j('body .fakelink').css('cursor', 'auto');
553 function profChangeMember(gid,cid) {
554 $j('body .fakelink').css('cursor', 'wait');
555 $j.get('profperm/' + gid + '/' + cid, function(data) {
556 $j('#prof-update-wrapper').html(data);
557 $j('body .fakelink').css('cursor', 'auto');
561 function contactgroupChangeMember(gid,cid) {
562 $j('body').css('cursor', 'wait');
563 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
564 $j('body').css('cursor', 'auto');
569 function checkboxhighlight(box) {
570 if($j(box).is(':checked')) {
571 $j(box).addClass('checkeditem');
574 $j(box).removeClass('checkeditem');
578 function notifyMarkAll() {
579 $j.get('notify/mark/all', function(data) {
580 if(timer) clearTimeout(timer);
581 timer = setTimeout(NavUpdate,1000);
586 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
587 function fcFileBrowser (field_name, url, type, win) {
588 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
589 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
590 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
593 var cmsURL = baseurl+"/fbrowser/"+type+"/";
595 tinyMCE.activeEditor.windowManager.open({
597 title : 'File Browser',
598 width : 420, // Your dimensions may differ - toy around with them!
601 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
602 close_previous : "no"
610 function setupFieldRichtext(){
613 mode : "specific_textareas",
614 editor_selector: "fieldRichtext",
615 plugins : "bbcode,paste, inlinepopups",
616 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
617 theme_advanced_buttons2 : "",
618 theme_advanced_buttons3 : "",
619 theme_advanced_toolbar_location : "top",
620 theme_advanced_toolbar_align : "center",
621 theme_advanced_blockformats : "blockquote,code",
622 paste_text_sticky : true,
623 entity_encoding : "raw",
624 add_unload_trigger : false,
625 remove_linebreaks : false,
626 force_p_newlines : false,
627 force_br_newlines : true,
628 forced_root_block : '',
630 content_css: baseurl+"/view/custom_tinymce.css",
631 theme_advanced_path : false,
632 file_browser_callback : "fcFileBrowser",
638 * sprintf in javascript
639 * "{0} and {1}".format('zero','uno');
641 String.prototype.format = function() {
642 var formatted = this;
643 for (var i = 0; i < arguments.length; i++) {
644 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
645 formatted = formatted.replace(regexp, arguments[i]);
650 Array.prototype.remove = function(item) {
651 to=undefined; from=this.indexOf(item);
652 var rest = this.slice((to || from) + 1 || this.length);
653 this.length = from < 0 ? this.length + from : from;
654 return this.push.apply(this, rest);
657 function previewTheme(elm) {
658 theme = $j(elm).val();
659 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
660 $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>');