2 function openClose(listID) {
3 /* if(document.getElementById(theID).style.display == "block") {
4 document.getElementById(theID).style.display = "none"
7 document.getElementById(theID).style.display = "block"
9 listID = "#" + listID.replace(/:/g, "\\:");
10 listID = listID.replace(/\./g, "\\.");
11 listID = listID.replace(/@/g, "\\@");
13 if($(listID).is(":visible")) {
15 $(listID+"-wrapper").show();
19 $(listID+"-wrapper").hide();
23 function openMenu(theID) {
24 document.getElementById(theID).style.display = "block"
27 function closeMenu(theID) {
28 document.getElementById(theID).style.display = "none"
37 var totStopped = false;
41 var in_progress = false;
42 var langSelect = false;
43 var commentBusy = false;
44 var last_popup_menu = null;
45 var last_popup_button = null;
48 $.ajaxSetup({cache: false});
52 /* setup tooltips *//*
53 $("a,.tt").each(function(){
56 if (e.hasClass("tttop")) pos="top";
57 if (e.hasClass("ttbottom")) pos="bottom";
58 if (e.hasClass("ttleft")) pos="left";
59 if (e.hasClass("ttright")) pos="right";
60 e.tipTip({defaultPosition: pos, edgeOffset: 8});
65 /* setup onoff widgets */
66 $(".onoff input").each(function(){
68 id = $(this).attr("id");
69 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
72 $(".onoff > a").click(function(event){
73 event.preventDefault();
74 var input = $(this).siblings("input");
75 var val = 1-input.val();
76 var id = input.attr("id");
77 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
78 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
83 function close_last_popup_menu(e) {
85 if( last_popup_menu ) {
86 if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
87 last_popup_menu.hide();
88 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
89 last_popup_button.removeClass("selected");
90 last_popup_menu = null;
91 last_popup_button = null;
95 $('img[rel^=#]').click(function(e){
97 close_last_popup_menu(e);
98 menu = $( $(this).attr('rel') );
102 if (menu.attr('popup')=="false") return false;
104 // $(this).parent().toggleClass("selected");
107 if (menu.css("display") == "none") {
108 $(this).parent().addClass("selected");
110 if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').hide();
111 last_popup_menu = menu;
112 last_popup_button = $(this).parent();
114 $(this).parent().removeClass("selected");
116 if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
117 last_popup_menu = null;
118 last_popup_button = null;
122 $('html').click(function(e) {
123 close_last_popup_menu(e);
127 /*$("a.popupbox").colorbox({
129 'transition' : 'none'
133 /* notifications template */
134 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
135 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
136 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
137 var notifications_empty = unescape($("#nav-notifications-menu").html());
139 /* nav update event */
140 $('nav').bind('nav-update', function(e,data){;
141 var invalid = $(data).find('invalid').text();
142 if(invalid == 1) { window.location.href=window.location.href }
144 var net = $(data).find('net').text();
145 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
146 $('#net-update').html(net);
148 var home = $(data).find('home').text();
149 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
150 $('#home-update').html(home);
152 var intro = $(data).find('intro').text();
153 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
154 $('#intro-update').html(intro);
156 var mail = $(data).find('mail').text();
157 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
158 $('#mail-update').html(mail);
160 var intro = $(data).find('intro').text();
161 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
162 $('#intro-update-li').html(intro);
164 var mail = $(data).find('mail').text();
165 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
166 $('#mail-update-li').html(mail);
168 var eNotif = $(data).find('notif')
170 if (eNotif.children("note").length==0){
171 $("#nav-notifications-menu").html(notifications_empty);
173 nnm = $("#nav-notifications-menu");
174 nnm.html(notifications_all + notifications_mark);
175 //nnm.attr('popup','true');
176 eNotif.children("note").each(function(){
178 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
179 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
183 $("img[data-src]", nnm).each(function(i, el){
184 // Add src attribute for images with a data-src attribute
185 // However, don't bother if the data-src attribute is empty, because
186 // an empty "src" tag for an image will cause some browsers
187 // to prefetch the root page of the Friendica hub, which will
188 // unnecessarily load an entire profile/ or network/ page
189 if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
192 notif = eNotif.attr('count');
194 $("#nav-notifications-linkmenu").addClass("on");
196 $("#nav-notifications-linkmenu").removeClass("on");
198 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
199 $('#notify-update').html(notif);
201 var eSysmsg = $(data).find('sysmsgs');
202 eSysmsg.children("notice").each(function(){
203 text = $(this).text();
204 $.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
206 eSysmsg.children("info").each(function(){
207 text = $(this).text();
208 $.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
215 // Allow folks to stop the ajax page updates with the pause/break key
216 /* $(document).keydown(function(event) {
217 if(event.keyCode == '8') {
218 var target = event.target || event.srcElement;
219 if (!/input|textarea/i.test(target.nodeName)) {
223 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
224 event.preventDefault();
225 if(stopped == false) {
230 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
244 function NavUpdate() {
247 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
248 $.get(pingCmd,function(data) {
249 $(data).find('result').each(function() {
250 // send nav-update event
251 $('nav').trigger('nav-update', this);
258 if($('#live-network').length) { src = 'network'; liveUpdate(); }
259 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
260 if($('#live-community').length) { src = 'community'; liveUpdate(); }
261 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
262 if($('#live-display').length) { src = 'display'; liveUpdate(); }
263 /*if($('#live-display').length) {
266 window.location.href=window.location.href
269 if($('#live-photos').length) {
272 window.location.href=window.location.href
282 timer = setTimeout(NavUpdate,updateInterval);
285 function liveUpdate() {
286 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $('.like-rotator').hide(); return; }
287 if(($('.comment-edit-text-full').length) || (in_progress)) {
289 clearTimeout(livetime);
291 livetime = setTimeout(liveUpdate, 5000);
297 prev = 'live-' + src;
300 var udargs = ((netargs.length) ? '/' + netargs : '');
301 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page;
303 $.get(update_url,function(data) {
305 // $('.collapsed-comments',data).each(function() {
306 // var ident = $(this).attr('id');
307 // var is_hidden = $('#' + ident).is(':hidden');
308 // if($('#' + ident).length) {
309 // $('#' + ident).replaceWith($(this));
311 // $('#' + ident).hide();
317 $('.toplevel_item',data).each(function() {
318 var ident = $(this).attr('id');
320 if($('#' + ident).length == 0 && profile_page == 1) {
321 $('img',this).each(function() {
322 $(this).attr('src',$(this).attr('dst'));
324 $('#' + prev).after($(this));
327 // Find out if the hidden comments are open, so we can keep it that way
328 // if a new comment has been posted
329 var id = $('.hide-comments-total', this).attr('id');
330 if(typeof id != 'undefined') {
331 id = id.split('-')[3];
332 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
335 $('img',this).each(function() {
336 $(this).attr('src',$(this).attr('dst'));
338 //vScroll = $(document).scrollTop();
339 $('html').height($('html').height());
340 $('#' + ident).replaceWith($(this));
342 if(typeof id != 'undefined') {
343 if(commentsOpen) showHideComments(id);
345 $('html').height('auto');
346 //$(document).scrollTop(vScroll);
354 // reset vars for inserting individual items
356 /*prev = 'live-' + src;
358 $('.wall-item-outside-wrapper',data).each(function() {
359 var ident = $(this).attr('id');
361 if($('#' + ident).length == 0 && prev != 'live-' + src) {
362 $('img',this).each(function() {
363 $(this).attr('src',$(this).attr('dst'));
365 $('#' + prev).after($(this));
368 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
369 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
370 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
371 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
372 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
373 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
374 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
375 $(this).attr('src',$(this).attr('dst'));
381 $('.like-rotator').hide();
384 $('body').css('cursor', 'auto');
386 /* autocomplete @nicknames */
387 $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl");
389 // setup videos, since VideoJS won't take care of any loaded via AJAX
390 if(typeof videojs != 'undefined') videojs.autoSetup();
394 function collapseHeight(elems) {
395 var elemName = '.wall-item-body:not(.divmore)';
396 if(typeof elems != 'undefined') {
397 elemName = elems + ' ' + elemName;
399 $(elemName).each(function() {
400 $('html').height($('html').height());
401 $(this).readmore({maxheight:350 , moreLink:'<a href="#" class="showmore">+ Show more</a>', lessLink:'<a href="#" class="showmore">+ Show less</a>'});
402 $(this).addClass('divmore');
403 $('html').height('auto');
407 /* function imgbright(node) {
408 $(node).removeClass("drophide").addClass("drop");
411 function imgdull(node) {
412 $(node).removeClass("drop").addClass("drophide");
415 // Since our ajax calls are asynchronous, we will give a few
416 // seconds for the first ajax call (setting like/dislike), then
417 // run the updater to pick up any changes and display on the page.
418 // The updater will turn any rotators off when it's done.
419 // This function will have returned long before any of these
420 // events have completed and therefore there won't be any
421 // visible feedback that anything changed without all this
422 // trickery. This still could cause confusion if the "like" ajax call
423 // is delayed and NavUpdate runs before it completes.
425 function dolike(ident,verb) {
427 $('#like-rotator-' + ident.toString()).show();
428 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
429 // if(timer) clearTimeout(timer);
430 // timer = setTimeout(NavUpdate,3000);
434 function dostar(ident) {
435 ident = ident.toString();
436 //$('#like-rotator-' + ident).show();
437 $.get('starred/' + ident, function(data) {
438 if(data.match(/1/)) {
439 $('#starred-' + ident).addClass('starred');
440 $('#starred-' + ident).removeClass('unstarred');
441 $('#star-' + ident).addClass('hidden');
442 $('#unstar-' + ident).removeClass('hidden');
445 $('#starred-' + ident).addClass('unstarred');
446 $('#starred-' + ident).removeClass('starred');
447 $('#star-' + ident).removeClass('hidden');
448 $('#unstar-' + ident).addClass('hidden');
450 //$('#like-rotator-' + ident).hide();
454 function getPosition(e) {
455 var cursor = {x:0, y:0};
456 if ( e.pageX || e.pageY ) {
461 if( e.clientX || e.clientY ) {
462 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
463 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
475 var lockvisible = false;
477 function lockview(event,id) {
478 event = event || window.event;
479 cursor = getPosition(event);
485 $.get('lockview/' + id, function(data) {
486 $('#panel').html(data);
487 $('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
493 function lockviewhide() {
498 function post_comment(id) {
501 $('body').css('cursor', 'wait');
502 $("#comment-preview-inp-" + id).val("0");
505 $("#comment-edit-form-" + id).serialize(),
508 $("#comment-edit-wrapper-" + id).hide();
509 $("#comment-edit-text-" + id).val('');
510 var tarea = document.getElementById("comment-edit-text-" + id);
512 commentClose(tarea,id);
513 if(timer) clearTimeout(timer);
514 timer = setTimeout(NavUpdate,10);
517 window.location.href=data.reload;
526 function preview_comment(id) {
527 $("#comment-preview-inp-" + id).val("1");
528 $("#comment-edit-preview-" + id).show();
531 $("#comment-edit-form-" + id).serialize(),
535 $("#comment-edit-preview-" + id).html(data.preview);
536 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
545 function showHideComments(id) {
546 if( $("#collapsed-comments-" + id).is(":visible")) {
547 $("#collapsed-comments-" + id).hide();
548 $("#hide-comments-" + id).html(window.showMore);
551 $("#collapsed-comments-" + id).show();
552 $("#hide-comments-" + id).html(window.showFewer);
553 collapseHeight("#collapsed-comments-" + id);
558 function preview_post() {
559 $("#jot-preview").val("1");
560 $("#jot-preview-content").show();
563 $("#profile-jot-form").serialize(),
566 $("#jot-preview-content").html(data.preview);
567 $("#jot-preview-content" + " a").click(function() { return false; });
572 $("#jot-preview").val("0");
578 // unpause auto reloads if they are currently stopped
581 $('#pause').html('');
586 // Converts the binary representation of data to hex
589 // discuss at: http://phpjs.org/functions/bin2hex
590 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
591 // + bugfixed by: Onno Marsman
592 // + bugfixed by: Linuxworld
593 // * example 1: bin2hex('Kev');
594 // * returns 1: '4b6576'
595 // * example 2: bin2hex(String.fromCharCode(0x00));
597 var v,i, f = 0, a = [];
601 for (i = 0; i<f; i++) {
602 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
608 function groupChangeMember(gid, cid, sec_token) {
609 $('body .fakelink').css('cursor', 'wait');
610 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
611 $('#group-update-wrapper').html(data);
612 $('body .fakelink').css('cursor', 'auto');
616 function profChangeMember(gid,cid) {
617 $('body .fakelink').css('cursor', 'wait');
618 $.get('profperm/' + gid + '/' + cid, function(data) {
619 $('#prof-update-wrapper').html(data);
620 $('body .fakelink').css('cursor', 'auto');
624 function contactgroupChangeMember(gid,cid) {
625 $('body').css('cursor', 'wait');
626 $.get('contactgroup/' + gid + '/' + cid, function(data) {
627 $('body').css('cursor', 'auto');
632 function checkboxhighlight(box) {
633 if($(box).is(':checked')) {
634 $(box).addClass('checkeditem');
637 $(box).removeClass('checkeditem');
641 function notifyMarkAll() {
642 $.get('notify/mark/all', function(data) {
643 if(timer) clearTimeout(timer);
644 timer = setTimeout(NavUpdate,1000);
649 * sprintf in javascript
650 * "{0} and {1}".format('zero','uno');
652 String.prototype.format = function() {
653 var formatted = this;
654 for (var i = 0; i < arguments.length; i++) {
655 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
656 formatted = formatted.replace(regexp, arguments[i]);
661 Array.prototype.remove = function(item) {
662 to=undefined; from=this.indexOf(item);
663 var rest = this.slice((to || from) + 1 || this.length);
664 this.length = from < 0 ? this.length + from : from;
665 return this.push.apply(this, rest);
668 function previewTheme(elm) {
669 theme = $(elm).val();
670 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
671 $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');