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 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");
71 function close_last_popup_menu(e) {
73 if( last_popup_menu ) {
74 if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
75 last_popup_menu.hide();
76 last_popup_button.removeClass("selected");
77 last_popup_menu = null;
78 last_popup_button = null;
82 $('a[rel^=#]').click(function(e){
84 close_last_popup_menu(e);
85 menu = $( $(this).attr('rel') );
89 if (menu.attr('popup')=="false") return false;
91 $(this).parent().toggleClass("selected");
92 menu.slideToggle('fast');
94 if (menu.css("display") == "none") {
95 last_popup_menu = null;
96 last_popup_button = null;
98 last_popup_menu = menu;
99 last_popup_button = $(this).parent();
103 $('html').click(function(e) {
104 close_last_popup_menu(e);
108 $("a.popupbox").colorbox({
110 'transition' : 'elastic'
114 /* notifications template */
115 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
116 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
117 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
118 var notifications_empty = unescape($("#nav-notifications-menu").html());
120 /* nav update event */
121 $('nav').bind('nav-update', function(e,data){;
122 var invalid = $(data).find('invalid').text();
123 if(invalid == 1) { window.location.href=window.location.href }
125 var net = $(data).find('net').text();
126 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
127 $('#net-update').html(net);
129 var home = $(data).find('home').text();
130 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
131 $('#home-update').html(home);
133 var intro = $(data).find('intro').text();
134 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
135 $('#intro-update').html(intro);
137 var mail = $(data).find('mail').text();
138 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
139 $('#mail-update').html(mail);
141 var intro = $(data).find('intro').text();
142 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
143 $('#intro-update-li').html(intro);
145 var mail = $(data).find('mail').text();
146 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
147 $('#mail-update-li').html(mail);
149 var eNotif = $(data).find('notif')
151 if (eNotif.children("note").length==0){
152 $("#nav-notifications-menu").html(notifications_empty);
154 nnm = $("#nav-notifications-menu");
155 nnm.html(notifications_all + notifications_mark);
156 //nnm.attr('popup','true');
157 eNotif.children("note").each(function(){
159 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
160 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
164 $("img[data-src]", nnm).each(function(i, el){
165 // Add src attribute for images with a data-src attribute
166 // However, don't bother if the data-src attribute is empty, because
167 // an empty "src" tag for an image will cause some browsers
168 // to prefetch the root page of the Friendica hub, which will
169 // unnecessarily load an entire profile/ or network/ page
170 if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
173 notif = eNotif.attr('count');
175 $("#nav-notifications-linkmenu").addClass("on");
177 $("#nav-notifications-linkmenu").removeClass("on");
179 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
180 $('#notify-update').html(notif);
182 var eSysmsg = $(data).find('sysmsgs');
183 eSysmsg.children("notice").each(function(){
184 text = $(this).text();
185 $.jGrowl(text, { sticky: false, theme: 'notice', life: 3000 }); // originally: sticky: true,
187 eSysmsg.children("info").each(function(){
188 text = $(this).text();
189 $.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
196 // Allow folks to stop the ajax page updates with the pause/break key
197 $(document).keydown(function(event) {
198 if(event.keyCode == '8') {
199 var target = event.target || event.srcElement;
200 if (!/input|textarea/i.test(target.nodeName)) {
204 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
205 event.preventDefault();
206 if(stopped == false) {
211 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
225 function NavUpdate() {
228 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
229 $.get(pingCmd,function(data) {
230 $(data).find('result').each(function() {
231 // send nav-update event
232 $('nav').trigger('nav-update', this);
239 if($('#live-network').length) { src = 'network'; liveUpdate(); }
240 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
241 if($('#live-community').length) { src = 'community'; liveUpdate(); }
242 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
243 if($('#live-display').length) { src = 'display'; liveUpdate(); }
244 /*if($('#live-display').length) {
247 window.location.href=window.location.href
250 if($('#live-photos').length) {
253 window.location.href=window.location.href
263 timer = setTimeout(NavUpdate,updateInterval);
266 function liveUpdate() {
267 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $('.like-rotator').hide(); return; }
268 if(($('.comment-edit-text-full').length) || (in_progress)) {
270 clearTimeout(livetime);
272 livetime = setTimeout(liveUpdate, 5000);
278 prev = 'live-' + src;
281 var udargs = ((netargs.length) ? '/' + netargs : '');
282 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page;
284 $.get(update_url,function(data) {
286 // $('.collapsed-comments',data).each(function() {
287 // var ident = $(this).attr('id');
288 // var is_hidden = $('#' + ident).is(':hidden');
289 // if($('#' + ident).length) {
290 // $('#' + ident).replaceWith($(this));
292 // $('#' + ident).hide();
298 $('.toplevel_item',data).each(function() {
299 var ident = $(this).attr('id');
301 if($('#' + ident).length == 0 && profile_page == 1) {
302 $('img',this).each(function() {
303 $(this).attr('src',$(this).attr('dst'));
305 $('#' + prev).after($(this));
308 // Find out if the hidden comments are open, so we can keep it that way
309 // if a new comment has been posted
310 var id = $('.hide-comments-total', this).attr('id');
311 if(typeof id != 'undefined') {
312 id = id.split('-')[3];
313 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
316 $('img',this).each(function() {
317 $(this).attr('src',$(this).attr('dst'));
319 //vScroll = $(document).scrollTop();
320 $('html').height($('html').height());
321 $('#' + ident).replaceWith($(this));
323 if(typeof id != 'undefined') {
324 if(commentsOpen) showHideComments(id);
326 $('html').height('auto');
327 //$(document).scrollTop(vScroll);
330 // Add Colorbox for viewing Network page images
331 $("#" + ident + " .wall-item-body a img").each(function(){
332 var aElem = $(this).parent();
333 var imgHref = aElem.attr("href");
335 // We need to make sure we only put a Colorbox on links to Friendica images
336 // We'll try to do this by looking for links of the form
337 // .../photo/ab803d8eg08daf85023adfec08(-0.jpg) (with nothing more following), in hopes
338 // that that will be unique enough
339 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
341 // Add a unique class to all the images of a certain post, to allow scrolling through
342 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
343 $(this).addClass(cBoxClass);
356 // reset vars for inserting individual items
358 /*prev = 'live-' + src;
360 $('.wall-item-outside-wrapper',data).each(function() {
361 var ident = $(this).attr('id');
363 if($('#' + ident).length == 0 && prev != 'live-' + src) {
364 $('img',this).each(function() {
365 $(this).attr('src',$(this).attr('dst'));
367 $('#' + prev).after($(this));
370 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
371 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
372 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
373 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
374 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
375 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
376 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
377 $(this).attr('src',$(this).attr('dst'));
383 $('.like-rotator').hide();
386 $('body').css('cursor', 'auto');
388 /* autocomplete @nicknames */
389 $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl");
393 // setup videos, since VideoJS won't take care of any loaded via AJAX
394 if(typeof videojs != 'undefined') videojs.autoSetup();
398 function collapseHeight(elems) {
399 var elemName = '.wall-item-body:not(.divmore)';
400 if(typeof elems != 'undefined') {
401 elemName = elems + ' ' + elemName;
403 $(elemName).each(function() {
404 if($(this).height() > 450) {
405 $('html').height($('html').height());
406 $(this).divgrow({ initialHeight: 400, showBrackets: false, speed: 0 });
407 $(this).addClass('divmore');
408 $('html').height('auto');
413 /*function imgbright(node) {
414 $(node).removeClass("drophide").addClass("drop");
417 function imgdull(node) {
418 $(node).removeClass("drop").addClass("drophide");
421 // Since our ajax calls are asynchronous, we will give a few
422 // seconds for the first ajax call (setting like/dislike), then
423 // run the updater to pick up any changes and display on the page.
424 // The updater will turn any rotators off when it's done.
425 // This function will have returned long before any of these
426 // events have completed and therefore there won't be any
427 // visible feedback that anything changed without all this
428 // trickery. This still could cause confusion if the "like" ajax call
429 // is delayed and NavUpdate runs before it completes.
431 function dolike(ident,verb) {
433 $('#like-rotator-' + ident.toString()).show();
434 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
438 function dostar(ident) {
439 ident = ident.toString();
440 // $('#like-rotator-' + ident).show();
441 $.get('starred/' + ident, function(data) {
442 if(data.match(/1/)) {
443 $('#starred-' + ident).addClass('starred');
444 $('#starred-' + ident).removeClass('unstarred');
445 $('#star-' + ident).addClass('hidden');
446 $('#unstar-' + ident).removeClass('hidden');
449 $('#starred-' + ident).addClass('unstarred');
450 $('#starred-' + ident).removeClass('starred');
451 $('#star-' + ident).removeClass('hidden');
452 $('#unstar-' + ident).addClass('hidden');
454 // $('#like-rotator-' + ident).hide();
458 function getPosition(e) {
459 var cursor = {x:0, y:0};
460 if ( e.pageX || e.pageY ) {
465 if( e.clientX || e.clientY ) {
466 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
467 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
479 var lockvisible = false;
481 function lockview(event,id) {
482 event = event || window.event;
483 cursor = getPosition(event);
489 $.get('lockview/' + id, function(data) {
490 $('#panel').html(data);
491 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
497 function lockviewhide() {
502 function post_comment(id) {
505 $('body').css('cursor', 'wait');
506 $("#comment-preview-inp-" + id).val("0");
509 $("#comment-edit-form-" + id).serialize(),
512 $("#comment-edit-wrapper-" + id).hide();
513 $("#comment-edit-text-" + id).val('');
514 var tarea = document.getElementById("comment-edit-text-" + id);
516 commentClose(tarea,id);
517 if(timer) clearTimeout(timer);
518 timer = setTimeout(NavUpdate,10);
521 window.location.href=data.reload;
530 function preview_comment(id) {
531 $("#comment-preview-inp-" + id).val("1");
532 $("#comment-edit-preview-" + id).show();
535 $("#comment-edit-form-" + id).serialize(),
539 $("#comment-edit-preview-" + id).html(data.preview);
540 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
549 function showHideComments(id) {
550 if( $("#collapsed-comments-" + id).is(":visible")) {
551 $("#collapsed-comments-" + id).hide();
552 $("#hide-comments-" + id).html(window.showMore);
555 $("#collapsed-comments-" + id).show();
556 $("#hide-comments-" + id).html(window.showFewer);
557 collapseHeight("#collapsed-comments-" + id);
562 function preview_post() {
563 $("#jot-preview").val("1");
564 $("#jot-preview-content").show();
567 $("#profile-jot-form").serialize(),
570 $("#jot-preview-content").html(data.preview);
571 $("#jot-preview-content" + " a").click(function() { return false; });
576 $("#jot-preview").val("0");
582 // unpause auto reloads if they are currently stopped
585 $('#pause').html('');
590 // Converts the binary representation of data to hex
593 // discuss at: http://phpjs.org/functions/bin2hex
594 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
595 // + bugfixed by: Onno Marsman
596 // + bugfixed by: Linuxworld
597 // * example 1: bin2hex('Kev');
598 // * returns 1: '4b6576'
599 // * example 2: bin2hex(String.fromCharCode(0x00));
601 var v,i, f = 0, a = [];
605 for (i = 0; i<f; i++) {
606 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
612 function groupChangeMember(gid, cid, sec_token) {
613 $('body .fakelink').css('cursor', 'wait');
614 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
615 $('#group-update-wrapper').html(data);
616 $('body .fakelink').css('cursor', 'auto');
620 function profChangeMember(gid,cid) {
621 $('body .fakelink').css('cursor', 'wait');
622 $.get('profperm/' + gid + '/' + cid, function(data) {
623 $('#prof-update-wrapper').html(data);
624 $('body .fakelink').css('cursor', 'auto');
628 function contactgroupChangeMember(gid,cid) {
629 $('body').css('cursor', 'wait');
630 $.get('contactgroup/' + gid + '/' + cid, function(data) {
631 $('body').css('cursor', 'auto');
636 function checkboxhighlight(box) {
637 if($(box).is(':checked')) {
638 $(box).addClass('checkeditem');
641 $(box).removeClass('checkeditem');
645 function notifyMarkAll() {
646 $.get('notify/mark/all', function(data) {
647 if(timer) clearTimeout(timer);
648 timer = setTimeout(NavUpdate,1000);
653 * sprintf in javascript
654 * "{0} and {1}".format('zero','uno');
656 String.prototype.format = function() {
657 var formatted = this;
658 for (var i = 0; i < arguments.length; i++) {
659 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
660 formatted = formatted.replace(regexp, arguments[i]);
665 Array.prototype.remove = function(item) {
666 to=undefined; from=this.indexOf(item);
667 var rest = this.slice((to || from) + 1 || this.length);
668 this.length = from < 0 ? this.length + from : from;
669 return this.push.apply(this, rest);
672 function previewTheme(elm) {
673 theme = $(elm).val();
674 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
675 $('#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>');