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"
28 var in_progress = false;
29 var langSelect = false;
30 var commentBusy = false;
33 $.ajaxSetup({cache: false});
35 msie = $.browser.msie ;
38 $("a,.tt").each(function(){
41 if (e.hasClass("tttop")) pos="top";
42 if (e.hasClass("ttbottom")) pos="bottom";
43 if (e.hasClass("ttleft")) pos="left";
44 if (e.hasClass("ttright")) pos="right";
45 e.tipTip({defaultPosition: pos, edgeOffset: 8});
50 /* setup onoff widgets */
51 $(".onoff input").each(function(){
53 id = $(this).attr("id");
54 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
57 $(".onoff > a").click(function(event){
58 event.preventDefault();
59 var input = $(this).siblings("input");
60 var val = 1-input.val();
61 var id = input.attr("id");
62 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
63 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
68 /* setup field_richtext */
72 $('a[rel^=#]').click(function(e){
73 menu = $( $(this).attr('rel') );
76 if (menu.attr('popup')=="false") return false;
77 $(this).parent().toggleClass("selected");
83 $("a.popupbox").fancybox({
84 'transitionIn' : 'elastic',
85 'transitionOut' : 'elastic'
89 /* notifications template */
90 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
91 var notifications_empty = unescape($("#nav-notifications-menu").html());
93 /* nav update event */
94 $('nav').bind('nav-update', function(e,data){;
95 var net = $(data).find('net').text();
96 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
97 $('#net-update').html(net);
99 var home = $(data).find('home').text();
100 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
101 $('#home-update').html(home);
105 var intro = $(data).find('intro').text();
106 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
107 $('#intro-update').html(intro);
109 var mail = $(data).find('mail').text();
110 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
111 $('#mail-update').html(mail);
113 var eNotif = $(data).find('notif')
114 notif = eNotif.attr('count');
116 $("#nav-notifications-linkmenu").addClass("on");
117 nnm = $("#nav-notifications-menu");
119 nnm.html("<li><a href='"+baseurl+"/notifications/network'>Show All Notifications</a></li>");
121 //nnm.attr('popup','true');
122 eNotif.children("note").each(function(){
124 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
125 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'));
130 $("#nav-notifications-linkmenu").removeClass("on");
131 $("#nav-notifications-menu").html(notifications_empty);
133 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
134 $('#notify-update').html(notif);
136 var eSysmsg = $(data).find('sysmsgs');
137 eSysmsg.children("notice").each(function(){
138 text = $(this).text();
139 $.jGrowl(text, { sticky: true, theme: 'notice' });
141 eSysmsg.children("info").each(function(){
142 text = $(this).text();
143 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
150 // Allow folks to stop the ajax page updates with the pause/break key
151 $(document).keypress(function(event) {
152 if(event.keyCode == '19') {
153 event.preventDefault();
154 if(stopped == false) {
156 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
160 $('#pause').html('');
165 if(stopped == true) {
167 $('#pause').html('');
176 function NavUpdate() {
179 $.get("ping",function(data) {
180 $(data).find('result').each(function() {
181 // send nav-update event
182 $('nav').trigger('nav-update', this);
187 if($('#live-network').length) { src = 'network'; liveUpdate(); }
188 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
189 if($('#live-community').length) { src = 'community'; liveUpdate(); }
190 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
191 if($('#live-display').length) {
194 window.location.href=window.location.href
197 if($('#live-photos').length) {
200 window.location.href=window.location.href
210 timer = setTimeout(NavUpdate,30000);
213 function liveUpdate() {
214 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
215 if(($('.comment-edit-text-full').length) || (in_progress)) {
216 livetime = setTimeout(liveUpdate, 10000);
219 prev = 'live-' + src;
222 var udargs = ((netargs.length) ? '/' + netargs : '');
223 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
225 $.get(update_url,function(data) {
227 // $('.collapsed-comments',data).each(function() {
228 // var ident = $(this).attr('id');
229 // var is_hidden = $('#' + ident).is(':hidden');
230 // if($('#' + ident).length) {
231 // $('#' + ident).replaceWith($(this));
233 // $('#' + ident).hide();
239 $('.tread-wrapper',data).each(function() {
240 var ident = $(this).attr('id');
241 if($('#' + ident).length == 0) {
242 $('img',this).each(function() {
243 $(this).attr('src',$(this).attr('dst'));
245 $('#' + prev).after($(this));
250 // reset vars for inserting individual items
252 prev = 'live-' + src;
254 $('.wall-item-outside-wrapper',data).each(function() {
255 var ident = $(this).attr('id');
256 if($('#' + ident).length == 0) {
257 $('img',this).each(function() {
258 $(this).attr('src',$(this).attr('dst'));
260 $('#' + prev).after($(this));
263 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
264 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
265 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
266 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
267 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
268 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
269 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
270 $(this).attr('src',$(this).attr('dst'));
276 $('.like-rotator').hide();
279 $('body').css('cursor', 'auto');
281 /* autocomplete @nicknames */
282 $(".comment-edit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
286 function imgbright(node) {
287 $(node).removeClass("drophide").addClass("drop");
290 function imgdull(node) {
291 $(node).removeClass("drop").addClass("drophide");
294 // Since our ajax calls are asynchronous, we will give a few
295 // seconds for the first ajax call (setting like/dislike), then
296 // run the updater to pick up any changes and display on the page.
297 // The updater will turn any rotators off when it's done.
298 // This function will have returned long before any of these
299 // events have completed and therefore there won't be any
300 // visible feedback that anything changed without all this
301 // trickery. This still could cause confusion if the "like" ajax call
302 // is delayed and NavUpdate runs before it completes.
304 function dolike(ident,verb) {
305 $('#like-rotator-' + ident.toString()).show();
306 $.get('like/' + ident.toString() + '?verb=' + verb );
307 if(timer) clearTimeout(timer);
308 timer = setTimeout(NavUpdate,3000);
312 function dostar(ident) {
313 ident = ident.toString();
314 $('#like-rotator-' + ident).show();
315 $.get('starred/' + ident, function(data) {
316 if(data.match(/1/)) {
317 $('#starred-' + ident).addClass('starred');
318 $('#starred-' + ident).removeClass('unstarred');
319 $('#star-' + ident).addClass('hidden');
320 $('#unstar-' + ident).removeClass('hidden');
323 $('#starred-' + ident).addClass('unstarred');
324 $('#starred-' + ident).removeClass('starred');
325 $('#star-' + ident).removeClass('hidden');
326 $('#unstar-' + ident).addClass('hidden');
328 $('#like-rotator-' + ident).hide();
332 function getPosition(e) {
333 var cursor = {x:0, y:0};
334 if ( e.pageX || e.pageY ) {
339 if( e.clientX || e.clientY ) {
340 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
341 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
353 var lockvisible = false;
355 function lockview(event,id) {
356 event = event || window.event;
357 cursor = getPosition(event);
363 $.get('lockview/' + id, function(data) {
364 $('#panel').html(data);
365 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
371 function lockviewhide() {
376 function post_comment(id) {
378 $('body').css('cursor', 'wait');
381 $("#comment-edit-form-" + id).serialize(),
384 $("#comment-edit-wrapper-" + id).hide();
385 $("#comment-edit-text-" + id).val('');
386 var tarea = document.getElementById("comment-edit-text-" + id);
388 commentClose(tarea,id);
389 if(timer) clearTimeout(timer);
390 timer = setTimeout(NavUpdate,10);
393 window.location.href=data.reload;
403 // Converts the binary representation of data to hex
406 // discuss at: http://phpjs.org/functions/bin2hex
407 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
408 // + bugfixed by: Onno Marsman
409 // + bugfixed by: Linuxworld
410 // * example 1: bin2hex('Kev');
411 // * returns 1: '4b6576'
412 // * example 2: bin2hex(String.fromCharCode(0x00));
414 var v,i, f = 0, a = [];
418 for (i = 0; i<f; i++) {
419 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
425 function groupChangeMember(gid,cid) {
426 $('body .fakelink').css('cursor', 'wait');
427 $.get('group/' + gid + '/' + cid, function(data) {
428 $('#group-update-wrapper').html(data);
429 $('body .fakelink').css('cursor', 'auto');
433 function profChangeMember(gid,cid) {
434 $('body .fakelink').css('cursor', 'wait');
435 $.get('profperm/' + gid + '/' + cid, function(data) {
436 $('#prof-update-wrapper').html(data);
437 $('body .fakelink').css('cursor', 'auto');
441 function contactgroupChangeMember(gid,cid) {
442 $('body').css('cursor', 'wait');
443 $.get('contactgroup/' + gid + '/' + cid, function(data) {
444 $('body').css('cursor', 'auto');
449 function checkboxhighlight(box) {
450 if($(box).is(':checked')) {
451 $(box).addClass('checkeditem');
454 $(box).removeClass('checkeditem');
458 function setupFieldRichtext(){
461 mode : "specific_textareas",
462 editor_selector: "fieldRichtext",
463 plugins : "bbcode,paste",
464 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
465 theme_advanced_buttons2 : "",
466 theme_advanced_buttons3 : "",
467 theme_advanced_toolbar_location : "top",
468 theme_advanced_toolbar_align : "center",
469 theme_advanced_blockformats : "blockquote,code",
470 paste_text_sticky : true,
471 entity_encoding : "raw",
472 add_unload_trigger : false,
473 remove_linebreaks : false,
474 force_p_newlines : false,
475 force_br_newlines : true,
476 forced_root_block : '',
478 content_css: baseurl+"/view/custom_tinymce.css",
479 theme_advanced_path : false,
485 * sprintf in javascript
486 * "{0} and {1}".format('zero','uno');
488 String.prototype.format = function() {
489 var formatted = this;
490 for (var i = 0; i < arguments.length; i++) {
491 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
492 formatted = formatted.replace(regexp, arguments[i]);
497 Array.prototype.remove = function(item) {
498 to=undefined; from=this.indexOf(item);
499 var rest = this.slice((to || from) + 1 || this.length);
500 this.length = from < 0 ? this.length + from : from;
501 return this.push.apply(this, rest);