1 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
3 // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
4 if (!Element.prototype.matches) {
5 Element.prototype.matches =
6 Element.prototype.matchesSelector ||
7 Element.prototype.mozMatchesSelector ||
8 Element.prototype.msMatchesSelector ||
9 Element.prototype.oMatchesSelector ||
10 Element.prototype.webkitMatchesSelector ||
12 var matches = (this.document || this.ownerDocument).querySelectorAll(s),
14 while (--i >= 0 && matches.item(i) !== this) {}
19 function resizeIframe(obj) {
20 _resizeIframe(obj, 0);
23 function _resizeIframe(obj, desth) {
24 var h = obj.style.height;
25 var ch = obj.contentWindow.document.body.scrollHeight;
27 if (h == (ch + 'px')) {
30 if (desth == ch && ch > 0) {
31 obj.style.height = ch + 'px';
33 setTimeout(_resizeIframe, 100, obj, ch);
36 function initWidget(inflated, deflated) {
37 var elInf = document.getElementById(inflated);
38 var elDef = document.getElementById(deflated);
40 if (!elInf || !elDef) {
43 if (localStorage.getItem(window.location.pathname.split("/")[1] + ":" + inflated) != "none") {
44 elInf.style.display = "block";
45 elDef.style.display = "none";
47 elInf.style.display = "none";
48 elDef.style.display = "block";
52 function openCloseWidget(inflated, deflated) {
53 var elInf = document.getElementById(inflated);
54 var elDef = document.getElementById(deflated);
56 if (!elInf || !elDef) {
60 if (window.getComputedStyle(elInf).display === "none") {
61 elInf.style.display = "block";
62 elDef.style.display = "none";
63 localStorage.setItem(window.location.pathname.split("/")[1] + ":" + inflated, "block");
65 elInf.style.display = "none";
66 elDef.style.display = "block";
67 localStorage.setItem(window.location.pathname.split("/")[1] + ":" + inflated, "none");
71 function openClose(theID) {
72 var el = document.getElementById(theID);
74 if (window.getComputedStyle(el).display === "none") {
82 function openMenu(theID) {
83 var el = document.getElementById(theID);
85 if (!el.dataset.display) {
86 el.dataset.display = 'block';
88 el.style.display = el.dataset.display;
92 function closeMenu(theID) {
93 var el = document.getElementById(theID);
95 el.dataset.display = window.getComputedStyle(el).display;
96 el.style.display = "none";
100 function decodeHtml(html) {
101 var txt = document.createElement("textarea");
103 txt.innerHTML = html;
108 * Retrieves a single named query string parameter
110 * @param {string} name
112 * @see https://davidwalsh.name/query-string-javascript
114 function getUrlParameter(name) {
115 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
116 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
117 var results = regex.exec(location.search);
118 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
124 var force_update = false;
127 var totStopped = false;
131 var in_progress = false;
132 var langSelect = false;
133 var commentBusy = false;
134 var last_popup_menu = null;
135 var last_popup_button = null;
136 var lockLoadContent = false;
138 const urlRegex = /^(?:https?:\/\/|\s)[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})(?:\/+[a-z0-9_.:;-]*)*(?:\?[&%|+a-z0-9_=,.:;-]*)?(?:[&%|+&a-z0-9_=,:;.-]*)(?:[!#\/&%|+a-z0-9_=,:;.-]*)}*$/i;
141 $.ajaxSetup({cache: false});
143 /* setup comment textarea buttons */
144 /* comment textarea buttons needs some "data-*" attributes to work:
145 * data-role="insert-formatting" : to mark the element as a formatting button
146 * data-bbcode="<string>" : name of the bbcode element to insert. insertFormatting() will insert it as "[name][/name]"
147 * data-id="<string>" : id of the comment, used to find other comment-related element, like the textarea
149 $('body').on('click','[data-role="insert-formatting"]', function(e) {
152 var bbcode = o.data('bbcode');
153 var id = o.data('id');
154 if (bbcode == "img") {
155 Dialog.doImageBrowser("comment", id);
159 if (bbcode == "imgprv") {
163 insertFormatting(bbcode, id);
166 /* event from comment textarea button popups */
167 /* insert returned bbcode at cursor position or replace selected text */
168 $("body").on("fbrowser.image.comment", function(e, filename, bbcode, id) {
170 var textarea = document.getElementById("comment-edit-text-" +id);
171 var start = textarea.selectionStart;
172 var end = textarea.selectionEnd;
173 textarea.value = textarea.value.substring(0, start) + bbcode + textarea.value.substring(end, textarea.value.length);
174 $(textarea).trigger('change');
178 function close_last_popup_menu() {
179 if (last_popup_menu) {
180 last_popup_menu.hide();
181 last_popup_menu.off('click', function(e) {e.stopPropagation()});
182 last_popup_button.removeClass("selected");
183 last_popup_menu = null;
184 last_popup_button = null;
187 $('a[rel^="#"]').click(function(e) {
189 var parent = $(this).parent();
190 var isSelected = (last_popup_button && parent.attr('id') == last_popup_button.attr('id'));
191 close_last_popup_menu();
195 menu = $($(this).attr('rel'));
198 if (menu.attr('popup') == "false") {
201 parent.toggleClass("selected");
203 if (menu.css("display") == "none") {
204 last_popup_menu = null;
205 last_popup_button = null;
207 last_popup_menu = menu;
208 last_popup_menu.on('click', function(e) {e.stopPropagation()});
209 last_popup_button = parent;
210 $('#nav-notifications-menu').perfectScrollbar('update');
214 $('html').click(function() {
215 close_last_popup_menu();
219 $("a.popupbox").colorbox({
221 'transition' : 'elastic',
224 $("a.ajax-popupbox").colorbox({
225 'transition' : 'elastic',
229 /* notifications template */
230 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
231 var notifications_all = unescape($('<div>').append($("#nav-notifications-see-all").clone()).html()); //outerHtml hack
232 var notifications_mark = unescape($('<div>').append($("#nav-notifications-mark-all").clone()).html()); //outerHtml hack
233 var notifications_empty = unescape($("#nav-notifications-menu").html());
235 /* enable perfect-scrollbars for different elements */
236 $('#nav-notifications-menu, aside').perfectScrollbar();
238 /* nav update event */
239 $('nav').bind('nav-update', function(e, data) {
240 var invalid = data.invalid || 0;
242 window.location.href=window.location.href
245 ['net', 'home', 'intro', 'mail', 'events', 'birthdays', 'notification'].forEach(function(type) {
246 var number = data[type];
249 $('#' + type + '-update').removeClass('show');
251 $('#' + type + '-update').addClass('show');
253 $('#' + type + '-update').text(number);
256 var intro = data['intro'];
258 intro = ''; $('#intro-update-li').removeClass('show')
260 $('#intro-update-li').addClass('show')
263 $('#intro-update-li').html(intro);
265 var mail = data['mail'];
267 mail = ''; $('#mail-update-li').removeClass('show')
269 $('#mail-update-li').addClass('show')
272 $('#mail-update-li').html(mail);
274 $(".sidebar-group-li .notify").removeClass("show");
275 $(data.groups).each(function(key, group) {
277 var gcount = group.count;
278 $(".group-"+gid+" .notify").addClass("show").text(gcount);
281 $(".forum-widget-entry .notify").removeClass("show");
282 $(data.forums).each(function(key, forum) {
284 var fcount = forum.count;
285 $(".forum-"+fid+" .notify").addClass("show").text(fcount);
288 if (data.notifications.length == 0) {
289 $("#nav-notifications-menu").html(notifications_empty);
291 var nnm = $("#nav-notifications-menu");
292 nnm.html(notifications_all + notifications_mark);
294 var lastItemStorageKey = "notification-lastitem:" + localUser;
295 var notification_lastitem = parseInt(localStorage.getItem(lastItemStorageKey));
296 var notification_id = 0;
298 // Insert notifs into the notifications-menu
299 $(data.notifications).each(function(key, notification) {
300 var text = notification.message.format('<span class="contactname">' + notification.name + '</span>');
301 var contact = ('<a href="' + notification.url + '"><span class="contactname">' + notification.name + '</span></a>');
302 var seenclass = (notification.seen == 1) ? "notification-seen" : "notification-unseen";
303 var html = notifications_tpl.format(
304 notification.href, // {0} // link to the source
305 notification.photo, // {1} // photo of the contact
306 text, // {2} // preformatted text (autor + text)
307 notification.date, // {3} // date of notification (time ago)
308 seenclass, // {4} // visited status of the notification
309 new Date(notification.timestamp*1000), // {5} // date of notification
310 notification.url, // {6} // profile url of the contact
311 notification.message.format(contact), // {7} // preformatted html (text including author profile url)
312 '' // {8} // Deprecated
317 // Desktop Notifications
318 $(data.notifications.reverse()).each(function(key, e) {
319 notification_id = parseInt(e.timestamp);
320 if (notification_lastitem !== null && notification_id > notification_lastitem && Number(e.seen) === 0) {
321 if (getNotificationPermission() === "granted") {
322 var notification = new Notification(document.title, {
323 body: decodeHtml(e.message.replace('→ ', '').format(e.name)),
326 notification['url'] = e.href;
327 notification.addEventListener("click", function(ev) {
328 window.location = ev.target.url;
334 notification_lastitem = notification_id;
335 localStorage.setItem(lastItemStorageKey, notification_lastitem)
337 $("img[data-src]", nnm).each(function(i, el) {
338 // Add src attribute for images with a data-src attribute
339 // However, don't bother if the data-src attribute is empty, because
340 // an empty "src" tag for an image will cause some browsers
341 // to prefetch the root page of the Friendica hub, which will
342 // unnecessarily load an entire profile/ or network/ page
343 if ($(el).data("src") != '') {
344 $(el).attr('src', $(el).data("src"));
349 var notif = data['notification'];
351 $("#nav-notifications-linkmenu").addClass("on");
353 $("#nav-notifications-linkmenu").removeClass("on");
356 $(data.sysmsgs.notice).each(function(key, message) {
357 $.jGrowl(message, {sticky: true, theme: 'notice'});
359 $(data.sysmsgs.info).each(function(key, message) {
360 $.jGrowl(message, {sticky: false, theme: 'info', life: 5000});
363 // Update the js scrollbars
364 $('#nav-notifications-menu').perfectScrollbar('update');
367 // Asynchronous calls are deferred until the very end of the page load to ease on slower connections
368 window.addEventListener("load", function(){
370 if (typeof acl !== 'undefined') {
375 // Allow folks to stop the ajax page updates with the pause/break key
376 $(document).keydown(function(event) {
377 if (event.keyCode == '8') {
378 var target = event.target || event.srcElement;
379 if (!/input|textarea/i.test(target.nodeName)) {
384 if (event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
385 event.preventDefault();
386 if (stopped == false) {
391 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
395 } else if (!totStopped) {
400 // Scroll to the next/previous thread when pressing J and K
401 $(document).keydown(function (event) {
402 var threads = $('.thread_level_1');
403 if ((event.keyCode === 74 || event.keyCode === 75) && !$(event.target).is('textarea, input')) {
404 var scrollTop = $(window).scrollTop();
405 if (event.keyCode === 75) {
406 threads = $(threads.get().reverse());
408 threads.each(function(key, item) {
410 var top = $(item).offset().top - 100;
411 if (event.keyCode === 74) {
412 comparison = top > scrollTop + 1;
413 } else if (event.keyCode === 75) {
414 comparison = top < scrollTop - 1;
417 $('html, body').animate({scrollTop: top}, 200);
424 // Set an event listener for infinite scroll
425 if (typeof infinite_scroll !== 'undefined') {
426 $(window).scroll(function(e) {
427 if ($(document).height() != $(window).height()) {
428 // First method that is expected to work - but has problems with Chrome
429 if ($(window).scrollTop() > ($(document).height() - $(window).height() * 1.5))
432 // This method works with Chrome - but seems to be much slower in Firefox
433 if ($(window).scrollTop() > (($("section").height() + $("header").height() + $("footer").height()) - $(window).height() * 1.5)) {
442 * Inserts a BBCode tag in the comment textarea identified by id
444 * @param {string} BBCode
448 function insertFormatting(BBCode, id) {
449 let textarea = document.getElementById('comment-edit-text-' + id);
451 if (textarea.value === '') {
453 .addClass("comment-edit-text-full")
454 .removeClass("comment-edit-text-empty");
455 closeMenu("comment-fake-form-" + id);
456 openMenu("item-comments-" + id);
459 insertBBCodeInTextarea(BBCode, textarea);
465 * Inserts a BBCode tag in the provided textarea element, wrapping the currently selected text.
466 * For URL BBCode, it discriminates between link text and non-link text to determine where to insert the selected text.
468 * @param {string} BBCode
469 * @param {HTMLTextAreaElement} textarea
471 function insertBBCodeInTextarea(BBCode, textarea) {
472 let selectionStart = textarea.selectionStart;
473 let selectionEnd = textarea.selectionEnd;
474 let selectedText = textarea.value.substring(selectionStart, selectionEnd);
475 let openingTag = '[' + BBCode + ']';
476 let closingTag = '[/' + BBCode + ']';
477 let cursorPosition = selectionStart + openingTag.length + selectedText.length;
479 if (BBCode === 'url') {
480 if (urlRegex.test(selectedText)) {
481 openingTag = '[' + BBCode + '=' + selectedText + ']';
483 cursorPosition = selectionStart + openingTag.length;
485 openingTag = '[' + BBCode + '=]';
486 cursorPosition = selectionStart + openingTag.length - 1;
490 textarea.value = textarea.value.substring(0, selectionStart) + openingTag + selectedText + closingTag + textarea.value.substring(selectionEnd, textarea.value.length);
491 textarea.setSelectionRange(cursorPosition, cursorPosition);
492 textarea.dispatchEvent(new Event('change'));
496 function NavUpdate() {
498 var pingCmd = 'ping?format=json' + ((localUser != 0) ? '&uid=' + localUser : '');
499 $.get(pingCmd, function(data) {
501 // send nav-update event
502 $('nav').trigger('nav-update', data.result);
505 ['network', 'profile', 'community', 'notes', 'display', 'contact'].forEach(function (src) {
506 if ($('#live-' + src).length) {
510 if ($('#live-photos').length) {
513 window.location.href = window.location.href;
519 timer = setTimeout(NavUpdate, updateInterval);
522 function updateConvItems(data) {
524 $('.toplevel_item',data).each(function() {
525 var ident = $(this).attr('id');
527 // Add new top-level item.
528 if ($('#' + ident).length === 0
529 && (!getUrlParameter('page')
530 && !getUrlParameter('max_id')
531 && !getUrlParameter('since_id')
532 || getUrlParameter('page') === '1'
535 $('#' + prev).after($(this));
537 // Replace already existing thread.
539 // Find out if the hidden comments are open, so we can keep it that way
540 // if a new comment has been posted
541 var id = $('.hide-comments-total', this).attr('id');
542 if (typeof id != 'undefined') {
543 id = id.split('-')[3];
544 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
547 $('#' + ident).replaceWith($(this));
549 if (typeof id != 'undefined') {
551 showHideComments(id);
558 $('.like-rotator').hide();
561 $('body').css('cursor', 'auto');
563 /* autocomplete @nicknames */
564 $(".comment-edit-form textarea").editor_autocomplete(baseurl + '/search/acl');
565 /* autocomplete bbcode */
566 $(".comment-edit-form textarea").bbco_autocomplete('bbcode');
569 function liveUpdate(src) {
570 if ((src == null) || stopped || !profile_uid) {
571 $('.like-rotator').hide(); return;
574 if (($('.comment-edit-text-full').length) || in_progress) {
576 clearTimeout(livetime);
578 livetime = setTimeout(function() {liveUpdate(src)}, 5000);
582 if (livetime != null) {
585 prev = 'live-' + src;
589 if ($(document).scrollTop() == 0) {
593 var orgHeight = $("section").height();
595 var udargs = ((netargs.length) ? '/' + netargs : '');
597 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&force=' + ((force_update) ? 1 : 0) + '&item=' + update_item;
599 if (getUrlParameter('page')) {
600 update_url += '&page=' + getUrlParameter('page');
602 if (getUrlParameter('since_id')) {
603 update_url += '&since_id=' + getUrlParameter('since_id');
605 if (getUrlParameter('max_id')) {
606 update_url += '&max_id=' + getUrlParameter('max_id');
609 $.get(update_url,function(data) {
611 force_update = false;
614 $('.wall-item-body', data).imagesLoaded(function() {
615 updateConvItems(data);
617 document.dispatchEvent(new Event('postprocess_liveupdate'));
619 // Update the scroll position.
620 $(window).scrollTop($(window).scrollTop() + $("section").height() - orgHeight);
625 function imgbright(node) {
626 $(node).removeClass("drophide").addClass("drop");
629 function imgdull(node) {
630 $(node).removeClass("drop").addClass("drophide");
633 // Since our ajax calls are asynchronous, we will give a few
634 // seconds for the first ajax call (setting like/dislike), then
635 // run the updater to pick up any changes and display on the page.
636 // The updater will turn any rotators off when it's done.
637 // This function will have returned long before any of these
638 // events have completed and therefore there won't be any
639 // visible feedback that anything changed without all this
640 // trickery. This still could cause confusion if the "like" ajax call
641 // is delayed and NavUpdate runs before it completes.
643 function dolike(ident,verb) {
645 $('#like-rotator-' + ident.toString()).show();
646 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate);
649 update_item = ident.toString();
652 function dosubthread(ident) {
654 $('#like-rotator-' + ident.toString()).show();
655 $.get('subthread/' + ident.toString(), NavUpdate);
659 function dostar(ident) {
660 ident = ident.toString();
661 $('#like-rotator-' + ident).show();
662 $.get('starred/' + ident, function(data) {
663 if (data.match(/1/)) {
664 $('#starred-' + ident).addClass('starred');
665 $('#starred-' + ident).removeClass('unstarred');
666 $('#star-' + ident).addClass('hidden');
667 $('#unstar-' + ident).removeClass('hidden');
669 $('#starred-' + ident).addClass('unstarred');
670 $('#starred-' + ident).removeClass('starred');
671 $('#star-' + ident).removeClass('hidden');
672 $('#unstar-' + ident).addClass('hidden');
674 $('#like-rotator-' + ident).hide();
678 function dopin(ident) {
679 ident = ident.toString();
680 $('#like-rotator-' + ident).show();
681 $.get('pinned/' + ident, function(data) {
682 if (data.match(/1/)) {
683 $('#pinned-' + ident).addClass('pinned');
684 $('#pinned-' + ident).removeClass('unpinned');
685 $('#pin-' + ident).addClass('hidden');
686 $('#unpin-' + ident).removeClass('hidden');
688 $('#pinned-' + ident).addClass('unpinned');
689 $('#pinned-' + ident).removeClass('pinned');
690 $('#pin-' + ident).removeClass('hidden');
691 $('#unpin-' + ident).addClass('hidden');
693 $('#like-rotator-' + ident).hide();
697 function doignore(ident) {
698 ident = ident.toString();
699 $('#like-rotator-' + ident).show();
700 $.get('item/ignore/' + ident, function(data) {
702 $('#ignored-' + ident)
704 .removeClass('unignored');
705 $('#ignore-' + ident).addClass('hidden');
706 $('#unignore-' + ident).removeClass('hidden');
708 $('#ignored-' + ident)
709 .addClass('unignored')
710 .removeClass('ignored');
711 $('#ignore-' + ident).removeClass('hidden');
712 $('#unignore-' + ident).addClass('hidden');
714 $('#like-rotator-' + ident).hide();
718 function getPosition(e) {
719 var cursor = {x:0, y:0};
721 if (e.pageX || e.pageY) {
725 if (e.clientX || e.clientY) {
726 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
727 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
728 } else if (e.x || e.y) {
736 var lockvisible = false;
738 function lockview(event,id) {
739 event = event || window.event;
740 cursor = getPosition(event);
745 $.get('lockview/' + id, function(data) {
746 $('#panel').html(data);
747 $('#panel').css({'left': cursor.x + 5 , 'top': cursor.y + 5});
753 function lockviewhide() {
758 function post_comment(id) {
761 $('body').css('cursor', 'wait');
764 $("#comment-edit-form-" + id).serialize(),
767 $("#comment-edit-wrapper-" + id).hide();
768 $("#comment-edit-text-" + id).val('');
769 var tarea = document.getElementById("comment-edit-text-" + id);
771 commentClose(tarea,id);
776 timer = setTimeout(NavUpdate,10);
781 window.location.href=data.reload;
789 function preview_comment(id) {
790 $("#comment-edit-preview-" + id).show();
793 $("#comment-edit-form-" + id).serialize() + '&preview=1',
796 $("#comment-edit-preview-" + id).html(data.preview);
797 $("#comment-edit-preview-" + id + " a").click(function() {return false;});
805 function showHideComments(id) {
806 if ($('#collapsed-comments-' + id).is(':visible')) {
807 $('#collapsed-comments-' + id).slideUp();
808 $('#hide-comments-' + id).hide();
809 $('#hide-comments-total-' + id).show();
811 $('#collapsed-comments-' + id).slideDown();
812 $('#hide-comments-' + id).show();
813 $('#hide-comments-total-' + id).hide();
817 function preview_post() {
818 $("#jot-preview-content").show();
821 $("#profile-jot-form").serialize() + '&preview=1',
824 $("#jot-preview-content").html(data.preview);
825 $("#jot-preview-content" + " a").click(function() {return false;});
826 document.dispatchEvent(new Event('postprocess_liveupdate'));
835 // unpause auto reloads if they are currently stopped
838 $('#pause').html('');
841 // load more network content (used for infinite scroll)
842 function loadScrollContent() {
843 if (lockLoadContent) {
846 lockLoadContent = true;
848 $("#scroll-loader").fadeIn('normal');
850 // the page number to load is one higher than the actual
852 infinite_scroll.pageno+=1;
854 match = $("span.received").last();
855 if (match.length > 0) {
856 received = match[0].innerHTML;
858 received = "0000-00-00 00:00:00";
861 match = $("span.created").last();
862 if (match.length > 0) {
863 created = match[0].innerHTML;
865 created = "0000-00-00 00:00:00";
868 match = $("span.commented").last();
869 if (match.length > 0) {
870 commented = match[0].innerHTML;
872 commented = "0000-00-00 00:00:00";
875 match = $("span.id").last();
876 if (match.length > 0) {
877 id = match[0].innerHTML;
882 // get the raw content from the next page and insert this content
883 // right before "#conversation-end"
884 $.get(infinite_scroll.reload_uri + '&mode=raw&last_received=' + received + '&last_commented=' + commented + '&last_created=' + created + '&last_id=' + id + '&page=' + infinite_scroll.pageno, function(data) {
885 $("#scroll-loader").hide();
886 if ($(data).length > 0) {
887 $(data).insertBefore('#conversation-end');
888 lockLoadContent = false;
890 $("#scroll-end").fadeIn('normal');
893 document.dispatchEvent(new Event('postprocess_liveupdate'));
897 function bin2hex(s) {
898 // Converts the binary representation of data to hex
901 // discuss at: http://phpjs.org/functions/bin2hex
902 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
903 // + bugfixed by: Onno Marsman
904 // + bugfixed by: Linuxworld
905 // * example 1: bin2hex('Kev');
906 // * returns 1: '4b6576'
907 // * example 2: bin2hex(String.fromCharCode(0x00));
909 var v,i, f = 0, a = [];
913 for (i = 0; i<f; i++) {
914 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
920 function groupChangeMember(gid, cid, sec_token) {
921 $('body .fakelink').css('cursor', 'wait');
922 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
923 $('#group-update-wrapper').html(data);
924 $('body .fakelink').css('cursor', 'auto');
928 function profChangeMember(gid,cid) {
929 $('body .fakelink').css('cursor', 'wait');
930 $.get('profperm/' + gid + '/' + cid, function(data) {
931 $('#prof-update-wrapper').html(data);
932 $('body .fakelink').css('cursor', 'auto');
936 function contactgroupChangeMember(checkbox, gid, cid) {
938 // checkbox.checked is the checkbox state after the click
939 if (checkbox.checked) {
940 url = 'group/' + gid + '/add/' + cid;
942 url = 'group/' + gid + '/remove/' + cid;
944 $('body').css('cursor', 'wait');
947 // Restores previous state in case of error
948 checkbox.checked = !checkbox.checked;
951 $('body').css('cursor', 'auto');
957 function checkboxhighlight(box) {
958 if ($(box).is(':checked')) {
959 $(box).addClass('checkeditem');
961 $(box).removeClass('checkeditem');
965 function notificationMarkAll() {
966 $.get('notification/mark/all', function(data) {
970 timer = setTimeout(NavUpdate,1000);
976 * sprintf in javascript
977 * "{0} and {1}".format('zero','uno');
979 String.prototype.format = function() {
980 var formatted = this;
981 for (var i = 0; i < arguments.length; i++) {
982 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
983 formatted = formatted.replace(regexp, arguments[i]);
988 Array.prototype.remove = function(item) {
989 to=undefined; from=this.indexOf(item);
990 var rest = this.slice((to || from) + 1 || this.length);
991 this.length = from < 0 ? this.length + from : from;
992 return this.push.apply(this, rest);
995 function previewTheme(elm) {
996 theme = $(elm).val();
997 $.getJSON('pretheme?theme=' + theme,function(data) {
998 $('#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>');
1003 // notification permission settings in localstorage
1004 // set by settings page
1005 function getNotificationPermission() {
1006 if (window["Notification"] === undefined) {
1010 if (Notification.permission === 'granted') {
1011 var val = localStorage.getItem('notification-permissions');
1017 return Notification.permission;
1022 * Show a dialog loaded from an url
1023 * By defaults this load the url in an iframe in colorbox
1024 * Themes can overwrite `show()` function to personalize it
1031 * @return object colorbox
1033 show : function (url) {
1034 var size = Dialog._get_size();
1035 return $.colorbox({href: url, iframe:true,innerWidth: size.width+'px',innerHeight: size.height+'px'})
1039 * Show the Image browser dialog
1041 * @param string name
1042 * @param string id (optional)
1045 * The name will be used to build the event name
1046 * fired by image browser dialog when the user select
1047 * an image. The optional id will be passed as argument
1048 * to the event handler
1050 doImageBrowser : function (name, id) {
1051 var url = Dialog._get_url("image",name,id);
1052 return Dialog.show(url);
1056 * Show the File browser dialog
1058 * @param string name
1059 * @param string id (optional)
1062 * The name will be used to build the event name
1063 * fired by file browser dialog when the user select
1064 * a file. The optional id will be passed as argument
1065 * to the event handler
1067 doFileBrowser : function (name, id) {
1068 var url = Dialog._get_url("file",name,id);
1069 return Dialog.show(url);
1072 _get_url : function(type, name, id) {
1074 if (id !== undefined) {
1075 hash = hash + "-" + id;
1077 return baseurl + "/fbrowser/"+type+"/?mode=minimal#"+hash;
1080 _get_size: function() {
1082 width: window.innerWidth-50,
1083 height: window.innerHeight-100