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});
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 function close_last_popup_menu(e) {
70 if( last_popup_menu ) {
71 if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
72 last_popup_menu.hide();
73 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
74 last_popup_button.removeClass("selected");
75 last_popup_menu = null;
76 last_popup_button = null;
80 $('img[rel^=#]').click(function(e){
82 close_last_popup_menu(e);
83 menu = $( $(this).attr('rel') );
87 if (menu.attr('popup')=="false") return false;
89 // $(this).parent().toggleClass("selected");
92 if (menu.css("display") == "none") {
93 $(this).parent().addClass("selected");
95 if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').hide();
96 last_popup_menu = menu;
97 last_popup_button = $(this).parent();
99 $(this).parent().removeClass("selected");
101 if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
102 last_popup_menu = null;
103 last_popup_button = null;
107 $('html').click(function(e) {
108 close_last_popup_menu(e);
112 /*$("a.popupbox").colorbox({
114 'transition' : 'none'
118 /* notifications template */
119 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
120 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
121 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
122 var notifications_empty = unescape($("#nav-notifications-menu").html());
124 /* nav update event */
125 $('nav').bind('nav-update', function(e,data){;
126 var invalid = $(data).find('invalid').text();
127 if(invalid == 1) { window.location.href=window.location.href }
129 var net = $(data).find('net').text();
130 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
131 $('#net-update').html(net);
133 var home = $(data).find('home').text();
134 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
135 $('#home-update').html(home);
137 var intro = $(data).find('intro').text();
138 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
139 $('#intro-update').html(intro);
141 var mail = $(data).find('mail').text();
142 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
143 $('#mail-update').html(mail);
145 var intro = $(data).find('intro').text();
146 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
147 $('#intro-update-li').html(intro);
149 var mail = $(data).find('mail').text();
150 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
151 $('#mail-update-li').html(mail);
153 var eNotif = $(data).find('notif')
155 if (eNotif.children("note").length==0){
156 $("#nav-notifications-menu").html(notifications_empty);
158 nnm = $("#nav-notifications-menu");
159 nnm.html(notifications_all + notifications_mark);
160 //nnm.attr('popup','true');
161 eNotif.children("note").each(function(){
163 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
164 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
168 $("img[data-src]", nnm).each(function(i, el){
169 // Add src attribute for images with a data-src attribute
170 // However, don't bother if the data-src attribute is empty, because
171 // an empty "src" tag for an image will cause some browsers
172 // to prefetch the root page of the Friendica hub, which will
173 // unnecessarily load an entire profile/ or network/ page
174 if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
177 notif = eNotif.attr('count');
179 $("#nav-notifications-linkmenu").addClass("on");
181 $("#nav-notifications-linkmenu").removeClass("on");
183 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
184 $('#notify-update').html(notif);
186 var eSysmsg = $(data).find('sysmsgs');
187 eSysmsg.children("notice").each(function(){
188 text = $(this).text();
189 $.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
191 eSysmsg.children("info").each(function(){
192 text = $(this).text();
193 $.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
200 // Allow folks to stop the ajax page updates with the pause/break key
201 /* $(document).keydown(function(event) {
202 if(event.keyCode == '8') {
203 var target = event.target || event.srcElement;
204 if (!/input|textarea/i.test(target.nodeName)) {
208 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
209 event.preventDefault();
210 if(stopped == false) {
215 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
229 function NavUpdate() {
232 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
233 $.get(pingCmd,function(data) {
234 $(data).find('result').each(function() {
235 // send nav-update event
236 $('nav').trigger('nav-update', this);
243 if($('#live-network').length) { src = 'network'; liveUpdate(); }
244 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
245 if($('#live-community').length) { src = 'community'; liveUpdate(); }
246 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
247 if($('#live-display').length) { src = 'display'; liveUpdate(); }
248 /*if($('#live-display').length) {
251 window.location.href=window.location.href
254 if($('#live-photos').length) {
257 window.location.href=window.location.href
267 timer = setTimeout(NavUpdate,updateInterval);
270 function liveUpdate() {
271 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $('.like-rotator').hide(); return; }
272 if(($('.comment-edit-text-full').length) || (in_progress)) {
274 clearTimeout(livetime);
276 livetime = setTimeout(liveUpdate, 5000);
282 prev = 'live-' + src;
285 var udargs = ((netargs.length) ? '/' + netargs : '');
286 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page;
288 $.get(update_url,function(data) {
290 // $('.collapsed-comments',data).each(function() {
291 // var ident = $(this).attr('id');
292 // var is_hidden = $('#' + ident).is(':hidden');
293 // if($('#' + ident).length) {
294 // $('#' + ident).replaceWith($(this));
296 // $('#' + ident).hide();
302 $('.toplevel_item',data).each(function() {
303 var ident = $(this).attr('id');
305 if($('#' + ident).length == 0 && profile_page == 1) {
306 $('img',this).each(function() {
307 $(this).attr('src',$(this).attr('dst'));
309 $('#' + prev).after($(this));
312 // Find out if the hidden comments are open, so we can keep it that way
313 // if a new comment has been posted
314 var id = $('.hide-comments-total', this).attr('id');
315 if(typeof id != 'undefined') {
316 id = id.split('-')[3];
317 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
320 $('img',this).each(function() {
321 $(this).attr('src',$(this).attr('dst'));
323 //vScroll = $(document).scrollTop();
324 $('html').height($('html').height());
325 $('#' + ident).replaceWith($(this));
327 if(typeof id != 'undefined') {
328 if(commentsOpen) showHideComments(id);
330 $('html').height('auto');
331 //$(document).scrollTop(vScroll);
339 // reset vars for inserting individual items
341 /*prev = 'live-' + src;
343 $('.wall-item-outside-wrapper',data).each(function() {
344 var ident = $(this).attr('id');
346 if($('#' + ident).length == 0 && prev != 'live-' + src) {
347 $('img',this).each(function() {
348 $(this).attr('src',$(this).attr('dst'));
350 $('#' + prev).after($(this));
353 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
354 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
355 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
356 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
357 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
358 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
359 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
360 $(this).attr('src',$(this).attr('dst'));
366 $('.like-rotator').hide();
369 $('body').css('cursor', 'auto');
371 /* autocomplete @nicknames */
372 $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl");
374 // setup videos, since VideoJS won't take care of any loaded via AJAX
375 if(typeof videojs != 'undefined') videojs.autoSetup();
379 function collapseHeight(elems) {
380 var elemName = '.wall-item-body:not(.divmore)';
381 if(typeof elems != 'undefined') {
382 elemName = elems + ' ' + elemName;
384 $(elemName).each(function() {
385 $('html').height($('html').height());
386 $(this).readmore({maxheight:350 , moreLink:'<a href="#" class="showmore">+ Show more</a>', lessLink:'<a href="#" class="showmore">+ Show less</a>'});
387 $(this).addClass('divmore');
388 $('html').height('auto');
392 /* function imgbright(node) {
393 $(node).removeClass("drophide").addClass("drop");
396 function imgdull(node) {
397 $(node).removeClass("drop").addClass("drophide");
400 // Since our ajax calls are asynchronous, we will give a few
401 // seconds for the first ajax call (setting like/dislike), then
402 // run the updater to pick up any changes and display on the page.
403 // The updater will turn any rotators off when it's done.
404 // This function will have returned long before any of these
405 // events have completed and therefore there won't be any
406 // visible feedback that anything changed without all this
407 // trickery. This still could cause confusion if the "like" ajax call
408 // is delayed and NavUpdate runs before it completes.
410 function dolike(ident,verb) {
412 $('#like-rotator-' + ident.toString()).show();
413 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
414 // if(timer) clearTimeout(timer);
415 // timer = setTimeout(NavUpdate,3000);
419 function dostar(ident) {
420 ident = ident.toString();
421 //$('#like-rotator-' + ident).show();
422 $.get('starred/' + ident, function(data) {
423 if(data.match(/1/)) {
424 $('#starred-' + ident).addClass('starred');
425 $('#starred-' + ident).removeClass('unstarred');
426 $('#star-' + ident).addClass('hidden');
427 $('#unstar-' + ident).removeClass('hidden');
430 $('#starred-' + ident).addClass('unstarred');
431 $('#starred-' + ident).removeClass('starred');
432 $('#star-' + ident).removeClass('hidden');
433 $('#unstar-' + ident).addClass('hidden');
435 //$('#like-rotator-' + ident).hide();
439 function getPosition(e) {
440 var cursor = {x:0, y:0};
441 if ( e.pageX || e.pageY ) {
446 if( e.clientX || e.clientY ) {
447 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
448 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
460 var lockvisible = false;
462 function lockview(event,id) {
463 event = event || window.event;
464 cursor = getPosition(event);
470 $.get('lockview/' + id, function(data) {
471 $('#panel').html(data);
472 $('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
478 function lockviewhide() {
483 function post_comment(id) {
486 $('body').css('cursor', 'wait');
487 $("#comment-preview-inp-" + id).val("0");
490 $("#comment-edit-form-" + id).serialize(),
493 $("#comment-edit-wrapper-" + id).hide();
494 $("#comment-edit-text-" + id).val('');
495 var tarea = document.getElementById("comment-edit-text-" + id);
497 commentClose(tarea,id);
498 if(timer) clearTimeout(timer);
499 timer = setTimeout(NavUpdate,10);
502 window.location.href=data.reload;
511 function preview_comment(id) {
512 $("#comment-preview-inp-" + id).val("1");
513 $("#comment-edit-preview-" + id).show();
516 $("#comment-edit-form-" + id).serialize(),
520 $("#comment-edit-preview-" + id).html(data.preview);
521 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
530 function showHideComments(id) {
531 if( $("#collapsed-comments-" + id).is(":visible")) {
532 $("#collapsed-comments-" + id).hide();
533 $("#hide-comments-" + id).html(window.showMore);
536 $("#collapsed-comments-" + id).show();
537 $("#hide-comments-" + id).html(window.showFewer);
538 collapseHeight("#collapsed-comments-" + id);
543 function preview_post() {
544 $("#jot-preview").val("1");
545 $("#jot-preview-content").show();
548 $("#profile-jot-form").serialize(),
551 $("#jot-preview-content").html(data.preview);
552 $("#jot-preview-content" + " a").click(function() { return false; });
557 $("#jot-preview").val("0");
563 // unpause auto reloads if they are currently stopped
566 $('#pause').html('');
571 // Converts the binary representation of data to hex
574 // discuss at: http://phpjs.org/functions/bin2hex
575 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
576 // + bugfixed by: Onno Marsman
577 // + bugfixed by: Linuxworld
578 // * example 1: bin2hex('Kev');
579 // * returns 1: '4b6576'
580 // * example 2: bin2hex(String.fromCharCode(0x00));
582 var v,i, f = 0, a = [];
586 for (i = 0; i<f; i++) {
587 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
593 function groupChangeMember(gid, cid, sec_token) {
594 $('body .fakelink').css('cursor', 'wait');
595 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
596 $('#group-update-wrapper').html(data);
597 $('body .fakelink').css('cursor', 'auto');
601 function profChangeMember(gid,cid) {
602 $('body .fakelink').css('cursor', 'wait');
603 $.get('profperm/' + gid + '/' + cid, function(data) {
604 $('#prof-update-wrapper').html(data);
605 $('body .fakelink').css('cursor', 'auto');
609 function contactgroupChangeMember(gid,cid) {
610 $('body').css('cursor', 'wait');
611 $.get('contactgroup/' + gid + '/' + cid, function(data) {
612 $('body').css('cursor', 'auto');
617 function checkboxhighlight(box) {
618 if($(box).is(':checked')) {
619 $(box).addClass('checkeditem');
622 $(box).removeClass('checkeditem');
626 function notifyMarkAll() {
627 $.get('notify/mark/all', function(data) {
628 if(timer) clearTimeout(timer);
629 timer = setTimeout(NavUpdate,1000);
634 * sprintf in javascript
635 * "{0} and {1}".format('zero','uno');
637 String.prototype.format = function() {
638 var formatted = this;
639 for (var i = 0; i < arguments.length; i++) {
640 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
641 formatted = formatted.replace(regexp, arguments[i]);
646 Array.prototype.remove = function(item) {
647 to=undefined; from=this.indexOf(item);
648 var rest = this.slice((to || from) + 1 || this.length);
649 this.length = from < 0 ? this.length + from : from;
650 return this.push.apply(this, rest);
653 function previewTheme(elm) {
654 theme = $(elm).val();
655 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
656 $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');