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 $.ajaxSetup({cache: false});
39 msie = $.browser.msie ;
41 /* setup tooltips *//*
42 $("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 $(".onoff input").each(function(){
57 id = $(this).attr("id");
58 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
61 $(".onoff > a").click(function(event){
62 event.preventDefault();
63 var input = $(this).siblings("input");
64 var val = 1-input.val();
65 var id = input.attr("id");
66 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
67 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
72 /* setup field_richtext */
76 function close_last_popup_menu() {
78 last_popup_menu.hide();
79 last_popup_button.removeClass("selected");
80 last_popup_menu = null;
81 last_popup_button = null;
84 $('a[rel^=#]').click(function(e){
85 close_last_popup_menu();
86 menu = $( $(this).attr('rel') );
89 if (menu.attr('popup')=="false") return false;
90 $(this).parent().toggleClass("selected");
92 if (menu.css("display") == "none") {
93 last_popup_menu = null;
94 last_popup_button = null;
96 last_popup_menu = menu;
97 last_popup_button = $(this).parent();
101 $('html').click(function() {
102 close_last_popup_menu();
106 $("a.popupbox").fancybox({
107 'transitionIn' : 'elastic',
108 'transitionOut' : 'elastic'
112 /* notifications template */
113 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
114 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
115 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
116 var notifications_empty = unescape($("#nav-notifications-menu").html());
118 /* nav update event */
119 $('nav').bind('nav-update', function(e,data){;
120 var net = $(data).find('net').text();
121 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
122 $('#net-update').html(net);
124 var home = $(data).find('home').text();
125 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
126 $('#home-update').html(home);
128 var intro = $(data).find('intro').text();
129 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
130 $('#intro-update').html(intro);
132 var mail = $(data).find('mail').text();
133 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
134 $('#mail-update').html(mail);
136 var intro = $(data).find('intro').text();
137 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
138 $('#intro-update-li').html(intro);
140 var mail = $(data).find('mail').text();
141 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
142 $('#mail-update-li').html(mail);
144 var eNotif = $(data).find('notif')
146 if (eNotif.children("note").length==0){
147 $("#nav-notifications-menu").html(notifications_empty);
149 nnm = $("#nav-notifications-menu");
150 nnm.html(notifications_all + notifications_mark);
151 //nnm.attr('popup','true');
152 eNotif.children("note").each(function(){
154 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
155 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
159 notif = eNotif.attr('count');
161 $("#nav-notifications-linkmenu").addClass("on");
163 $("#nav-notifications-linkmenu").removeClass("on");
165 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
166 $('#notify-update').html(notif);
168 var eSysmsg = $(data).find('sysmsgs');
169 eSysmsg.children("notice").each(function(){
170 text = $(this).text();
171 $.jGrowl(text, { sticky: true, theme: 'notice' });
173 eSysmsg.children("info").each(function(){
174 text = $(this).text();
175 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
182 // Allow folks to stop the ajax page updates with the pause/break key
183 $(document).keydown(function(event) {
184 if(event.keyCode == '8') {
185 var target = event.target || event.srcElement;
186 if (!/input|textarea/i.test(target.nodeName)) {
190 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
191 event.preventDefault();
192 if(stopped == false) {
197 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
211 function NavUpdate() {
214 $.get("ping",function(data) {
215 $(data).find('result').each(function() {
216 // send nav-update event
217 $('nav').trigger('nav-update', this);
222 if($('#live-network').length) { src = 'network'; liveUpdate(); }
223 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
224 if($('#live-community').length) { src = 'community'; liveUpdate(); }
225 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
226 if($('#live-display').length) {
229 window.location.href=window.location.href
232 if($('#live-photos').length) {
235 window.location.href=window.location.href
245 timer = setTimeout(NavUpdate,updateInterval);
248 function liveUpdate() {
249 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
250 if(($('.comment-edit-text-full').length) || (in_progress)) {
252 clearTimeout(livetime);
254 livetime = setTimeout(liveUpdate, 10000);
260 prev = 'live-' + src;
263 var udargs = ((netargs.length) ? '/' + netargs : '');
264 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
266 $.get(update_url,function(data) {
268 // $('.collapsed-comments',data).each(function() {
269 // var ident = $(this).attr('id');
270 // var is_hidden = $('#' + ident).is(':hidden');
271 // if($('#' + ident).length) {
272 // $('#' + ident).replaceWith($(this));
274 // $('#' + ident).hide();
280 $('.tread-wrapper',data).each(function() {
281 var ident = $(this).attr('id');
283 if($('#' + ident).length == 0 && profile_page == 1) {
284 $('img',this).each(function() {
285 $(this).attr('src',$(this).attr('dst'));
287 $('#' + prev).after($(this));
290 $('img',this).each(function() {
291 $(this).attr('src',$(this).attr('dst'));
293 $('#' + ident).replaceWith($(this));
298 // reset vars for inserting individual items
300 /* prev = 'live-' + src;
302 $('.wall-item-outside-wrapper',data).each(function() {
303 var ident = $(this).attr('id');
305 if($('#' + ident).length == 0 && prev != 'live-' + src) {
306 $('img',this).each(function() {
307 $(this).attr('src',$(this).attr('dst'));
309 $('#' + prev).after($(this));
312 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
313 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
314 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
315 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
316 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
317 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
318 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
319 $(this).attr('src',$(this).attr('dst'));
325 $('.like-rotator').hide();
328 $('body').css('cursor', 'auto');
330 /* autocomplete @nicknames */
331 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
335 function imgbright(node) {
336 $(node).removeClass("drophide").addClass("drop");
339 function imgdull(node) {
340 $(node).removeClass("drop").addClass("drophide");
343 // Since our ajax calls are asynchronous, we will give a few
344 // seconds for the first ajax call (setting like/dislike), then
345 // run the updater to pick up any changes and display on the page.
346 // The updater will turn any rotators off when it's done.
347 // This function will have returned long before any of these
348 // events have completed and therefore there won't be any
349 // visible feedback that anything changed without all this
350 // trickery. This still could cause confusion if the "like" ajax call
351 // is delayed and NavUpdate runs before it completes.
353 function dolike(ident,verb) {
355 $('#like-rotator-' + ident.toString()).show();
356 $.get('like/' + ident.toString() + '?verb=' + verb );
357 if(timer) clearTimeout(timer);
358 timer = setTimeout(NavUpdate,3000);
362 function dostar(ident) {
363 ident = ident.toString();
364 $('#like-rotator-' + ident).show();
365 $.get('starred/' + ident, function(data) {
366 if(data.match(/1/)) {
367 $('#starred-' + ident).addClass('starred');
368 $('#starred-' + ident).removeClass('unstarred');
369 $('#star-' + ident).addClass('hidden');
370 $('#unstar-' + ident).removeClass('hidden');
373 $('#starred-' + ident).addClass('unstarred');
374 $('#starred-' + ident).removeClass('starred');
375 $('#star-' + ident).removeClass('hidden');
376 $('#unstar-' + ident).addClass('hidden');
378 $('#like-rotator-' + ident).hide();
382 function getPosition(e) {
383 var cursor = {x:0, y:0};
384 if ( e.pageX || e.pageY ) {
389 if( e.clientX || e.clientY ) {
390 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
391 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
403 var lockvisible = false;
405 function lockview(event,id) {
406 event = event || window.event;
407 cursor = getPosition(event);
413 $.get('lockview/' + id, function(data) {
414 $('#panel').html(data);
415 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
421 function lockviewhide() {
426 function post_comment(id) {
429 $('body').css('cursor', 'wait');
430 $("#comment-preview-inp-" + id).val("0");
433 $("#comment-edit-form-" + id).serialize(),
436 $("#comment-edit-wrapper-" + id).hide();
437 $("#comment-edit-text-" + id).val('');
438 var tarea = document.getElementById("comment-edit-text-" + id);
440 commentClose(tarea,id);
441 if(timer) clearTimeout(timer);
442 timer = setTimeout(NavUpdate,10);
445 window.location.href=data.reload;
454 function preview_comment(id) {
455 $("#comment-preview-inp-" + id).val("1");
456 $("#comment-edit-preview-" + id).show();
459 $("#comment-edit-form-" + id).serialize(),
463 $("#comment-edit-preview-" + id).html(data.preview);
464 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
474 function preview_post() {
475 $("#jot-preview").val("1");
476 $("#jot-preview-content").show();
477 tinyMCE.triggerSave();
480 $("#profile-jot-form").serialize(),
483 $("#jot-preview-content").html(data.preview);
484 $("#jot-preview-content" + " a").click(function() { return false; });
489 $("#jot-preview").val("0");
495 // unpause auto reloads if they are currently stopped
498 $('#pause').html('');
503 // Converts the binary representation of data to hex
506 // discuss at: http://phpjs.org/functions/bin2hex
507 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
508 // + bugfixed by: Onno Marsman
509 // + bugfixed by: Linuxworld
510 // * example 1: bin2hex('Kev');
511 // * returns 1: '4b6576'
512 // * example 2: bin2hex(String.fromCharCode(0x00));
514 var v,i, f = 0, a = [];
518 for (i = 0; i<f; i++) {
519 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
525 function groupChangeMember(gid, cid, sec_token) {
526 $('body .fakelink').css('cursor', 'wait');
527 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
528 $('#group-update-wrapper').html(data);
529 $('body .fakelink').css('cursor', 'auto');
533 function profChangeMember(gid,cid) {
534 $('body .fakelink').css('cursor', 'wait');
535 $.get('profperm/' + gid + '/' + cid, function(data) {
536 $('#prof-update-wrapper').html(data);
537 $('body .fakelink').css('cursor', 'auto');
541 function contactgroupChangeMember(gid,cid) {
542 $('body').css('cursor', 'wait');
543 $.get('contactgroup/' + gid + '/' + cid, function(data) {
544 $('body').css('cursor', 'auto');
549 function checkboxhighlight(box) {
550 if($(box).is(':checked')) {
551 $(box).addClass('checkeditem');
554 $(box).removeClass('checkeditem');
558 function notifyMarkAll() {
559 $.get('notify/mark/all', function(data) {
560 if(timer) clearTimeout(timer);
561 timer = setTimeout(NavUpdate,1000);
566 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
567 function fcFileBrowser (field_name, url, type, win) {
568 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
569 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
570 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
573 var cmsURL = baseurl+"/fbrowser/"+type+"/";
575 tinyMCE.activeEditor.windowManager.open({
577 title : 'File Browser',
578 width : 420, // Your dimensions may differ - toy around with them!
581 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
582 close_previous : "no"
590 function setupFieldRichtext(){
593 mode : "specific_textareas",
594 editor_selector: "fieldRichtext",
595 plugins : "bbcode,paste, inlinepopups",
596 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
597 theme_advanced_buttons2 : "",
598 theme_advanced_buttons3 : "",
599 theme_advanced_toolbar_location : "top",
600 theme_advanced_toolbar_align : "center",
601 theme_advanced_blockformats : "blockquote,code",
602 paste_text_sticky : true,
603 entity_encoding : "raw",
604 add_unload_trigger : false,
605 remove_linebreaks : false,
606 force_p_newlines : false,
607 force_br_newlines : true,
608 forced_root_block : '',
610 content_css: baseurl+"/view/custom_tinymce.css",
611 theme_advanced_path : false,
612 file_browser_callback : "fcFileBrowser",
618 * sprintf in javascript
619 * "{0} and {1}".format('zero','uno');
621 String.prototype.format = function() {
622 var formatted = this;
623 for (var i = 0; i < arguments.length; i++) {
624 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
625 formatted = formatted.replace(regexp, arguments[i]);
630 Array.prototype.remove = function(item) {
631 to=undefined; from=this.indexOf(item);
632 var rest = this.slice((to || from) + 1 || this.length);
633 this.length = from < 0 ? this.length + from : from;
634 return this.push.apply(this, rest);
637 function previewTheme(elm) {
638 theme = $(elm).val();
639 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
640 $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><a href="' + data.img + '"><img src="' + data.img + '" width="320" height="240" alt="' + theme + '" /></a>');