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('.toplevel_item',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");
353 var bimgs = $j(".wall-item-body > img").not(function() { return this.complete; });
354 var bimgcount = bimgs.length;
357 bimgs.load(function() {
371 function collapseHeight() {
372 $j(".wall-item-body").each(function() {
373 if($j(this).height() > 310) {
374 if(! $j(this).hasClass('divmore')) {
375 $j(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
376 $j(this).addClass('divmore');
382 function imgbright(node) {
383 $j(node).removeClass("drophide").addClass("drop");
386 function imgdull(node) {
387 $j(node).removeClass("drop").addClass("drophide");
390 // Since our ajax calls are asynchronous, we will give a few
391 // seconds for the first ajax call (setting like/dislike), then
392 // run the updater to pick up any changes and display on the page.
393 // The updater will turn any rotators off when it's done.
394 // This function will have returned long before any of these
395 // events have completed and therefore there won't be any
396 // visible feedback that anything changed without all this
397 // trickery. This still could cause confusion if the "like" ajax call
398 // is delayed and NavUpdate runs before it completes.
400 function dolike(ident,verb) {
402 $j('#like-rotator-' + ident.toString()).show();
403 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
404 // if(timer) clearTimeout(timer);
405 // timer = setTimeout(NavUpdate,3000);
409 function dostar(ident) {
410 ident = ident.toString();
411 //$j('#like-rotator-' + ident).show();
412 $j.get('starred/' + ident, function(data) {
413 if(data.match(/1/)) {
414 $j('#starred-' + ident).addClass('starred');
415 $j('#starred-' + ident).removeClass('unstarred');
416 $j('#star-' + ident).addClass('hidden');
417 $j('#unstar-' + ident).removeClass('hidden');
420 $j('#starred-' + ident).addClass('unstarred');
421 $j('#starred-' + ident).removeClass('starred');
422 $j('#star-' + ident).removeClass('hidden');
423 $j('#unstar-' + ident).addClass('hidden');
425 //$j('#like-rotator-' + ident).hide();
429 function getPosition(e) {
430 var cursor = {x:0, y:0};
431 if ( e.touches[0].pageX || e.touches[0].pageY ) {
432 cursor.x = e.touches[0].pageX;
433 cursor.y = e.touches[0].pageY;
436 if( e.touches[0].clientX || e.touches[0].clientY ) {
437 cursor.x = e.touches[0].clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
438 cursor.y = e.touches[0].clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
441 if( e.touches[0].x || e.touches[0].y ) {
442 cursor.touches[0].x = e.touches[0].x;
443 cursor.touches[0].y = e.touches[0].y;
450 var lockvisible = false;
452 function lockview(event,id) {
453 event = event || window.event;
454 cursor = getPosition(event);
460 $j.get('lockview/' + id, function(data) {
461 $j('#panel').html(data);
462 $j('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
468 function lockviewhide() {
473 function post_comment(id) {
476 $j('body').css('cursor', 'wait');
477 $j("#comment-preview-inp-" + id).val("0");
480 $j("#comment-edit-form-" + id).serialize(),
483 $j("#comment-edit-wrapper-" + id).hide();
484 $j("#comment-edit-text-" + id).val('');
485 var tarea = document.getElementById("comment-edit-text-" + id);
487 commentClose(tarea,id);
488 if(timer) clearTimeout(timer);
489 timer = setTimeout(NavUpdate,10);
492 window.location.href=data.reload;
501 function preview_comment(id) {
502 $j("#comment-preview-inp-" + id).val("1");
503 $j("#comment-edit-preview-" + id).show();
506 $j("#comment-edit-form-" + id).serialize(),
510 $j("#comment-edit-preview-" + id).html(data.preview);
511 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
521 function preview_post() {
522 $j("#jot-preview").val("1");
523 $j("#jot-preview-content").show();
524 tinyMCE.triggerSave();
527 $j("#profile-jot-form").serialize(),
530 $j("#jot-preview-content").html(data.preview);
531 $j("#jot-preview-content" + " a").click(function() { return false; });
536 $j("#jot-preview").val("0");
542 // unpause auto reloads if they are currently stopped
545 $j('#pause').html('');
550 // Converts the binary representation of data to hex
553 // discuss at: http://phpjs.org/functions/bin2hex
554 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
555 // + bugfixed by: Onno Marsman
556 // + bugfixed by: Linuxworld
557 // * example 1: bin2hex('Kev');
558 // * returns 1: '4b6576'
559 // * example 2: bin2hex(String.fromCharCode(0x00));
561 var v,i, f = 0, a = [];
565 for (i = 0; i<f; i++) {
566 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
572 function groupChangeMember(gid, cid, sec_token) {
573 $j('body .fakelink').css('cursor', 'wait');
574 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
575 $j('#group-update-wrapper').html(data);
576 $j('body .fakelink').css('cursor', 'auto');
580 function profChangeMember(gid,cid) {
581 $j('body .fakelink').css('cursor', 'wait');
582 $j.get('profperm/' + gid + '/' + cid, function(data) {
583 $j('#prof-update-wrapper').html(data);
584 $j('body .fakelink').css('cursor', 'auto');
588 function contactgroupChangeMember(gid,cid) {
589 $j('body').css('cursor', 'wait');
590 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
591 $j('body').css('cursor', 'auto');
596 function checkboxhighlight(box) {
597 if($j(box).is(':checked')) {
598 $j(box).addClass('checkeditem');
601 $j(box).removeClass('checkeditem');
605 function notifyMarkAll() {
606 $j.get('notify/mark/all', function(data) {
607 if(timer) clearTimeout(timer);
608 timer = setTimeout(NavUpdate,1000);
613 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
614 function fcFileBrowser (field_name, url, type, win) {
615 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
616 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
617 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
620 var cmsURL = baseurl+"/fbrowser/"+type+"/";
622 tinyMCE.activeEditor.windowManager.open({
624 title : 'File Browser',
625 width : 420, // Your dimensions may differ - toy around with them!
628 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
629 close_previous : "no"
637 function setupFieldRichtext(){
640 mode : "specific_textareas",
641 editor_selector: "fieldRichtext",
642 plugins : "bbcode,paste, inlinepopups",
643 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
644 theme_advanced_buttons2 : "",
645 theme_advanced_buttons3 : "",
646 theme_advanced_toolbar_location : "top",
647 theme_advanced_toolbar_align : "center",
648 theme_advanced_blockformats : "blockquote,code",
649 paste_text_sticky : true,
650 entity_encoding : "raw",
651 add_unload_trigger : false,
652 remove_linebreaks : false,
653 force_p_newlines : false,
654 force_br_newlines : true,
655 forced_root_block : '',
657 content_css: baseurl+"/view/custom_tinymce.css",
658 theme_advanced_path : false,
659 file_browser_callback : "fcFileBrowser",
665 * sprintf in javascript
666 * "{0} and {1}".format('zero','uno');
668 String.prototype.format = function() {
669 var formatted = this;
670 for (var i = 0; i < arguments.length; i++) {
671 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
672 formatted = formatted.replace(regexp, arguments[i]);
677 Array.prototype.remove = function(item) {
678 to=undefined; from=this.indexOf(item);
679 var rest = this.slice((to || from) + 1 || this.length);
680 this.length = from < 0 ? this.length + from : from;
681 return this.push.apply(this, rest);
684 function previewTheme(elm) {
685 theme = $j(elm).val();
686 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
687 $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>');