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(e) {
78 if( last_popup_menu ) {
79 if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
80 last_popup_menu.hide();
81 last_popup_button.removeClass("selected");
82 last_popup_menu = null;
83 last_popup_button = null;
87 $('a[rel^=#]').click(function(e){
89 close_last_popup_menu(e);
90 menu = $( $(this).attr('rel') );
94 if (menu.attr('popup')=="false") return false;
96 $(this).parent().toggleClass("selected");
97 menu.slideToggle('fast');
99 if (menu.css("display") == "none") {
100 last_popup_menu = null;
101 last_popup_button = null;
103 last_popup_menu = menu;
104 last_popup_button = $(this).parent();
108 $('html').click(function(e) {
109 close_last_popup_menu(e);
113 $("a.popupbox").fancybox({
114 'transitionIn' : 'none',
115 'transitionOut' : 'none'
119 /* notifications template */
120 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
121 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
122 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
123 var notifications_empty = unescape($("#nav-notifications-menu").html());
125 /* nav update event */
126 $('nav').bind('nav-update', function(e,data){;
127 var invalid = $(data).find('invalid').text();
128 if(invalid == 1) { window.location.href=window.location.href }
130 var net = $(data).find('net').text();
131 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
132 $('#net-update').html(net);
134 var home = $(data).find('home').text();
135 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
136 $('#home-update').html(home);
138 var intro = $(data).find('intro').text();
139 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
140 $('#intro-update').html(intro);
142 var mail = $(data).find('mail').text();
143 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
144 $('#mail-update').html(mail);
146 var intro = $(data).find('intro').text();
147 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
148 $('#intro-update-li').html(intro);
150 var mail = $(data).find('mail').text();
151 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
152 $('#mail-update-li').html(mail);
154 var eNotif = $(data).find('notif')
156 if (eNotif.children("note").length==0){
157 $("#nav-notifications-menu").html(notifications_empty);
159 nnm = $("#nav-notifications-menu");
160 nnm.html(notifications_all + notifications_mark);
161 //nnm.attr('popup','true');
162 eNotif.children("note").each(function(){
164 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
165 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
169 notif = eNotif.attr('count');
171 $("#nav-notifications-linkmenu").addClass("on");
173 $("#nav-notifications-linkmenu").removeClass("on");
175 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
176 $('#notify-update').html(notif);
178 var eSysmsg = $(data).find('sysmsgs');
179 eSysmsg.children("notice").each(function(){
180 text = $(this).text();
181 $.jGrowl(text, { sticky: true, theme: 'notice' });
183 eSysmsg.children("info").each(function(){
184 text = $(this).text();
185 $.jGrowl(text, { sticky: false, theme: 'info', life: 1500 });
192 // Allow folks to stop the ajax page updates with the pause/break key
193 $(document).keydown(function(event) {
194 if(event.keyCode == '8') {
195 var target = event.target || event.srcElement;
196 if (!/input|textarea/i.test(target.nodeName)) {
200 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
201 event.preventDefault();
202 if(stopped == false) {
207 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
221 function NavUpdate() {
224 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
225 $.get(pingCmd,function(data) {
226 $(data).find('result').each(function() {
227 // send nav-update event
228 $('nav').trigger('nav-update', this);
235 if($('#live-network').length) { src = 'network'; liveUpdate(); }
236 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
237 if($('#live-community').length) { src = 'community'; liveUpdate(); }
238 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
239 if($('#live-display').length) {
242 window.location.href=window.location.href
245 if($('#live-photos').length) {
248 window.location.href=window.location.href
258 timer = setTimeout(NavUpdate,updateInterval);
261 function liveUpdate() {
262 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
263 if(($('.comment-edit-text-full').length) || (in_progress)) {
265 clearTimeout(livetime);
267 livetime = setTimeout(liveUpdate, 10000);
273 prev = 'live-' + src;
276 var udargs = ((netargs.length) ? '/' + netargs : '');
277 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
279 $.get(update_url,function(data) {
281 // $('.collapsed-comments',data).each(function() {
282 // var ident = $(this).attr('id');
283 // var is_hidden = $('#' + ident).is(':hidden');
284 // if($('#' + ident).length) {
285 // $('#' + ident).replaceWith($(this));
287 // $('#' + ident).hide();
293 $('.tread-wrapper',data).each(function() {
294 var ident = $(this).attr('id');
296 if($('#' + ident).length == 0 && profile_page == 1) {
297 $('img',this).each(function() {
298 $(this).attr('src',$(this).attr('dst'));
300 $('#' + prev).after($(this));
303 $('img',this).each(function() {
304 $(this).attr('src',$(this).attr('dst'));
306 $('#' + ident).replaceWith($(this));
311 // reset vars for inserting individual items
313 /*prev = 'live-' + src;
315 $('.wall-item-outside-wrapper',data).each(function() {
316 var ident = $(this).attr('id');
318 if($('#' + ident).length == 0 && prev != 'live-' + src) {
319 $('img',this).each(function() {
320 $(this).attr('src',$(this).attr('dst'));
322 $('#' + prev).after($(this));
325 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
326 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
327 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
328 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
329 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
330 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
331 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
332 $(this).attr('src',$(this).attr('dst'));
338 $('.like-rotator').hide();
341 $('body').css('cursor', 'auto');
343 /* autocomplete @nicknames */
344 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
348 function imgbright(node) {
349 $(node).removeClass("drophide").addClass("drop");
352 function imgdull(node) {
353 $(node).removeClass("drop").addClass("drophide");
356 // Since our ajax calls are asynchronous, we will give a few
357 // seconds for the first ajax call (setting like/dislike), then
358 // run the updater to pick up any changes and display on the page.
359 // The updater will turn any rotators off when it's done.
360 // This function will have returned long before any of these
361 // events have completed and therefore there won't be any
362 // visible feedback that anything changed without all this
363 // trickery. This still could cause confusion if the "like" ajax call
364 // is delayed and NavUpdate runs before it completes.
366 function dolike(ident,verb) {
368 $('#like-rotator-' + ident.toString()).show();
369 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
370 // if(timer) clearTimeout(timer);
371 // timer = setTimeout(NavUpdate,3000);
375 function dostar(ident) {
376 ident = ident.toString();
377 // $('#like-rotator-' + ident).show();
378 $.get('starred/' + ident, function(data) {
379 if(data.match(/1/)) {
380 $('#starred-' + ident).addClass('starred');
381 $('#starred-' + ident).removeClass('unstarred');
382 $('#star-' + ident).addClass('hidden');
383 $('#unstar-' + ident).removeClass('hidden');
386 $('#starred-' + ident).addClass('unstarred');
387 $('#starred-' + ident).removeClass('starred');
388 $('#star-' + ident).removeClass('hidden');
389 $('#unstar-' + ident).addClass('hidden');
391 // $('#like-rotator-' + ident).hide();
395 function getPosition(e) {
396 var cursor = {x:0, y:0};
397 if ( e.pageX || e.pageY ) {
402 if( e.clientX || e.clientY ) {
403 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
404 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
416 var lockvisible = false;
418 function lockview(event,id) {
419 event = event || window.event;
420 cursor = getPosition(event);
426 $.get('lockview/' + id, function(data) {
427 $('#panel').html(data);
428 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
434 function lockviewhide() {
439 function post_comment(id) {
442 $('body').css('cursor', 'wait');
443 $("#comment-preview-inp-" + id).val("0");
446 $("#comment-edit-form-" + id).serialize(),
449 $("#comment-edit-wrapper-" + id).hide();
450 $("#comment-edit-text-" + id).val('');
451 var tarea = document.getElementById("comment-edit-text-" + id);
453 commentClose(tarea,id);
454 if(timer) clearTimeout(timer);
455 timer = setTimeout(NavUpdate,10);
458 window.location.href=data.reload;
467 function preview_comment(id) {
468 $("#comment-preview-inp-" + id).val("1");
469 $("#comment-edit-preview-" + id).show();
472 $("#comment-edit-form-" + id).serialize(),
476 $("#comment-edit-preview-" + id).html(data.preview);
477 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
487 function preview_post() {
488 $("#jot-preview").val("1");
489 $("#jot-preview-content").show();
490 tinyMCE.triggerSave();
493 $("#profile-jot-form").serialize(),
496 $("#jot-preview-content").html(data.preview);
497 $("#jot-preview-content" + " a").click(function() { return false; });
502 $("#jot-preview").val("0");
508 // unpause auto reloads if they are currently stopped
511 $('#pause').html('');
516 // Converts the binary representation of data to hex
519 // discuss at: http://phpjs.org/functions/bin2hex
520 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
521 // + bugfixed by: Onno Marsman
522 // + bugfixed by: Linuxworld
523 // * example 1: bin2hex('Kev');
524 // * returns 1: '4b6576'
525 // * example 2: bin2hex(String.fromCharCode(0x00));
527 var v,i, f = 0, a = [];
531 for (i = 0; i<f; i++) {
532 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
538 function groupChangeMember(gid, cid, sec_token) {
539 $('body .fakelink').css('cursor', 'wait');
540 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
541 $('#group-update-wrapper').html(data);
542 $('body .fakelink').css('cursor', 'auto');
546 function profChangeMember(gid,cid) {
547 $('body .fakelink').css('cursor', 'wait');
548 $.get('profperm/' + gid + '/' + cid, function(data) {
549 $('#prof-update-wrapper').html(data);
550 $('body .fakelink').css('cursor', 'auto');
554 function contactgroupChangeMember(gid,cid) {
555 $('body').css('cursor', 'wait');
556 $.get('contactgroup/' + gid + '/' + cid, function(data) {
557 $('body').css('cursor', 'auto');
562 function checkboxhighlight(box) {
563 if($(box).is(':checked')) {
564 $(box).addClass('checkeditem');
567 $(box).removeClass('checkeditem');
571 function notifyMarkAll() {
572 $.get('notify/mark/all', function(data) {
573 if(timer) clearTimeout(timer);
574 timer = setTimeout(NavUpdate,1000);
579 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
580 function fcFileBrowser (field_name, url, type, win) {
581 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
582 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
583 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
586 var cmsURL = baseurl+"/fbrowser/"+type+"/";
588 tinyMCE.activeEditor.windowManager.open({
590 title : 'File Browser',
591 width : 420, // Your dimensions may differ - toy around with them!
594 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
595 close_previous : "no"
603 function setupFieldRichtext(){
606 mode : "specific_textareas",
607 editor_selector: "fieldRichtext",
608 plugins : "bbcode,paste, inlinepopups",
609 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
610 theme_advanced_buttons2 : "",
611 theme_advanced_buttons3 : "",
612 theme_advanced_toolbar_location : "top",
613 theme_advanced_toolbar_align : "center",
614 theme_advanced_blockformats : "blockquote,code",
615 paste_text_sticky : true,
616 entity_encoding : "raw",
617 add_unload_trigger : false,
618 remove_linebreaks : false,
619 force_p_newlines : false,
620 force_br_newlines : true,
621 forced_root_block : '',
623 content_css: baseurl+"/view/custom_tinymce.css",
624 theme_advanced_path : false,
625 file_browser_callback : "fcFileBrowser",
631 * sprintf in javascript
632 * "{0} and {1}".format('zero','uno');
634 String.prototype.format = function() {
635 var formatted = this;
636 for (var i = 0; i < arguments.length; i++) {
637 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
638 formatted = formatted.replace(regexp, arguments[i]);
643 Array.prototype.remove = function(item) {
644 to=undefined; from=this.indexOf(item);
645 var rest = this.slice((to || from) + 1 || this.length);
646 this.length = from < 0 ? this.length + from : from;
647 return this.push.apply(this, rest);
650 function previewTheme(elm) {
651 theme = $(elm).val();
652 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
653 $('#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>');