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"
25 var totStopped = false;
29 var in_progress = false;
30 var langSelect = false;
31 var commentBusy = false;
32 var last_popup_menu = null;
33 var last_popup_button = null;
36 $.ajaxSetup({cache: false});
38 msie = $.browser.msie ;
40 /* setup tooltips *//*
41 $("a,.tt").each(function(){
44 if (e.hasClass("tttop")) pos="top";
45 if (e.hasClass("ttbottom")) pos="bottom";
46 if (e.hasClass("ttleft")) pos="left";
47 if (e.hasClass("ttright")) pos="right";
48 e.tipTip({defaultPosition: pos, edgeOffset: 8});
53 /* setup onoff widgets */
54 $(".onoff input").each(function(){
56 id = $(this).attr("id");
57 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
60 $(".onoff > a").click(function(event){
61 event.preventDefault();
62 var input = $(this).siblings("input");
63 var val = 1-input.val();
64 var id = input.attr("id");
65 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
66 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
71 /* setup field_richtext */
75 $('a[rel^=#]').click(function(e){
76 menu = $( $(this).attr('rel') );
79 if (menu.attr('popup')=="false") return false;
80 $(this).parent().toggleClass("selected");
82 if (menu.css("display") == "none") {
83 last_popup_menu = null;
84 last_popup_button = null;
86 last_popup_menu = menu;
87 last_popup_button = $(this).parent();
91 $('html').click(function() {
93 last_popup_menu.hide();
94 last_popup_button.removeClass("selected");
95 last_popup_menu = null;
96 last_popup_button = null;
101 $("a.popupbox").fancybox({
102 'transitionIn' : 'elastic',
103 'transitionOut' : 'elastic'
107 /* notifications template */
108 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
109 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
110 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
111 var notifications_empty = unescape($("#nav-notifications-menu").html());
113 /* nav update event */
114 $('nav').bind('nav-update', function(e,data){;
115 var net = $(data).find('net').text();
116 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
117 $('#net-update').html(net);
119 var home = $(data).find('home').text();
120 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
121 $('#home-update').html(home);
123 var intro = $(data).find('intro').text();
124 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
125 $('#intro-update').html(intro);
127 var mail = $(data).find('mail').text();
128 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
129 $('#mail-update').html(mail);
131 var intro = $(data).find('intro').text();
132 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
133 $('#intro-update-li').html(intro);
135 var mail = $(data).find('mail').text();
136 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
137 $('#mail-update-li').html(mail);
139 var eNotif = $(data).find('notif')
140 notif = eNotif.attr('count');
142 $("#nav-notifications-linkmenu").addClass("on");
143 nnm = $("#nav-notifications-menu");
145 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'));
156 // $("#nav-notifications-linkmenu").removeClass("on");
157 // $("#nav-notifications-menu").html(notifications_empty);
159 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
160 $('#notify-update').html(notif);
162 var eSysmsg = $(data).find('sysmsgs');
163 eSysmsg.children("notice").each(function(){
164 text = $(this).text();
165 $.jGrowl(text, { sticky: true, theme: 'notice' });
167 eSysmsg.children("info").each(function(){
168 text = $(this).text();
169 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
176 // Allow folks to stop the ajax page updates with the pause/break key
177 $(document).keydown(function(event) {
178 if(event.keyCode == '8') {
179 var target = event.target || event.srcElement;
180 if (!/input|textarea/i.test(target.nodeName)) {
184 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
185 event.preventDefault();
186 if(stopped == false) {
191 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
205 function NavUpdate() {
208 $.get("ping",function(data) {
209 $(data).find('result').each(function() {
210 // send nav-update event
211 $('nav').trigger('nav-update', this);
216 if($('#live-network').length) { src = 'network'; liveUpdate(); }
217 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
218 if($('#live-community').length) { src = 'community'; liveUpdate(); }
219 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
220 if($('#live-display').length) {
223 window.location.href=window.location.href
226 if($('#live-photos').length) {
229 window.location.href=window.location.href
239 timer = setTimeout(NavUpdate,updateInterval);
242 function liveUpdate() {
243 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
244 if(($('.comment-edit-text-full').length) || (in_progress)) {
246 clearTimeout(livetime);
248 livetime = setTimeout(liveUpdate, 10000);
254 prev = 'live-' + src;
257 var udargs = ((netargs.length) ? '/' + netargs : '');
258 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
260 $.get(update_url,function(data) {
262 // $('.collapsed-comments',data).each(function() {
263 // var ident = $(this).attr('id');
264 // var is_hidden = $('#' + ident).is(':hidden');
265 // if($('#' + ident).length) {
266 // $('#' + ident).replaceWith($(this));
268 // $('#' + ident).hide();
274 $('.tread-wrapper',data).each(function() {
275 var ident = $(this).attr('id');
277 if($('#' + ident).length == 0 && profile_page == 1) {
278 $('img',this).each(function() {
279 $(this).attr('src',$(this).attr('dst'));
281 $('#' + prev).after($(this));
284 $('img',this).each(function() {
285 $(this).attr('src',$(this).attr('dst'));
287 $('#' + ident).replaceWith($(this));
292 // reset vars for inserting individual items
294 /* prev = 'live-' + src;
296 $('.wall-item-outside-wrapper',data).each(function() {
297 var ident = $(this).attr('id');
299 if($('#' + ident).length == 0 && prev != 'live-' + src) {
300 $('img',this).each(function() {
301 $(this).attr('src',$(this).attr('dst'));
303 $('#' + prev).after($(this));
306 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
307 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
308 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
309 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
310 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
311 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
312 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
313 $(this).attr('src',$(this).attr('dst'));
319 $('.like-rotator').hide();
322 $('body').css('cursor', 'auto');
324 /* autocomplete @nicknames */
325 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
329 function imgbright(node) {
330 $(node).removeClass("drophide").addClass("drop");
333 function imgdull(node) {
334 $(node).removeClass("drop").addClass("drophide");
337 // Since our ajax calls are asynchronous, we will give a few
338 // seconds for the first ajax call (setting like/dislike), then
339 // run the updater to pick up any changes and display on the page.
340 // The updater will turn any rotators off when it's done.
341 // This function will have returned long before any of these
342 // events have completed and therefore there won't be any
343 // visible feedback that anything changed without all this
344 // trickery. This still could cause confusion if the "like" ajax call
345 // is delayed and NavUpdate runs before it completes.
347 function dolike(ident,verb) {
349 $('#like-rotator-' + ident.toString()).show();
350 $.get('like/' + ident.toString() + '?verb=' + verb );
351 if(timer) clearTimeout(timer);
352 timer = setTimeout(NavUpdate,3000);
356 function dostar(ident) {
357 ident = ident.toString();
358 $('#like-rotator-' + ident).show();
359 $.get('starred/' + ident, function(data) {
360 if(data.match(/1/)) {
361 $('#starred-' + ident).addClass('starred');
362 $('#starred-' + ident).removeClass('unstarred');
363 $('#star-' + ident).addClass('hidden');
364 $('#unstar-' + ident).removeClass('hidden');
367 $('#starred-' + ident).addClass('unstarred');
368 $('#starred-' + ident).removeClass('starred');
369 $('#star-' + ident).removeClass('hidden');
370 $('#unstar-' + ident).addClass('hidden');
372 $('#like-rotator-' + ident).hide();
376 function getPosition(e) {
377 var cursor = {x:0, y:0};
378 if ( e.pageX || e.pageY ) {
383 if( e.clientX || e.clientY ) {
384 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
385 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
397 var lockvisible = false;
399 function lockview(event,id) {
400 event = event || window.event;
401 cursor = getPosition(event);
407 $.get('lockview/' + id, function(data) {
408 $('#panel').html(data);
409 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
415 function lockviewhide() {
420 function post_comment(id) {
423 $('body').css('cursor', 'wait');
424 $("#comment-preview-inp-" + id).val("0");
427 $("#comment-edit-form-" + id).serialize(),
430 $("#comment-edit-wrapper-" + id).hide();
431 $("#comment-edit-text-" + id).val('');
432 var tarea = document.getElementById("comment-edit-text-" + id);
434 commentClose(tarea,id);
435 if(timer) clearTimeout(timer);
436 timer = setTimeout(NavUpdate,10);
439 window.location.href=data.reload;
448 function preview_comment(id) {
449 $("#comment-preview-inp-" + id).val("1");
450 $("#comment-edit-preview-" + id).show();
453 $("#comment-edit-form-" + id).serialize(),
457 $("#comment-edit-preview-" + id).html(data.preview);
458 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
468 function preview_post() {
469 $("#jot-preview").val("1");
470 $("#jot-preview-content").show();
471 tinyMCE.triggerSave();
474 $("#profile-jot-form").serialize(),
477 $("#jot-preview-content").html(data.preview);
478 $("#jot-preview-content" + " a").click(function() { return false; });
483 $("#jot-preview").val("0");
489 // unpause auto reloads if they are currently stopped
492 $('#pause').html('');
497 // Converts the binary representation of data to hex
500 // discuss at: http://phpjs.org/functions/bin2hex
501 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
502 // + bugfixed by: Onno Marsman
503 // + bugfixed by: Linuxworld
504 // * example 1: bin2hex('Kev');
505 // * returns 1: '4b6576'
506 // * example 2: bin2hex(String.fromCharCode(0x00));
508 var v,i, f = 0, a = [];
512 for (i = 0; i<f; i++) {
513 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
519 function groupChangeMember(gid, cid, sec_token) {
520 $('body .fakelink').css('cursor', 'wait');
521 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
522 $('#group-update-wrapper').html(data);
523 $('body .fakelink').css('cursor', 'auto');
527 function profChangeMember(gid,cid) {
528 $('body .fakelink').css('cursor', 'wait');
529 $.get('profperm/' + gid + '/' + cid, function(data) {
530 $('#prof-update-wrapper').html(data);
531 $('body .fakelink').css('cursor', 'auto');
535 function contactgroupChangeMember(gid,cid) {
536 $('body').css('cursor', 'wait');
537 $.get('contactgroup/' + gid + '/' + cid, function(data) {
538 $('body').css('cursor', 'auto');
543 function checkboxhighlight(box) {
544 if($(box).is(':checked')) {
545 $(box).addClass('checkeditem');
548 $(box).removeClass('checkeditem');
552 function notifyMarkAll() {
553 $.get('notify/mark/all', function(data) {
554 if(timer) clearTimeout(timer);
555 timer = setTimeout(NavUpdate,1000);
560 function setupFieldRichtext(){
563 mode : "specific_textareas",
564 editor_selector: "fieldRichtext",
565 plugins : "bbcode,paste",
566 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
567 theme_advanced_buttons2 : "",
568 theme_advanced_buttons3 : "",
569 theme_advanced_toolbar_location : "top",
570 theme_advanced_toolbar_align : "center",
571 theme_advanced_blockformats : "blockquote,code",
572 paste_text_sticky : true,
573 entity_encoding : "raw",
574 add_unload_trigger : false,
575 remove_linebreaks : false,
576 force_p_newlines : false,
577 force_br_newlines : true,
578 forced_root_block : '',
580 content_css: baseurl+"/view/custom_tinymce.css",
581 theme_advanced_path : false,
587 * sprintf in javascript
588 * "{0} and {1}".format('zero','uno');
590 String.prototype.format = function() {
591 var formatted = this;
592 for (var i = 0; i < arguments.length; i++) {
593 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
594 formatted = formatted.replace(regexp, arguments[i]);
599 Array.prototype.remove = function(item) {
600 to=undefined; from=this.indexOf(item);
601 var rest = this.slice((to || from) + 1 || this.length);
602 this.length = from < 0 ? this.length + from : from;
603 return this.push.apply(this, rest);
606 function previewTheme(elm) {
607 theme = $(elm).val();
608 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
609 $('#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>');