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"
24 var totStopped = false;
28 var in_progress = false;
29 var langSelect = false;
30 var commentBusy = false;
31 var last_popup_menu = null;
32 var last_popup_button = null;
35 $.ajaxSetup({cache: false});
37 msie = $.browser.msie ;
39 /* setup tooltips *//*
40 $("a,.tt").each(function(){
43 if (e.hasClass("tttop")) pos="top";
44 if (e.hasClass("ttbottom")) pos="bottom";
45 if (e.hasClass("ttleft")) pos="left";
46 if (e.hasClass("ttright")) pos="right";
47 e.tipTip({defaultPosition: pos, edgeOffset: 8});
52 /* setup onoff widgets */
53 $(".onoff input").each(function(){
55 id = $(this).attr("id");
56 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
59 $(".onoff > a").click(function(event){
60 event.preventDefault();
61 var input = $(this).siblings("input");
62 var val = 1-input.val();
63 var id = input.attr("id");
64 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
65 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
70 /* setup field_richtext */
74 $('a[rel^=#]').click(function(e){
75 menu = $( $(this).attr('rel') );
78 if (menu.attr('popup')=="false") return false;
79 $(this).parent().toggleClass("selected");
81 if (menu.css("display") == "none") {
82 last_popup_menu = null;
83 last_popup_button = null;
85 last_popup_menu = menu;
86 last_popup_button = $(this).parent();
90 $('html').click(function() {
91 last_popup_menu.hide();
92 last_popup_button.removeClass("selected");
93 last_popup_menu = null;
94 last_popup_button = null;
98 $("a.popupbox").fancybox({
99 'transitionIn' : 'elastic',
100 'transitionOut' : 'elastic'
104 /* notifications template */
105 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
106 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
107 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
108 var notifications_empty = unescape($("#nav-notifications-menu").html());
110 /* nav update event */
111 $('nav').bind('nav-update', function(e,data){;
112 var net = $(data).find('net').text();
113 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
114 $('#net-update').html(net);
116 var home = $(data).find('home').text();
117 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
118 $('#home-update').html(home);
122 var intro = $(data).find('intro').text();
123 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
124 $('#intro-update').html(intro);
126 var mail = $(data).find('mail').text();
127 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
128 $('#mail-update').html(mail);
130 var eNotif = $(data).find('notif')
131 notif = eNotif.attr('count');
133 $("#nav-notifications-linkmenu").addClass("on");
134 nnm = $("#nav-notifications-menu");
136 nnm.html(notifications_all + notifications_mark);
138 //nnm.attr('popup','true');
139 eNotif.children("note").each(function(){
141 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
142 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
147 // $("#nav-notifications-linkmenu").removeClass("on");
148 // $("#nav-notifications-menu").html(notifications_empty);
150 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
151 $('#notify-update').html(notif);
153 var eSysmsg = $(data).find('sysmsgs');
154 eSysmsg.children("notice").each(function(){
155 text = $(this).text();
156 $.jGrowl(text, { sticky: true, theme: 'notice' });
158 eSysmsg.children("info").each(function(){
159 text = $(this).text();
160 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
167 // Allow folks to stop the ajax page updates with the pause/break key
168 $(document).keydown(function(event) {
169 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
170 event.preventDefault();
171 if(stopped == false) {
176 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
190 function NavUpdate() {
193 $.get("ping",function(data) {
194 $(data).find('result').each(function() {
195 // send nav-update event
196 $('nav').trigger('nav-update', this);
201 if($('#live-network').length) { src = 'network'; liveUpdate(); }
202 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
203 if($('#live-community').length) { src = 'community'; liveUpdate(); }
204 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
205 if($('#live-display').length) {
208 window.location.href=window.location.href
211 if($('#live-photos').length) {
214 window.location.href=window.location.href
224 timer = setTimeout(NavUpdate,updateInterval);
227 function liveUpdate() {
228 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
229 if(($('.comment-edit-text-full').length) || (in_progress)) {
231 clearTimeout(livetime);
233 livetime = setTimeout(liveUpdate, 10000);
239 prev = 'live-' + src;
242 var udargs = ((netargs.length) ? '/' + netargs : '');
243 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
245 $.get(update_url,function(data) {
247 // $('.collapsed-comments',data).each(function() {
248 // var ident = $(this).attr('id');
249 // var is_hidden = $('#' + ident).is(':hidden');
250 // if($('#' + ident).length) {
251 // $('#' + ident).replaceWith($(this));
253 // $('#' + ident).hide();
259 $('.tread-wrapper',data).each(function() {
260 var ident = $(this).attr('id');
262 if($('#' + ident).length == 0 && profile_page == 1) {
263 $('img',this).each(function() {
264 $(this).attr('src',$(this).attr('dst'));
266 $('#' + prev).after($(this));
269 $('img',this).each(function() {
270 $(this).attr('src',$(this).attr('dst'));
272 $('#' + ident).replaceWith($(this));
277 // reset vars for inserting individual items
279 /* prev = 'live-' + src;
281 $('.wall-item-outside-wrapper',data).each(function() {
282 var ident = $(this).attr('id');
284 if($('#' + ident).length == 0 && prev != 'live-' + src) {
285 $('img',this).each(function() {
286 $(this).attr('src',$(this).attr('dst'));
288 $('#' + prev).after($(this));
291 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
292 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
293 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
294 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
295 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
296 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
297 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
298 $(this).attr('src',$(this).attr('dst'));
304 $('.like-rotator').hide();
307 $('body').css('cursor', 'auto');
309 /* autocomplete @nicknames */
310 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
314 function imgbright(node) {
315 $(node).removeClass("drophide").addClass("drop");
318 function imgdull(node) {
319 $(node).removeClass("drop").addClass("drophide");
322 // Since our ajax calls are asynchronous, we will give a few
323 // seconds for the first ajax call (setting like/dislike), then
324 // run the updater to pick up any changes and display on the page.
325 // The updater will turn any rotators off when it's done.
326 // This function will have returned long before any of these
327 // events have completed and therefore there won't be any
328 // visible feedback that anything changed without all this
329 // trickery. This still could cause confusion if the "like" ajax call
330 // is delayed and NavUpdate runs before it completes.
332 function dolike(ident,verb) {
334 $('#like-rotator-' + ident.toString()).show();
335 $.get('like/' + ident.toString() + '?verb=' + verb );
336 if(timer) clearTimeout(timer);
337 timer = setTimeout(NavUpdate,3000);
341 function dostar(ident) {
342 ident = ident.toString();
343 $('#like-rotator-' + ident).show();
344 $.get('starred/' + ident, function(data) {
345 if(data.match(/1/)) {
346 $('#starred-' + ident).addClass('starred');
347 $('#starred-' + ident).removeClass('unstarred');
348 $('#star-' + ident).addClass('hidden');
349 $('#unstar-' + ident).removeClass('hidden');
352 $('#starred-' + ident).addClass('unstarred');
353 $('#starred-' + ident).removeClass('starred');
354 $('#star-' + ident).removeClass('hidden');
355 $('#unstar-' + ident).addClass('hidden');
357 $('#like-rotator-' + ident).hide();
361 function getPosition(e) {
362 var cursor = {x:0, y:0};
363 if ( e.pageX || e.pageY ) {
368 if( e.clientX || e.clientY ) {
369 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
370 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
382 var lockvisible = false;
384 function lockview(event,id) {
385 event = event || window.event;
386 cursor = getPosition(event);
392 $.get('lockview/' + id, function(data) {
393 $('#panel').html(data);
394 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
400 function lockviewhide() {
405 function post_comment(id) {
408 $('body').css('cursor', 'wait');
409 $("#comment-preview-inp-" + id).val("0");
412 $("#comment-edit-form-" + id).serialize(),
415 $("#comment-edit-wrapper-" + id).hide();
416 $("#comment-edit-text-" + id).val('');
417 var tarea = document.getElementById("comment-edit-text-" + id);
419 commentClose(tarea,id);
420 if(timer) clearTimeout(timer);
421 timer = setTimeout(NavUpdate,10);
424 window.location.href=data.reload;
433 function preview_comment(id) {
434 $("#comment-preview-inp-" + id).val("1");
435 $("#comment-edit-preview-" + id).show();
438 $("#comment-edit-form-" + id).serialize(),
442 $("#comment-edit-preview-" + id).html(data.preview);
443 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
453 function preview_post() {
454 $("#jot-preview").val("1");
455 $("#jot-preview-content").show();
456 tinyMCE.triggerSave();
459 $("#profile-jot-form").serialize(),
462 $("#jot-preview-content").html(data.preview);
463 $("#jot-preview-content" + " a").click(function() { return false; });
468 $("#jot-preview").val("0");
474 // unpause auto reloads if they are currently stopped
477 $('#pause').html('');
482 // Converts the binary representation of data to hex
485 // discuss at: http://phpjs.org/functions/bin2hex
486 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
487 // + bugfixed by: Onno Marsman
488 // + bugfixed by: Linuxworld
489 // * example 1: bin2hex('Kev');
490 // * returns 1: '4b6576'
491 // * example 2: bin2hex(String.fromCharCode(0x00));
493 var v,i, f = 0, a = [];
497 for (i = 0; i<f; i++) {
498 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
504 function groupChangeMember(gid, cid, sec_token) {
505 $('body .fakelink').css('cursor', 'wait');
506 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
507 $('#group-update-wrapper').html(data);
508 $('body .fakelink').css('cursor', 'auto');
512 function profChangeMember(gid,cid) {
513 $('body .fakelink').css('cursor', 'wait');
514 $.get('profperm/' + gid + '/' + cid, function(data) {
515 $('#prof-update-wrapper').html(data);
516 $('body .fakelink').css('cursor', 'auto');
520 function contactgroupChangeMember(gid,cid) {
521 $('body').css('cursor', 'wait');
522 $.get('contactgroup/' + gid + '/' + cid, function(data) {
523 $('body').css('cursor', 'auto');
528 function checkboxhighlight(box) {
529 if($(box).is(':checked')) {
530 $(box).addClass('checkeditem');
533 $(box).removeClass('checkeditem');
537 function notifyMarkAll() {
538 $.get('notify/mark/all', function(data) {
539 if(timer) clearTimeout(timer);
540 timer = setTimeout(NavUpdate,1000);
545 function setupFieldRichtext(){
548 mode : "specific_textareas",
549 editor_selector: "fieldRichtext",
550 plugins : "bbcode,paste",
551 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
552 theme_advanced_buttons2 : "",
553 theme_advanced_buttons3 : "",
554 theme_advanced_toolbar_location : "top",
555 theme_advanced_toolbar_align : "center",
556 theme_advanced_blockformats : "blockquote,code",
557 paste_text_sticky : true,
558 entity_encoding : "raw",
559 add_unload_trigger : false,
560 remove_linebreaks : false,
561 force_p_newlines : false,
562 force_br_newlines : true,
563 forced_root_block : '',
565 content_css: baseurl+"/view/custom_tinymce.css",
566 theme_advanced_path : false,
572 * sprintf in javascript
573 * "{0} and {1}".format('zero','uno');
575 String.prototype.format = function() {
576 var formatted = this;
577 for (var i = 0; i < arguments.length; i++) {
578 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
579 formatted = formatted.replace(regexp, arguments[i]);
584 Array.prototype.remove = function(item) {
585 to=undefined; from=this.indexOf(item);
586 var rest = this.slice((to || from) + 1 || this.length);
587 this.length = from < 0 ? this.length + from : from;
588 return this.push.apply(this, rest);
591 function previewTheme(elm) {
592 theme = $(elm).val();
593 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
594 $('#theme-preview').html('<a href="' + data.img + '"><img src="' + data.img + '" width="320" height="240" alt="' + theme + '" /></a>');