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 invalid = $(data).find('invalid').text();
121 if(invalid == 1) { window.location.href=window.location.href }
123 var net = $(data).find('net').text();
124 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
125 $('#net-update').html(net);
127 var home = $(data).find('home').text();
128 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
129 $('#home-update').html(home);
131 var intro = $(data).find('intro').text();
132 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
133 $('#intro-update').html(intro);
135 var mail = $(data).find('mail').text();
136 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
137 $('#mail-update').html(mail);
139 var intro = $(data).find('intro').text();
140 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
141 $('#intro-update-li').html(intro);
143 var mail = $(data).find('mail').text();
144 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
145 $('#mail-update-li').html(mail);
147 var eNotif = $(data).find('notif')
149 if (eNotif.children("note").length==0){
150 $("#nav-notifications-menu").html(notifications_empty);
152 nnm = $("#nav-notifications-menu");
153 nnm.html(notifications_all + notifications_mark);
154 //nnm.attr('popup','true');
155 eNotif.children("note").each(function(){
157 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
158 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
162 notif = eNotif.attr('count');
164 $("#nav-notifications-linkmenu").addClass("on");
166 $("#nav-notifications-linkmenu").removeClass("on");
168 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
169 $('#notify-update').html(notif);
171 var eSysmsg = $(data).find('sysmsgs');
172 eSysmsg.children("notice").each(function(){
173 text = $(this).text();
174 $.jGrowl(text, { sticky: true, theme: 'notice' });
176 eSysmsg.children("info").each(function(){
177 text = $(this).text();
178 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
185 // Allow folks to stop the ajax page updates with the pause/break key
186 $(document).keydown(function(event) {
187 if(event.keyCode == '8') {
188 var target = event.target || event.srcElement;
189 if (!/input|textarea/i.test(target.nodeName)) {
193 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
194 event.preventDefault();
195 if(stopped == false) {
200 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
214 function NavUpdate() {
217 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
218 $.get(pingCmd,function(data) {
219 $(data).find('result').each(function() {
220 // send nav-update event
221 $('nav').trigger('nav-update', this);
226 if($('#live-network').length) { src = 'network'; liveUpdate(); }
227 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
228 if($('#live-community').length) { src = 'community'; liveUpdate(); }
229 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
230 if($('#live-display').length) {
233 window.location.href=window.location.href
236 if($('#live-photos').length) {
239 window.location.href=window.location.href
249 timer = setTimeout(NavUpdate,updateInterval);
252 function liveUpdate() {
253 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
254 if(($('.comment-edit-text-full').length) || (in_progress)) {
256 clearTimeout(livetime);
258 livetime = setTimeout(liveUpdate, 10000);
264 prev = 'live-' + src;
267 var udargs = ((netargs.length) ? '/' + netargs : '');
268 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
270 $.get(update_url,function(data) {
272 // $('.collapsed-comments',data).each(function() {
273 // var ident = $(this).attr('id');
274 // var is_hidden = $('#' + ident).is(':hidden');
275 // if($('#' + ident).length) {
276 // $('#' + ident).replaceWith($(this));
278 // $('#' + ident).hide();
284 $('.tread-wrapper',data).each(function() {
285 var ident = $(this).attr('id');
287 if($('#' + ident).length == 0 && profile_page == 1) {
288 $('img',this).each(function() {
289 $(this).attr('src',$(this).attr('dst'));
291 $('#' + prev).after($(this));
294 $('img',this).each(function() {
295 $(this).attr('src',$(this).attr('dst'));
297 $('#' + ident).replaceWith($(this));
302 // reset vars for inserting individual items
304 /* prev = 'live-' + src;
306 $('.wall-item-outside-wrapper',data).each(function() {
307 var ident = $(this).attr('id');
309 if($('#' + ident).length == 0 && prev != 'live-' + src) {
310 $('img',this).each(function() {
311 $(this).attr('src',$(this).attr('dst'));
313 $('#' + prev).after($(this));
316 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
317 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
318 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
319 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
320 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
321 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
322 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
323 $(this).attr('src',$(this).attr('dst'));
329 $('.like-rotator').hide();
332 $('body').css('cursor', 'auto');
334 /* autocomplete @nicknames */
335 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
339 function imgbright(node) {
340 $(node).removeClass("drophide").addClass("drop");
343 function imgdull(node) {
344 $(node).removeClass("drop").addClass("drophide");
347 // Since our ajax calls are asynchronous, we will give a few
348 // seconds for the first ajax call (setting like/dislike), then
349 // run the updater to pick up any changes and display on the page.
350 // The updater will turn any rotators off when it's done.
351 // This function will have returned long before any of these
352 // events have completed and therefore there won't be any
353 // visible feedback that anything changed without all this
354 // trickery. This still could cause confusion if the "like" ajax call
355 // is delayed and NavUpdate runs before it completes.
357 function dolike(ident,verb) {
359 $('#like-rotator-' + ident.toString()).show();
360 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
361 // if(timer) clearTimeout(timer);
362 // timer = setTimeout(NavUpdate,3000);
366 function dostar(ident) {
367 ident = ident.toString();
368 $('#like-rotator-' + ident).show();
369 $.get('starred/' + ident, function(data) {
370 if(data.match(/1/)) {
371 $('#starred-' + ident).addClass('starred');
372 $('#starred-' + ident).removeClass('unstarred');
373 $('#star-' + ident).addClass('hidden');
374 $('#unstar-' + ident).removeClass('hidden');
377 $('#starred-' + ident).addClass('unstarred');
378 $('#starred-' + ident).removeClass('starred');
379 $('#star-' + ident).removeClass('hidden');
380 $('#unstar-' + ident).addClass('hidden');
382 $('#like-rotator-' + ident).hide();
386 function getPosition(e) {
387 var cursor = {x:0, y:0};
388 if ( e.pageX || e.pageY ) {
393 if( e.clientX || e.clientY ) {
394 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
395 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
407 var lockvisible = false;
409 function lockview(event,id) {
410 event = event || window.event;
411 cursor = getPosition(event);
417 $.get('lockview/' + id, function(data) {
418 $('#panel').html(data);
419 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
425 function lockviewhide() {
430 function post_comment(id) {
433 $('body').css('cursor', 'wait');
434 $("#comment-preview-inp-" + id).val("0");
437 $("#comment-edit-form-" + id).serialize(),
440 $("#comment-edit-wrapper-" + id).hide();
441 $("#comment-edit-text-" + id).val('');
442 var tarea = document.getElementById("comment-edit-text-" + id);
444 commentClose(tarea,id);
445 if(timer) clearTimeout(timer);
446 timer = setTimeout(NavUpdate,10);
449 window.location.href=data.reload;
458 function preview_comment(id) {
459 $("#comment-preview-inp-" + id).val("1");
460 $("#comment-edit-preview-" + id).show();
463 $("#comment-edit-form-" + id).serialize(),
467 $("#comment-edit-preview-" + id).html(data.preview);
468 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
478 function preview_post() {
479 $("#jot-preview").val("1");
480 $("#jot-preview-content").show();
481 tinyMCE.triggerSave();
484 $("#profile-jot-form").serialize(),
487 $("#jot-preview-content").html(data.preview);
488 $("#jot-preview-content" + " a").click(function() { return false; });
493 $("#jot-preview").val("0");
499 // unpause auto reloads if they are currently stopped
502 $('#pause').html('');
507 // Converts the binary representation of data to hex
510 // discuss at: http://phpjs.org/functions/bin2hex
511 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
512 // + bugfixed by: Onno Marsman
513 // + bugfixed by: Linuxworld
514 // * example 1: bin2hex('Kev');
515 // * returns 1: '4b6576'
516 // * example 2: bin2hex(String.fromCharCode(0x00));
518 var v,i, f = 0, a = [];
522 for (i = 0; i<f; i++) {
523 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
529 function groupChangeMember(gid, cid, sec_token) {
530 $('body .fakelink').css('cursor', 'wait');
531 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
532 $('#group-update-wrapper').html(data);
533 $('body .fakelink').css('cursor', 'auto');
537 function profChangeMember(gid,cid) {
538 $('body .fakelink').css('cursor', 'wait');
539 $.get('profperm/' + gid + '/' + cid, function(data) {
540 $('#prof-update-wrapper').html(data);
541 $('body .fakelink').css('cursor', 'auto');
545 function contactgroupChangeMember(gid,cid) {
546 $('body').css('cursor', 'wait');
547 $.get('contactgroup/' + gid + '/' + cid, function(data) {
548 $('body').css('cursor', 'auto');
553 function checkboxhighlight(box) {
554 if($(box).is(':checked')) {
555 $(box).addClass('checkeditem');
558 $(box).removeClass('checkeditem');
562 function notifyMarkAll() {
563 $.get('notify/mark/all', function(data) {
564 if(timer) clearTimeout(timer);
565 timer = setTimeout(NavUpdate,1000);
570 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
571 function fcFileBrowser (field_name, url, type, win) {
572 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
573 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
574 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
577 var cmsURL = baseurl+"/fbrowser/"+type+"/";
579 tinyMCE.activeEditor.windowManager.open({
581 title : 'File Browser',
582 width : 420, // Your dimensions may differ - toy around with them!
585 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
586 close_previous : "no"
594 function setupFieldRichtext(){
597 mode : "specific_textareas",
598 editor_selector: "fieldRichtext",
599 plugins : "bbcode,paste, inlinepopups",
600 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
601 theme_advanced_buttons2 : "",
602 theme_advanced_buttons3 : "",
603 theme_advanced_toolbar_location : "top",
604 theme_advanced_toolbar_align : "center",
605 theme_advanced_blockformats : "blockquote,code",
606 paste_text_sticky : true,
607 entity_encoding : "raw",
608 add_unload_trigger : false,
609 remove_linebreaks : false,
610 force_p_newlines : false,
611 force_br_newlines : true,
612 forced_root_block : '',
614 content_css: baseurl+"/view/custom_tinymce.css",
615 theme_advanced_path : false,
616 file_browser_callback : "fcFileBrowser",
622 * sprintf in javascript
623 * "{0} and {1}".format('zero','uno');
625 String.prototype.format = function() {
626 var formatted = this;
627 for (var i = 0; i < arguments.length; i++) {
628 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
629 formatted = formatted.replace(regexp, arguments[i]);
634 Array.prototype.remove = function(item) {
635 to=undefined; from=this.indexOf(item);
636 var rest = this.slice((to || from) + 1 || this.length);
637 this.length = from < 0 ? this.length + from : from;
638 return this.push.apply(this, rest);
641 function previewTheme(elm) {
642 theme = $(elm).val();
643 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
644 $('#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>');