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')
141 if (eNotif.children("note").length==0){
142 $("#nav-notifications-menu").html(notifications_empty);
144 nnm = $("#nav-notifications-menu");
145 nnm.html(notifications_all + notifications_mark);
146 //nnm.attr('popup','true');
147 eNotif.children("note").each(function(){
149 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
150 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
154 notif = eNotif.attr('count');
156 $("#nav-notifications-linkmenu").addClass("on");
158 $("#nav-notifications-linkmenu").removeClass("on");
160 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
161 $('#notify-update').html(notif);
163 var eSysmsg = $(data).find('sysmsgs');
164 eSysmsg.children("notice").each(function(){
165 text = $(this).text();
166 $.jGrowl(text, { sticky: true, theme: 'notice' });
168 eSysmsg.children("info").each(function(){
169 text = $(this).text();
170 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
177 // Allow folks to stop the ajax page updates with the pause/break key
178 $(document).keydown(function(event) {
179 if(event.keyCode == '8') {
180 var target = event.target || event.srcElement;
181 if (!/input|textarea/i.test(target.nodeName)) {
185 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
186 event.preventDefault();
187 if(stopped == false) {
192 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
206 function NavUpdate() {
209 $.get("ping",function(data) {
210 $(data).find('result').each(function() {
211 // send nav-update event
212 $('nav').trigger('nav-update', this);
217 if($('#live-network').length) { src = 'network'; liveUpdate(); }
218 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
219 if($('#live-community').length) { src = 'community'; liveUpdate(); }
220 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
221 if($('#live-display').length) {
224 window.location.href=window.location.href
227 if($('#live-photos').length) {
230 window.location.href=window.location.href
240 timer = setTimeout(NavUpdate,updateInterval);
243 function liveUpdate() {
244 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
245 if(($('.comment-edit-text-full').length) || (in_progress)) {
247 clearTimeout(livetime);
249 livetime = setTimeout(liveUpdate, 10000);
255 prev = 'live-' + src;
258 var udargs = ((netargs.length) ? '/' + netargs : '');
259 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
261 $.get(update_url,function(data) {
263 // $('.collapsed-comments',data).each(function() {
264 // var ident = $(this).attr('id');
265 // var is_hidden = $('#' + ident).is(':hidden');
266 // if($('#' + ident).length) {
267 // $('#' + ident).replaceWith($(this));
269 // $('#' + ident).hide();
275 $('.tread-wrapper',data).each(function() {
276 var ident = $(this).attr('id');
278 if($('#' + ident).length == 0 && profile_page == 1) {
279 $('img',this).each(function() {
280 $(this).attr('src',$(this).attr('dst'));
282 $('#' + prev).after($(this));
285 $('img',this).each(function() {
286 $(this).attr('src',$(this).attr('dst'));
288 $('#' + ident).replaceWith($(this));
293 // reset vars for inserting individual items
295 /* prev = 'live-' + src;
297 $('.wall-item-outside-wrapper',data).each(function() {
298 var ident = $(this).attr('id');
300 if($('#' + ident).length == 0 && prev != 'live-' + src) {
301 $('img',this).each(function() {
302 $(this).attr('src',$(this).attr('dst'));
304 $('#' + prev).after($(this));
307 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
308 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
309 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
310 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
311 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
312 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
313 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
314 $(this).attr('src',$(this).attr('dst'));
320 $('.like-rotator').hide();
323 $('body').css('cursor', 'auto');
325 /* autocomplete @nicknames */
326 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
330 function imgbright(node) {
331 $(node).removeClass("drophide").addClass("drop");
334 function imgdull(node) {
335 $(node).removeClass("drop").addClass("drophide");
338 // Since our ajax calls are asynchronous, we will give a few
339 // seconds for the first ajax call (setting like/dislike), then
340 // run the updater to pick up any changes and display on the page.
341 // The updater will turn any rotators off when it's done.
342 // This function will have returned long before any of these
343 // events have completed and therefore there won't be any
344 // visible feedback that anything changed without all this
345 // trickery. This still could cause confusion if the "like" ajax call
346 // is delayed and NavUpdate runs before it completes.
348 function dolike(ident,verb) {
350 $('#like-rotator-' + ident.toString()).show();
351 $.get('like/' + ident.toString() + '?verb=' + verb );
352 if(timer) clearTimeout(timer);
353 timer = setTimeout(NavUpdate,3000);
357 function dostar(ident) {
358 ident = ident.toString();
359 $('#like-rotator-' + ident).show();
360 $.get('starred/' + ident, function(data) {
361 if(data.match(/1/)) {
362 $('#starred-' + ident).addClass('starred');
363 $('#starred-' + ident).removeClass('unstarred');
364 $('#star-' + ident).addClass('hidden');
365 $('#unstar-' + ident).removeClass('hidden');
368 $('#starred-' + ident).addClass('unstarred');
369 $('#starred-' + ident).removeClass('starred');
370 $('#star-' + ident).removeClass('hidden');
371 $('#unstar-' + ident).addClass('hidden');
373 $('#like-rotator-' + ident).hide();
377 function getPosition(e) {
378 var cursor = {x:0, y:0};
379 if ( e.pageX || e.pageY ) {
384 if( e.clientX || e.clientY ) {
385 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
386 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
398 var lockvisible = false;
400 function lockview(event,id) {
401 event = event || window.event;
402 cursor = getPosition(event);
408 $.get('lockview/' + id, function(data) {
409 $('#panel').html(data);
410 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
416 function lockviewhide() {
421 function post_comment(id) {
424 $('body').css('cursor', 'wait');
425 $("#comment-preview-inp-" + id).val("0");
428 $("#comment-edit-form-" + id).serialize(),
431 $("#comment-edit-wrapper-" + id).hide();
432 $("#comment-edit-text-" + id).val('');
433 var tarea = document.getElementById("comment-edit-text-" + id);
435 commentClose(tarea,id);
436 if(timer) clearTimeout(timer);
437 timer = setTimeout(NavUpdate,10);
440 window.location.href=data.reload;
449 function preview_comment(id) {
450 $("#comment-preview-inp-" + id).val("1");
451 $("#comment-edit-preview-" + id).show();
454 $("#comment-edit-form-" + id).serialize(),
458 $("#comment-edit-preview-" + id).html(data.preview);
459 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
469 function preview_post() {
470 $("#jot-preview").val("1");
471 $("#jot-preview-content").show();
472 tinyMCE.triggerSave();
475 $("#profile-jot-form").serialize(),
478 $("#jot-preview-content").html(data.preview);
479 $("#jot-preview-content" + " a").click(function() { return false; });
484 $("#jot-preview").val("0");
490 // unpause auto reloads if they are currently stopped
493 $('#pause').html('');
498 // Converts the binary representation of data to hex
501 // discuss at: http://phpjs.org/functions/bin2hex
502 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
503 // + bugfixed by: Onno Marsman
504 // + bugfixed by: Linuxworld
505 // * example 1: bin2hex('Kev');
506 // * returns 1: '4b6576'
507 // * example 2: bin2hex(String.fromCharCode(0x00));
509 var v,i, f = 0, a = [];
513 for (i = 0; i<f; i++) {
514 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
520 function groupChangeMember(gid, cid, sec_token) {
521 $('body .fakelink').css('cursor', 'wait');
522 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
523 $('#group-update-wrapper').html(data);
524 $('body .fakelink').css('cursor', 'auto');
528 function profChangeMember(gid,cid) {
529 $('body .fakelink').css('cursor', 'wait');
530 $.get('profperm/' + gid + '/' + cid, function(data) {
531 $('#prof-update-wrapper').html(data);
532 $('body .fakelink').css('cursor', 'auto');
536 function contactgroupChangeMember(gid,cid) {
537 $('body').css('cursor', 'wait');
538 $.get('contactgroup/' + gid + '/' + cid, function(data) {
539 $('body').css('cursor', 'auto');
544 function checkboxhighlight(box) {
545 if($(box).is(':checked')) {
546 $(box).addClass('checkeditem');
549 $(box).removeClass('checkeditem');
553 function notifyMarkAll() {
554 $.get('notify/mark/all', function(data) {
555 if(timer) clearTimeout(timer);
556 timer = setTimeout(NavUpdate,1000);
561 function setupFieldRichtext(){
564 mode : "specific_textareas",
565 editor_selector: "fieldRichtext",
566 plugins : "bbcode,paste",
567 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
568 theme_advanced_buttons2 : "",
569 theme_advanced_buttons3 : "",
570 theme_advanced_toolbar_location : "top",
571 theme_advanced_toolbar_align : "center",
572 theme_advanced_blockformats : "blockquote,code",
573 paste_text_sticky : true,
574 entity_encoding : "raw",
575 add_unload_trigger : false,
576 remove_linebreaks : false,
577 force_p_newlines : false,
578 force_br_newlines : true,
579 forced_root_block : '',
581 content_css: baseurl+"/view/custom_tinymce.css",
582 theme_advanced_path : false,
588 * sprintf in javascript
589 * "{0} and {1}".format('zero','uno');
591 String.prototype.format = function() {
592 var formatted = this;
593 for (var i = 0; i < arguments.length; i++) {
594 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
595 formatted = formatted.replace(regexp, arguments[i]);
600 Array.prototype.remove = function(item) {
601 to=undefined; from=this.indexOf(item);
602 var rest = this.slice((to || from) + 1 || this.length);
603 this.length = from < 0 ? this.length + from : from;
604 return this.push.apply(this, rest);
607 function previewTheme(elm) {
608 theme = $(elm).val();
609 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
610 $('#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>');