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 $('a[rel^=#]').click(function(e){
77 menu = $( $(this).attr('rel') );
80 if (menu.attr('popup')=="false") return false;
81 $(this).parent().toggleClass("selected");
83 if (menu.css("display") == "none") {
84 last_popup_menu = null;
85 last_popup_button = null;
87 last_popup_menu = menu;
88 last_popup_button = $(this).parent();
92 $('html').click(function() {
94 last_popup_menu.hide();
95 last_popup_button.removeClass("selected");
96 last_popup_menu = null;
97 last_popup_button = null;
102 $("a.popupbox").fancybox({
103 'transitionIn' : 'elastic',
104 'transitionOut' : 'elastic'
108 /* notifications template */
109 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
110 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
111 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
112 var notifications_empty = unescape($("#nav-notifications-menu").html());
114 /* nav update event */
115 $('nav').bind('nav-update', function(e,data){;
116 var net = $(data).find('net').text();
117 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
118 $('#net-update').html(net);
120 var home = $(data).find('home').text();
121 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
122 $('#home-update').html(home);
124 var intro = $(data).find('intro').text();
125 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
126 $('#intro-update').html(intro);
128 var mail = $(data).find('mail').text();
129 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
130 $('#mail-update').html(mail);
132 var intro = $(data).find('intro').text();
133 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
134 $('#intro-update-li').html(intro);
136 var mail = $(data).find('mail').text();
137 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
138 $('#mail-update-li').html(mail);
140 var eNotif = $(data).find('notif')
142 if (eNotif.children("note").length==0){
143 $("#nav-notifications-menu").html(notifications_empty);
145 nnm = $("#nav-notifications-menu");
146 nnm.html(notifications_all + notifications_mark);
147 //nnm.attr('popup','true');
148 eNotif.children("note").each(function(){
150 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
151 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
155 notif = eNotif.attr('count');
157 $("#nav-notifications-linkmenu").addClass("on");
159 $("#nav-notifications-linkmenu").removeClass("on");
161 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
162 $('#notify-update').html(notif);
164 var eSysmsg = $(data).find('sysmsgs');
165 eSysmsg.children("notice").each(function(){
166 text = $(this).text();
167 $.jGrowl(text, { sticky: true, theme: 'notice' });
169 eSysmsg.children("info").each(function(){
170 text = $(this).text();
171 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
178 // Allow folks to stop the ajax page updates with the pause/break key
179 $(document).keydown(function(event) {
180 if(event.keyCode == '8') {
181 var target = event.target || event.srcElement;
182 if (!/input|textarea/i.test(target.nodeName)) {
186 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
187 event.preventDefault();
188 if(stopped == false) {
193 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
207 function NavUpdate() {
210 $.get("ping",function(data) {
211 $(data).find('result').each(function() {
212 // send nav-update event
213 $('nav').trigger('nav-update', this);
218 if($('#live-network').length) { src = 'network'; liveUpdate(); }
219 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
220 if($('#live-community').length) { src = 'community'; liveUpdate(); }
221 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
222 if($('#live-display').length) {
225 window.location.href=window.location.href
228 if($('#live-photos').length) {
231 window.location.href=window.location.href
241 timer = setTimeout(NavUpdate,updateInterval);
244 function liveUpdate() {
245 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
246 if(($('.comment-edit-text-full').length) || (in_progress)) {
248 clearTimeout(livetime);
250 livetime = setTimeout(liveUpdate, 10000);
256 prev = 'live-' + src;
259 var udargs = ((netargs.length) ? '/' + netargs : '');
260 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
262 $.get(update_url,function(data) {
264 // $('.collapsed-comments',data).each(function() {
265 // var ident = $(this).attr('id');
266 // var is_hidden = $('#' + ident).is(':hidden');
267 // if($('#' + ident).length) {
268 // $('#' + ident).replaceWith($(this));
270 // $('#' + ident).hide();
276 $('.tread-wrapper',data).each(function() {
277 var ident = $(this).attr('id');
279 if($('#' + ident).length == 0 && profile_page == 1) {
280 $('img',this).each(function() {
281 $(this).attr('src',$(this).attr('dst'));
283 $('#' + prev).after($(this));
286 $('img',this).each(function() {
287 $(this).attr('src',$(this).attr('dst'));
289 $('#' + ident).replaceWith($(this));
294 // reset vars for inserting individual items
296 /* prev = 'live-' + src;
298 $('.wall-item-outside-wrapper',data).each(function() {
299 var ident = $(this).attr('id');
301 if($('#' + ident).length == 0 && prev != 'live-' + src) {
302 $('img',this).each(function() {
303 $(this).attr('src',$(this).attr('dst'));
305 $('#' + prev).after($(this));
308 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
309 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
310 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
311 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
312 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
313 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
314 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
315 $(this).attr('src',$(this).attr('dst'));
321 $('.like-rotator').hide();
324 $('body').css('cursor', 'auto');
326 /* autocomplete @nicknames */
327 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
331 function imgbright(node) {
332 $(node).removeClass("drophide").addClass("drop");
335 function imgdull(node) {
336 $(node).removeClass("drop").addClass("drophide");
339 // Since our ajax calls are asynchronous, we will give a few
340 // seconds for the first ajax call (setting like/dislike), then
341 // run the updater to pick up any changes and display on the page.
342 // The updater will turn any rotators off when it's done.
343 // This function will have returned long before any of these
344 // events have completed and therefore there won't be any
345 // visible feedback that anything changed without all this
346 // trickery. This still could cause confusion if the "like" ajax call
347 // is delayed and NavUpdate runs before it completes.
349 function dolike(ident,verb) {
351 $('#like-rotator-' + ident.toString()).show();
352 $.get('like/' + ident.toString() + '?verb=' + verb );
353 if(timer) clearTimeout(timer);
354 timer = setTimeout(NavUpdate,3000);
358 function dostar(ident) {
359 ident = ident.toString();
360 $('#like-rotator-' + ident).show();
361 $.get('starred/' + ident, function(data) {
362 if(data.match(/1/)) {
363 $('#starred-' + ident).addClass('starred');
364 $('#starred-' + ident).removeClass('unstarred');
365 $('#star-' + ident).addClass('hidden');
366 $('#unstar-' + ident).removeClass('hidden');
369 $('#starred-' + ident).addClass('unstarred');
370 $('#starred-' + ident).removeClass('starred');
371 $('#star-' + ident).removeClass('hidden');
372 $('#unstar-' + ident).addClass('hidden');
374 $('#like-rotator-' + ident).hide();
378 function getPosition(e) {
379 var cursor = {x:0, y:0};
380 if ( e.pageX || e.pageY ) {
385 if( e.clientX || e.clientY ) {
386 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
387 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
399 var lockvisible = false;
401 function lockview(event,id) {
402 event = event || window.event;
403 cursor = getPosition(event);
409 $.get('lockview/' + id, function(data) {
410 $('#panel').html(data);
411 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
417 function lockviewhide() {
422 function post_comment(id) {
425 $('body').css('cursor', 'wait');
426 $("#comment-preview-inp-" + id).val("0");
429 $("#comment-edit-form-" + id).serialize(),
432 $("#comment-edit-wrapper-" + id).hide();
433 $("#comment-edit-text-" + id).val('');
434 var tarea = document.getElementById("comment-edit-text-" + id);
436 commentClose(tarea,id);
437 if(timer) clearTimeout(timer);
438 timer = setTimeout(NavUpdate,10);
441 window.location.href=data.reload;
450 function preview_comment(id) {
451 $("#comment-preview-inp-" + id).val("1");
452 $("#comment-edit-preview-" + id).show();
455 $("#comment-edit-form-" + id).serialize(),
459 $("#comment-edit-preview-" + id).html(data.preview);
460 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
470 function preview_post() {
471 $("#jot-preview").val("1");
472 $("#jot-preview-content").show();
473 tinyMCE.triggerSave();
476 $("#profile-jot-form").serialize(),
479 $("#jot-preview-content").html(data.preview);
480 $("#jot-preview-content" + " a").click(function() { return false; });
485 $("#jot-preview").val("0");
491 // unpause auto reloads if they are currently stopped
494 $('#pause').html('');
499 // Converts the binary representation of data to hex
502 // discuss at: http://phpjs.org/functions/bin2hex
503 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
504 // + bugfixed by: Onno Marsman
505 // + bugfixed by: Linuxworld
506 // * example 1: bin2hex('Kev');
507 // * returns 1: '4b6576'
508 // * example 2: bin2hex(String.fromCharCode(0x00));
510 var v,i, f = 0, a = [];
514 for (i = 0; i<f; i++) {
515 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
521 function groupChangeMember(gid, cid, sec_token) {
522 $('body .fakelink').css('cursor', 'wait');
523 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
524 $('#group-update-wrapper').html(data);
525 $('body .fakelink').css('cursor', 'auto');
529 function profChangeMember(gid,cid) {
530 $('body .fakelink').css('cursor', 'wait');
531 $.get('profperm/' + gid + '/' + cid, function(data) {
532 $('#prof-update-wrapper').html(data);
533 $('body .fakelink').css('cursor', 'auto');
537 function contactgroupChangeMember(gid,cid) {
538 $('body').css('cursor', 'wait');
539 $.get('contactgroup/' + gid + '/' + cid, function(data) {
540 $('body').css('cursor', 'auto');
545 function checkboxhighlight(box) {
546 if($(box).is(':checked')) {
547 $(box).addClass('checkeditem');
550 $(box).removeClass('checkeditem');
554 function notifyMarkAll() {
555 $.get('notify/mark/all', function(data) {
556 if(timer) clearTimeout(timer);
557 timer = setTimeout(NavUpdate,1000);
562 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
563 function fcFileBrowser (field_name, url, type, win) {
564 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
565 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
566 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
569 var cmsURL = baseurl+"/fbrowser/"+type+"/";
571 tinyMCE.activeEditor.windowManager.open({
573 title : 'File Browser',
574 width : 420, // Your dimensions may differ - toy around with them!
577 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
578 close_previous : "no"
586 function setupFieldRichtext(){
589 mode : "specific_textareas",
590 editor_selector: "fieldRichtext",
591 plugins : "bbcode,paste, inlinepopups",
592 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
593 theme_advanced_buttons2 : "",
594 theme_advanced_buttons3 : "",
595 theme_advanced_toolbar_location : "top",
596 theme_advanced_toolbar_align : "center",
597 theme_advanced_blockformats : "blockquote,code",
598 paste_text_sticky : true,
599 entity_encoding : "raw",
600 add_unload_trigger : false,
601 remove_linebreaks : false,
602 force_p_newlines : false,
603 force_br_newlines : true,
604 forced_root_block : '',
606 content_css: baseurl+"/view/custom_tinymce.css",
607 theme_advanced_path : false,
608 file_browser_callback : "fcFileBrowser",
614 * sprintf in javascript
615 * "{0} and {1}".format('zero','uno');
617 String.prototype.format = function() {
618 var formatted = this;
619 for (var i = 0; i < arguments.length; i++) {
620 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
621 formatted = formatted.replace(regexp, arguments[i]);
626 Array.prototype.remove = function(item) {
627 to=undefined; from=this.indexOf(item);
628 var rest = this.slice((to || from) + 1 || this.length);
629 this.length = from < 0 ? this.length + from : from;
630 return this.push.apply(this, rest);
633 function previewTheme(elm) {
634 theme = $(elm).val();
635 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
636 $('#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>');