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);
125 var intro = $(data).find('intro').text();
126 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
127 $('#intro-update').html(intro);
129 var mail = $(data).find('mail').text();
130 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
131 $('#mail-update').html(mail);
133 var eNotif = $(data).find('notif')
134 notif = eNotif.attr('count');
136 $("#nav-notifications-linkmenu").addClass("on");
137 nnm = $("#nav-notifications-menu");
139 nnm.html(notifications_all + notifications_mark);
141 //nnm.attr('popup','true');
142 eNotif.children("note").each(function(){
144 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
145 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
150 // $("#nav-notifications-linkmenu").removeClass("on");
151 // $("#nav-notifications-menu").html(notifications_empty);
153 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
154 $('#notify-update').html(notif);
156 var eSysmsg = $(data).find('sysmsgs');
157 eSysmsg.children("notice").each(function(){
158 text = $(this).text();
159 $.jGrowl(text, { sticky: true, theme: 'notice' });
161 eSysmsg.children("info").each(function(){
162 text = $(this).text();
163 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
170 // Allow folks to stop the ajax page updates with the pause/break key
171 $(document).keydown(function(event) {
172 if(event.keyCode == '8') {
173 var target = event.target || event.srcElement;
174 if (!/input|textarea/i.test(target.nodeName)) {
178 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
179 event.preventDefault();
180 if(stopped == false) {
185 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
199 function NavUpdate() {
202 $.get("ping",function(data) {
203 $(data).find('result').each(function() {
204 // send nav-update event
205 $('nav').trigger('nav-update', this);
210 if($('#live-network').length) { src = 'network'; liveUpdate(); }
211 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
212 if($('#live-community').length) { src = 'community'; liveUpdate(); }
213 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
214 if($('#live-display').length) {
217 window.location.href=window.location.href
220 if($('#live-photos').length) {
223 window.location.href=window.location.href
233 timer = setTimeout(NavUpdate,updateInterval);
236 function liveUpdate() {
237 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
238 if(($('.comment-edit-text-full').length) || (in_progress)) {
240 clearTimeout(livetime);
242 livetime = setTimeout(liveUpdate, 10000);
248 prev = 'live-' + src;
251 var udargs = ((netargs.length) ? '/' + netargs : '');
252 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
254 $.get(update_url,function(data) {
256 // $('.collapsed-comments',data).each(function() {
257 // var ident = $(this).attr('id');
258 // var is_hidden = $('#' + ident).is(':hidden');
259 // if($('#' + ident).length) {
260 // $('#' + ident).replaceWith($(this));
262 // $('#' + ident).hide();
268 $('.tread-wrapper',data).each(function() {
269 var ident = $(this).attr('id');
271 if($('#' + ident).length == 0 && profile_page == 1) {
272 $('img',this).each(function() {
273 $(this).attr('src',$(this).attr('dst'));
275 $('#' + prev).after($(this));
278 $('img',this).each(function() {
279 $(this).attr('src',$(this).attr('dst'));
281 $('#' + ident).replaceWith($(this));
286 // reset vars for inserting individual items
288 /* prev = 'live-' + src;
290 $('.wall-item-outside-wrapper',data).each(function() {
291 var ident = $(this).attr('id');
293 if($('#' + ident).length == 0 && prev != 'live-' + src) {
294 $('img',this).each(function() {
295 $(this).attr('src',$(this).attr('dst'));
297 $('#' + prev).after($(this));
300 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
301 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
302 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
303 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
304 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
305 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
306 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
307 $(this).attr('src',$(this).attr('dst'));
313 $('.like-rotator').hide();
316 $('body').css('cursor', 'auto');
318 /* autocomplete @nicknames */
319 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
323 function imgbright(node) {
324 $(node).removeClass("drophide").addClass("drop");
327 function imgdull(node) {
328 $(node).removeClass("drop").addClass("drophide");
331 // Since our ajax calls are asynchronous, we will give a few
332 // seconds for the first ajax call (setting like/dislike), then
333 // run the updater to pick up any changes and display on the page.
334 // The updater will turn any rotators off when it's done.
335 // This function will have returned long before any of these
336 // events have completed and therefore there won't be any
337 // visible feedback that anything changed without all this
338 // trickery. This still could cause confusion if the "like" ajax call
339 // is delayed and NavUpdate runs before it completes.
341 function dolike(ident,verb) {
343 $('#like-rotator-' + ident.toString()).show();
344 $.get('like/' + ident.toString() + '?verb=' + verb );
345 if(timer) clearTimeout(timer);
346 timer = setTimeout(NavUpdate,3000);
350 function dostar(ident) {
351 ident = ident.toString();
352 $('#like-rotator-' + ident).show();
353 $.get('starred/' + ident, function(data) {
354 if(data.match(/1/)) {
355 $('#starred-' + ident).addClass('starred');
356 $('#starred-' + ident).removeClass('unstarred');
357 $('#star-' + ident).addClass('hidden');
358 $('#unstar-' + ident).removeClass('hidden');
361 $('#starred-' + ident).addClass('unstarred');
362 $('#starred-' + ident).removeClass('starred');
363 $('#star-' + ident).removeClass('hidden');
364 $('#unstar-' + ident).addClass('hidden');
366 $('#like-rotator-' + ident).hide();
370 function getPosition(e) {
371 var cursor = {x:0, y:0};
372 if ( e.pageX || e.pageY ) {
377 if( e.clientX || e.clientY ) {
378 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
379 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
391 var lockvisible = false;
393 function lockview(event,id) {
394 event = event || window.event;
395 cursor = getPosition(event);
401 $.get('lockview/' + id, function(data) {
402 $('#panel').html(data);
403 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
409 function lockviewhide() {
414 function post_comment(id) {
417 $('body').css('cursor', 'wait');
418 $("#comment-preview-inp-" + id).val("0");
421 $("#comment-edit-form-" + id).serialize(),
424 $("#comment-edit-wrapper-" + id).hide();
425 $("#comment-edit-text-" + id).val('');
426 var tarea = document.getElementById("comment-edit-text-" + id);
428 commentClose(tarea,id);
429 if(timer) clearTimeout(timer);
430 timer = setTimeout(NavUpdate,10);
433 window.location.href=data.reload;
442 function preview_comment(id) {
443 $("#comment-preview-inp-" + id).val("1");
444 $("#comment-edit-preview-" + id).show();
447 $("#comment-edit-form-" + id).serialize(),
451 $("#comment-edit-preview-" + id).html(data.preview);
452 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
462 function preview_post() {
463 $("#jot-preview").val("1");
464 $("#jot-preview-content").show();
465 tinyMCE.triggerSave();
468 $("#profile-jot-form").serialize(),
471 $("#jot-preview-content").html(data.preview);
472 $("#jot-preview-content" + " a").click(function() { return false; });
477 $("#jot-preview").val("0");
483 // unpause auto reloads if they are currently stopped
486 $('#pause').html('');
491 // Converts the binary representation of data to hex
494 // discuss at: http://phpjs.org/functions/bin2hex
495 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
496 // + bugfixed by: Onno Marsman
497 // + bugfixed by: Linuxworld
498 // * example 1: bin2hex('Kev');
499 // * returns 1: '4b6576'
500 // * example 2: bin2hex(String.fromCharCode(0x00));
502 var v,i, f = 0, a = [];
506 for (i = 0; i<f; i++) {
507 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
513 function groupChangeMember(gid, cid, sec_token) {
514 $('body .fakelink').css('cursor', 'wait');
515 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
516 $('#group-update-wrapper').html(data);
517 $('body .fakelink').css('cursor', 'auto');
521 function profChangeMember(gid,cid) {
522 $('body .fakelink').css('cursor', 'wait');
523 $.get('profperm/' + gid + '/' + cid, function(data) {
524 $('#prof-update-wrapper').html(data);
525 $('body .fakelink').css('cursor', 'auto');
529 function contactgroupChangeMember(gid,cid) {
530 $('body').css('cursor', 'wait');
531 $.get('contactgroup/' + gid + '/' + cid, function(data) {
532 $('body').css('cursor', 'auto');
537 function checkboxhighlight(box) {
538 if($(box).is(':checked')) {
539 $(box).addClass('checkeditem');
542 $(box).removeClass('checkeditem');
546 function notifyMarkAll() {
547 $.get('notify/mark/all', function(data) {
548 if(timer) clearTimeout(timer);
549 timer = setTimeout(NavUpdate,1000);
554 function setupFieldRichtext(){
557 mode : "specific_textareas",
558 editor_selector: "fieldRichtext",
559 plugins : "bbcode,paste",
560 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
561 theme_advanced_buttons2 : "",
562 theme_advanced_buttons3 : "",
563 theme_advanced_toolbar_location : "top",
564 theme_advanced_toolbar_align : "center",
565 theme_advanced_blockformats : "blockquote,code",
566 paste_text_sticky : true,
567 entity_encoding : "raw",
568 add_unload_trigger : false,
569 remove_linebreaks : false,
570 force_p_newlines : false,
571 force_br_newlines : true,
572 forced_root_block : '',
574 content_css: baseurl+"/view/custom_tinymce.css",
575 theme_advanced_path : false,
581 * sprintf in javascript
582 * "{0} and {1}".format('zero','uno');
584 String.prototype.format = function() {
585 var formatted = this;
586 for (var i = 0; i < arguments.length; i++) {
587 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
588 formatted = formatted.replace(regexp, arguments[i]);
593 Array.prototype.remove = function(item) {
594 to=undefined; from=this.indexOf(item);
595 var rest = this.slice((to || from) + 1 || this.length);
596 this.length = from < 0 ? this.length + from : from;
597 return this.push.apply(this, rest);
600 function previewTheme(elm) {
601 theme = $(elm).val();
602 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
603 $('#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>');