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");
84 function close_last_popup_menu(e) {
86 if( last_popup_menu ) {
87 if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
88 last_popup_menu.hide();
89 last_popup_button.removeClass("selected");
90 last_popup_menu = null;
91 last_popup_button = null;
95 $('a[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");
105 menu.slideToggle('fast');
107 if (menu.css("display") == "none") {
108 last_popup_menu = null;
109 last_popup_button = null;
111 last_popup_menu = menu;
112 last_popup_button = $(this).parent();
116 $('html').click(function(e) {
117 close_last_popup_menu(e);
121 $("a.popupbox").colorbox({
123 'transition' : 'elastic'
127 /* notifications template */
128 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
129 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
130 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
131 var notifications_empty = unescape($("#nav-notifications-menu").html());
133 /* nav update event */
134 $('nav').bind('nav-update', function(e,data){;
135 var invalid = $(data).find('invalid').text();
136 if(invalid == 1) { window.location.href=window.location.href }
138 var net = $(data).find('net').text();
139 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
140 $('#net-update').html(net);
142 var home = $(data).find('home').text();
143 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
144 $('#home-update').html(home);
146 var intro = $(data).find('intro').text();
147 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
148 $('#intro-update').html(intro);
150 var mail = $(data).find('mail').text();
151 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
152 $('#mail-update').html(mail);
154 var intro = $(data).find('intro').text();
155 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
156 $('#intro-update-li').html(intro);
158 var mail = $(data).find('mail').text();
159 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
160 $('#mail-update-li').html(mail);
162 var eNotif = $(data).find('notif')
164 if (eNotif.children("note").length==0){
165 $("#nav-notifications-menu").html(notifications_empty);
167 nnm = $("#nav-notifications-menu");
168 nnm.html(notifications_all + notifications_mark);
169 //nnm.attr('popup','true');
170 eNotif.children("note").each(function(){
172 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
173 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
177 $("img[data-src]", nnm).each(function(i, el){
178 // Add src attribute for images with a data-src attribute
179 // However, don't bother if the data-src attribute is empty, because
180 // an empty "src" tag for an image will cause some browsers
181 // to prefetch the root page of the Friendica hub, which will
182 // unnecessarily load an entire profile/ or network/ page
183 if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
186 notif = eNotif.attr('count');
188 $("#nav-notifications-linkmenu").addClass("on");
190 $("#nav-notifications-linkmenu").removeClass("on");
192 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
193 $('#notify-update').html(notif);
195 var eSysmsg = $(data).find('sysmsgs');
196 eSysmsg.children("notice").each(function(){
197 text = $(this).text();
198 $.jGrowl(text, { sticky: false, theme: 'notice', life: 3000 }); // originally: sticky: true,
200 eSysmsg.children("info").each(function(){
201 text = $(this).text();
202 $.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
209 // Allow folks to stop the ajax page updates with the pause/break key
210 $(document).keydown(function(event) {
211 if(event.keyCode == '8') {
212 var target = event.target || event.srcElement;
213 if (!/input|textarea/i.test(target.nodeName)) {
217 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
218 event.preventDefault();
219 if(stopped == false) {
224 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
238 function NavUpdate() {
241 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
242 $.get(pingCmd,function(data) {
243 $(data).find('result').each(function() {
244 // send nav-update event
245 $('nav').trigger('nav-update', this);
252 if($('#live-network').length) { src = 'network'; liveUpdate(); }
253 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
254 if($('#live-community').length) { src = 'community'; liveUpdate(); }
255 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
256 if($('#live-display').length) { src = 'display'; liveUpdate(); }
257 /*if($('#live-display').length) {
260 window.location.href=window.location.href
263 if($('#live-photos').length) {
266 window.location.href=window.location.href
276 timer = setTimeout(NavUpdate,updateInterval);
279 function liveUpdate() {
280 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $('.like-rotator').hide(); return; }
281 if(($('.comment-edit-text-full').length) || (in_progress)) {
283 clearTimeout(livetime);
285 livetime = setTimeout(liveUpdate, 5000);
291 prev = 'live-' + src;
294 var udargs = ((netargs.length) ? '/' + netargs : '');
295 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page;
297 $.get(update_url,function(data) {
299 // $('.collapsed-comments',data).each(function() {
300 // var ident = $(this).attr('id');
301 // var is_hidden = $('#' + ident).is(':hidden');
302 // if($('#' + ident).length) {
303 // $('#' + ident).replaceWith($(this));
305 // $('#' + ident).hide();
311 $('.toplevel_item',data).each(function() {
312 var ident = $(this).attr('id');
314 if($('#' + ident).length == 0 && profile_page == 1) {
315 $('img',this).each(function() {
316 $(this).attr('src',$(this).attr('dst'));
318 $('#' + prev).after($(this));
321 // Find out if the hidden comments are open, so we can keep it that way
322 // if a new comment has been posted
323 var id = $('.hide-comments-total', this).attr('id');
324 if(typeof id != 'undefined') {
325 id = id.split('-')[3];
326 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
329 $('img',this).each(function() {
330 $(this).attr('src',$(this).attr('dst'));
332 //vScroll = $(document).scrollTop();
333 $('html').height($('html').height());
334 $('#' + ident).replaceWith($(this));
336 if(typeof id != 'undefined') {
337 if(commentsOpen) showHideComments(id);
339 $('html').height('auto');
340 //$(document).scrollTop(vScroll);
343 // Add Colorbox for viewing Network page images
344 $("#" + ident + " .wall-item-body a img").each(function(){
345 var aElem = $(this).parent();
346 var imgHref = aElem.attr("href");
348 // We need to make sure we only put a Colorbox on links to Friendica images
349 // We'll try to do this by looking for links of the form
350 // .../photo/ab803d8eg08daf85023adfec08(-0.jpg) (with nothing more following), in hopes
351 // that that will be unique enough
352 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
354 // Add a unique class to all the images of a certain post, to allow scrolling through
355 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
356 $(this).addClass(cBoxClass);
369 // reset vars for inserting individual items
371 /*prev = 'live-' + src;
373 $('.wall-item-outside-wrapper',data).each(function() {
374 var ident = $(this).attr('id');
376 if($('#' + ident).length == 0 && prev != 'live-' + src) {
377 $('img',this).each(function() {
378 $(this).attr('src',$(this).attr('dst'));
380 $('#' + prev).after($(this));
383 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
384 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
385 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
386 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
387 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
388 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
389 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
390 $(this).attr('src',$(this).attr('dst'));
396 $('.like-rotator').hide();
399 $('body').css('cursor', 'auto');
401 /* autocomplete @nicknames */
402 $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl");
406 // setup videos, since VideoJS won't take care of any loaded via AJAX
407 if(typeof videojs != 'undefined') videojs.autoSetup();
411 function collapseHeight(elems) {
412 var elemName = '.wall-item-body:not(.divmore)';
413 if(typeof elems != 'undefined') {
414 elemName = elems + ' ' + elemName;
416 $(elemName).each(function() {
417 if($(this).height() > 450) {
418 $('html').height($('html').height());
419 $(this).divgrow({ initialHeight: 400, showBrackets: false, speed: 0 });
420 $(this).addClass('divmore');
421 $('html').height('auto');
426 /*function imgbright(node) {
427 $(node).removeClass("drophide").addClass("drop");
430 function imgdull(node) {
431 $(node).removeClass("drop").addClass("drophide");
434 // Since our ajax calls are asynchronous, we will give a few
435 // seconds for the first ajax call (setting like/dislike), then
436 // run the updater to pick up any changes and display on the page.
437 // The updater will turn any rotators off when it's done.
438 // This function will have returned long before any of these
439 // events have completed and therefore there won't be any
440 // visible feedback that anything changed without all this
441 // trickery. This still could cause confusion if the "like" ajax call
442 // is delayed and NavUpdate runs before it completes.
444 function dolike(ident,verb) {
446 $('#like-rotator-' + ident.toString()).show();
447 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
451 function dostar(ident) {
452 ident = ident.toString();
453 // $('#like-rotator-' + ident).show();
454 $.get('starred/' + ident, function(data) {
455 if(data.match(/1/)) {
456 $('#starred-' + ident).addClass('starred');
457 $('#starred-' + ident).removeClass('unstarred');
458 $('#star-' + ident).addClass('hidden');
459 $('#unstar-' + ident).removeClass('hidden');
462 $('#starred-' + ident).addClass('unstarred');
463 $('#starred-' + ident).removeClass('starred');
464 $('#star-' + ident).removeClass('hidden');
465 $('#unstar-' + ident).addClass('hidden');
467 // $('#like-rotator-' + ident).hide();
471 function getPosition(e) {
472 var cursor = {x:0, y:0};
473 if ( e.pageX || e.pageY ) {
478 if( e.clientX || e.clientY ) {
479 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
480 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
492 var lockvisible = false;
494 function lockview(event,id) {
495 event = event || window.event;
496 cursor = getPosition(event);
502 $.get('lockview/' + id, function(data) {
503 $('#panel').html(data);
504 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
510 function lockviewhide() {
515 function post_comment(id) {
518 $('body').css('cursor', 'wait');
519 $("#comment-preview-inp-" + id).val("0");
522 $("#comment-edit-form-" + id).serialize(),
525 $("#comment-edit-wrapper-" + id).hide();
526 $("#comment-edit-text-" + id).val('');
527 var tarea = document.getElementById("comment-edit-text-" + id);
529 commentClose(tarea,id);
530 if(timer) clearTimeout(timer);
531 timer = setTimeout(NavUpdate,10);
534 window.location.href=data.reload;
543 function preview_comment(id) {
544 $("#comment-preview-inp-" + id).val("1");
545 $("#comment-edit-preview-" + id).show();
548 $("#comment-edit-form-" + id).serialize(),
552 $("#comment-edit-preview-" + id).html(data.preview);
553 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
562 function showHideComments(id) {
563 if( $("#collapsed-comments-" + id).is(":visible")) {
564 $("#collapsed-comments-" + id).hide();
565 $("#hide-comments-" + id).html(window.showMore);
568 $("#collapsed-comments-" + id).show();
569 $("#hide-comments-" + id).html(window.showFewer);
570 collapseHeight("#collapsed-comments-" + id);
575 function preview_post() {
576 $("#jot-preview").val("1");
577 $("#jot-preview-content").show();
580 $("#profile-jot-form").serialize(),
583 $("#jot-preview-content").html(data.preview);
584 $("#jot-preview-content" + " a").click(function() { return false; });
589 $("#jot-preview").val("0");
595 // unpause auto reloads if they are currently stopped
598 $('#pause').html('');
603 // Converts the binary representation of data to hex
606 // discuss at: http://phpjs.org/functions/bin2hex
607 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
608 // + bugfixed by: Onno Marsman
609 // + bugfixed by: Linuxworld
610 // * example 1: bin2hex('Kev');
611 // * returns 1: '4b6576'
612 // * example 2: bin2hex(String.fromCharCode(0x00));
614 var v,i, f = 0, a = [];
618 for (i = 0; i<f; i++) {
619 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
625 function groupChangeMember(gid, cid, sec_token) {
626 $('body .fakelink').css('cursor', 'wait');
627 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
628 $('#group-update-wrapper').html(data);
629 $('body .fakelink').css('cursor', 'auto');
633 function profChangeMember(gid,cid) {
634 $('body .fakelink').css('cursor', 'wait');
635 $.get('profperm/' + gid + '/' + cid, function(data) {
636 $('#prof-update-wrapper').html(data);
637 $('body .fakelink').css('cursor', 'auto');
641 function contactgroupChangeMember(gid,cid) {
642 $('body').css('cursor', 'wait');
643 $.get('contactgroup/' + gid + '/' + cid, function(data) {
644 $('body').css('cursor', 'auto');
649 function checkboxhighlight(box) {
650 if($(box).is(':checked')) {
651 $(box).addClass('checkeditem');
654 $(box).removeClass('checkeditem');
658 function notifyMarkAll() {
659 $.get('notify/mark/all', function(data) {
660 if(timer) clearTimeout(timer);
661 timer = setTimeout(NavUpdate,1000);
666 * sprintf in javascript
667 * "{0} and {1}".format('zero','uno');
669 String.prototype.format = function() {
670 var formatted = this;
671 for (var i = 0; i < arguments.length; i++) {
672 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
673 formatted = formatted.replace(regexp, arguments[i]);
678 Array.prototype.remove = function(item) {
679 to=undefined; from=this.indexOf(item);
680 var rest = this.slice((to || from) + 1 || this.length);
681 this.length = from < 0 ? this.length + from : from;
682 return this.push.apply(this, rest);
685 function previewTheme(elm) {
686 theme = $(elm).val();
687 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
688 $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div><a href="' + data.img + '"><img src="' + data.img + '" width="320" height="240" alt="' + theme + '" /></a>');