diff options
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/autocomplete.js | 16 | ||||
-rw-r--r-- | view/js/main.js | 707 | ||||
-rw-r--r-- | view/js/mod_cloud.js | 119 | ||||
-rw-r--r-- | view/js/mod_connections.js | 2 | ||||
-rw-r--r-- | view/js/mod_hq.js | 21 | ||||
-rw-r--r-- | view/js/mod_import_progress.js | 54 | ||||
-rw-r--r-- | view/js/mod_mail.js | 7 | ||||
-rw-r--r-- | view/js/mod_photos.js | 294 | ||||
-rw-r--r-- | view/js/mod_register.js | 2 | ||||
-rw-r--r-- | view/js/mod_settings.js | 8 |
10 files changed, 473 insertions, 757 deletions
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index c45c47518..d6893073d 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -163,7 +163,16 @@ function string2bb(element) { // Autocomplete contacts contacts = { - match: /(^|\s)(@\!*)([^ \n]{3,})$/, + match: /(^|\s)(@\!)([^ \n]{3,})$/, + index: 3, + cache: true, + search: function(term, callback) { contact_search(term, callback, backend_url, 'm', extra_channels, spinelement=false); }, + replace: editor_replace, + template: contact_format + }; + + channels = { + match: /(^(?=[^\!]{2})|\s)(@)([^ \n]{3,})$/, index: 3, cache: true, search: function(term, callback) { contact_search(term, callback, backend_url, 'c', extra_channels, spinelement=false); }, @@ -202,7 +211,8 @@ function string2bb(element) { maxCount: 100 } }); - textcomplete.register([contacts,smilies,tags]); + // it seems important that contacts are before channels here. Otherwise we run into regex issues. + textcomplete.register([contacts,channels,smilies,tags]); }); }; })( jQuery ); @@ -350,7 +360,7 @@ function string2bb(element) { return; if(type=='bbcode') { - var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'superscript', 'subscript', 'quote', 'code', 'open', 'spoiler', 'map', 'nobb', 'list', 'checklist', 'question', 'answer', 'ul', 'ol', 'dl', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'zrl', 'zmg', 'rpost', 'qr', 'observer', 'observer.language','embed', 'highlight', 'url', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; + var open_close_elements = ['bold', 'italic', 'underline', 'overline', 'strike', 'superscript', 'subscript', 'quote', 'code', 'open', 'spoiler', 'map', 'nobb', 'list', 'checklist', 'question', 'answer', 'ul', 'ol', 'dl', 'li', 'table', 'tr', 'th', 'td', 'center', 'color', 'font', 'size', 'zrl', 'zmg', 'rpost', 'qr', 'observer', 'observer.language','embed', 'mark', 'url', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; var open_elements = ['observer.baseurl', 'observer.address', 'observer.photo', 'observer.name', 'observer.webname', 'observer.url', '*', 'hr' ]; var elements = open_close_elements.concat(open_elements); diff --git a/view/js/main.js b/view/js/main.js index 6c418b213..f7709f9d1 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -26,13 +26,6 @@ var followUpPageLoad = false; var window_needs_alert = true; var expanded_items = []; -var sse_bs_active = false; -var sse_offset = 0; -var sse_type; -var sse_partial_result = false; -var sse_rmids = []; -var sse_fallback_interval; - var page_cache = {}; // take care of tab/window reloads on channel change @@ -41,6 +34,7 @@ if(localStorage.getItem('uid') !== localUser.toString()) { sessionStorage.clear(); localStorage.setItem('uid', localUser.toString()); } + window.onstorage = function(e) { if(e.key === 'uid' && parseInt(e.newValue) !== localUser) { if(window_needs_alert) { @@ -52,6 +46,14 @@ window.onstorage = function(e) { } } +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/ServiceWorker.js', { scope: '/' }).then(function(registration) { + console.log('Service worker registered. scope is', registration.scope); + }).catch(function(error) { + console.log('Service worker registration failed because ' + error); + }); +} + $.ajaxSetup({cache: false}); $(document).ready(function() { @@ -78,6 +80,65 @@ $(document).ready(function() { } }); + // @hilmar |-> + if ( typeof(window.tao) == 'undefined' ) { + window.tao = {}; + } + if ( typeof(window.tao.zin) == 'undefined' ) { + tao.zin = { syslc: '', syslcs: {}, htm: '', me: '', debug: '' }; + tao.zin.axim = '<div class="zinpax fa fa-sync fa-spin"> </div>'; + $('.navbar-app[href*="/lang"]').attr({"aria-expand": "true", "id": "zintog"}) + .removeAttr('href').addClass('zinlcx zinlcxp dropdown dropdown-toggle').css('cursor','pointer'); + $('.dropdown-item[href*="/lang"]').addClass('zinlcxmi zinlcx').removeAttr('href').css('cursor','pointer'); + } + $('.zinlcx').on('click', function(e) { + if (tao.zin.syslc == '') { + $('.zinlcx').append(tao.zin.axim); + $.ajax({ + type: 'POST', url: 'lang', + data: { zinlc: '??' } + }).done( function(re) { + tao.zin.re = JSON.parse(re); + tao.zin.syslc = tao.zin.re.lc; + tao.zin.syslcs = tao.zin.re.lcs; + tao.zin.htm = '<ul class="zinlcs fa-ul">'; + $.each( tao.zin.syslcs, function( k, v ) { + tao.zin.htm += '<li><a id="zinlc' + k + '" class="zinlc dropdown-item fakelink">' + k + ' ' + v + '</a></li>'; + }); + tao.zin.htm += '</ul>'; + $('.zinpax').remove(); + $('.zinlcx').append(tao.zin.htm); + $('.zinlcxp > ul').addClass('dropdown dropdown-menu dropdown-menu-end mt-2 show').css('right', 0); + }); + return false; + } else { + if (e.target.id == '' || e.target.id == 'zintog') { + // noop click on lang again + return false; + } + tao.zin.me = e.target.id.substr(5); + $('#right_aside_wrapper').append(tao.zin.axim); + $.ajax({ + type: 'POST', url: 'lang', + data: { zinlc: tao.zin.me } + }).done( function(re) { + tao.zin.re = JSON.parse(re); + location.reload(true); + }); + } + }); + $('#zintog').on('click', function() { + $('.zinlcs').toggle(); + }); + $('#dropdown-menu').on('shown.bs.dropdown', function() { + tao.zin.debug += 'e,'; + //$('.zinlcs').removeAttr('display'); + }) + .on('mouseleave', function() { + $(this).trigger('click'); + }); + // @hilmar <-| + var tf = new Function('n', 's', 'var k = s.split("/")['+aStr['plural_func']+']; return (k ? k : s);'); jQuery.timeago.settings.strings = { @@ -102,110 +163,63 @@ $(document).ready(function() { jQuery.timeago.settings.allowFuture = true; - if(sse_enabled) { - if(typeof(window.SharedWorker) === 'undefined') { - // notifications with multiple tabs open will not work very well in this scenario - var evtSource = new EventSource('/sse'); - - evtSource.addEventListener('notifications', function(e) { - var obj = JSON.parse(e.data); - sse_handleNotifications(obj, false, false); - }, false); + $(document).on('click', '.notification, .message', function(e) { + let b64mid = $(this).data('b64mid'); + let notify_id = $(this).data('notify_id'); + let path = $(this)[0].pathname.split('/')[1]; + let stateObj = { b64mid: b64mid }; + let singlethread_modules = ['display', 'hq']; + let redirect_modules = ['display', 'notify']; - document.addEventListener('visibilitychange', function() { - if (!document.hidden) { - sse_offset = 0; - sse_bs_init(); - } - }, false); + if(! b64mid && ! notify_id) + return; + if(localUser && redirect_modules.indexOf(path) !== -1) { + path = 'hq'; } - else { - var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser); - - myWorker.port.onmessage = function(e) { - obj = e.data; - console.log(obj); - sse_handleNotifications(obj, false, false); - } - myWorker.onerror = function(e) { - myWorker.port.close(); - } + if(notify_id) { + $.ajax({ + type: 'post', + url: 'notify', + data: { + 'notify_id' : notify_id + }, + async: ((module !== path) ? false : true) + }); + } - myWorker.port.start(); + if (module !== path) { + e.preventDefault(); + window.location.href = path + '/' + b64mid; } - } - else { - if (!document.hidden) - sse_fallback_interval = setInterval(sse_fallback, updateInterval); + else { - document.addEventListener('visibilitychange', function() { - if (document.hidden) { - clearInterval(sse_fallback_interval); - } - else { - sse_offset = 0; - sse_bs_init(); - sse_fallback_interval = setInterval(sse_fallback, updateInterval); + if (singlethread_modules.indexOf(module) !== -1) { + history.pushState(stateObj, '', module + '/' + b64mid); + $('.message').removeClass('active'); + $('[data-b64mid="' + b64mid + '"].message').addClass('active'); } - }, false); - } - - $('.notification-link').on('click', { replace: true, followup: false }, sse_bs_notifications); - - $('.notification-filter').on('keypress', function(e) { - if(e.which == 13) { // enter - this.blur(); - sse_offset = 0; - $("#nav-" + sse_type + "-menu").html(''); - $("#nav-" + sse_type + "-loading").show(); - - var cn_val = $('#cn-' + sse_type + '-input').length ? $('#cn-' + sse_type + '-input').val().toString().toLowerCase() : ''; - - $.get('/sse_bs/' + sse_type + '/' + sse_offset + '?nquery=' + encodeURIComponent(cn_val), function(obj) { - console.log('sse: bootstraping ' + sse_type); - console.log(obj); + if (b64mid) { - sse_bs_active = false; - sse_partial_result = true; - sse_offset = obj[sse_type].offset; - if(sse_offset < 0) - $("#nav-" + sse_type + "-loading").hide(); + e.preventDefault(); - sse_handleNotifications(obj, true, false); - - }); + if(! page_load) { + prepareLiveUpdate(b64mid, notify_id); + } + } } }); - $('.notifications-textinput-clear').on('click', function(e) { - if(! sse_partial_result) - return; - - $("#nav-" + sse_type + "-menu").html(''); - $("#nav-" + sse_type + "-loading").show(); - $.get('/sse_bs/' + sse_type, function(obj) { - console.log('sse: bootstraping ' + sse_type); - console.log(obj); - - sse_bs_active = false; - sse_partial_result = false; - sse_offset = obj[sse_type].offset; - if(sse_offset < 0) - $("#nav-" + sse_type + "-loading").hide(); - - sse_handleNotifications(obj, true, false); - - }); - }); - - $('.notification-content').on('scroll', function() { - if(this.scrollTop > this.scrollHeight - this.clientHeight - (this.scrollHeight/7)) { - sse_bs_notifications(sse_type, false, true); + window.onpopstate = function(e) { + if(e.state !== null && e.state.b64mid !== bParam_mid) { + prepareLiveUpdate(e.state.b64mid, ''); + $('.message').removeClass('active'); + $('[data-b64mid="' + e.state.b64mid + '"].message').addClass('active'); } - }); + + }; //mod_mail only $(".mail-conv-detail .autotime").timeago(); @@ -223,6 +237,13 @@ $(document).ready(function() { cache_next_page(); }); + $(document).on('hz:handleNetworkNotificationsItems', function(e, obj) { + push_notification( + obj.name, + $('<p>' + obj.message + '</p>').text(), + obj.b64mid + ); + }); }); function getConversationSettings() { @@ -504,11 +525,14 @@ function showHideComments(id) { } } -function openClose(theID) { - if(document.getElementById(theID).style.display == "block") { +function openClose(theID, display) { + if (typeof display == typeof undefined) + display = 'block'; + + if(document.getElementById(theID).style.display == display) { document.getElementById(theID).style.display = "none"; } else { - document.getElementById(theID).style.display = "block"; + document.getElementById(theID).style.display = display; } } @@ -520,9 +544,11 @@ function openCloseTR(theID) { } } -function closeOpen(theID) { +function closeOpen(theID, display) { + if (typeof display == typeof undefined) + display = 'block'; if(document.getElementById(theID).style.display == "none") { - document.getElementById(theID).style.display = "block"; + document.getElementById(theID).style.display = display; } else { document.getElementById(theID).style.display = "none"; } @@ -537,18 +563,20 @@ function closeMenu(theID) { } function markRead(notifType) { - $.get('ping?f=&markRead='+notifType); + $.get('notifications?f=&markRead='+notifType); $('.' + notifType + '-button').fadeOut(function() { $("." + notifType + "-update").html('0'); $('#nav-' + notifType + '-menu').html(''); $('#nav-' + notifType + '-sub').removeClass('show'); sessionStorage.removeItem('notification_open'); - sse_setNotificationsStatus(); + $(document).trigger('hz:sse_setNotificationsStatus'); }); + + } function markItemRead(itemId) { - $.get('ping?f=&markItemRead='+itemId); + $.get('notifications?f=&markItemRead='+itemId); $('.unseen-wall-indicator-'+itemId).remove(); } @@ -712,52 +740,18 @@ function updateConvItems(mode,data) { } } - // take care of the notifications count updates - var nmids = $(this).data('b64mids'); - - nmids.forEach(function(nmid, index) { - - sse_rmids.push(nmid); - - if($('.notification[data-b64mid=\'' + nmid + '\']').length) { - $('.notification[data-b64mid=\'' + nmid + '\']').each(function() { - var n = this.parentElement.id.split('-'); - return sse_updateNotifications(n[1], nmid); - }); - } - - // special handling for forum notifications - $('.notification-forum').filter(function() { - var fmids = decodeURIComponent($(this).data('b64mids')); - var n = this.parentElement.id.split('-'); - if(fmids.indexOf(nmid) > -1) { - var fcount = Number($('.' + n[1] + '-update').html()); - fcount--; - $('.' + n[1] + '-update').html(fcount); - if(fcount < 1) - $('.' + n[1] + '-button').fadeOut(); - - var count = Number($(this).find('.badge-secondary').html()); - count--; - $(this).find('.badge-secondary').html(count); - if(count < 1) - $(this).remove(); - } - }); - - - }); - - sse_setNotificationsStatus(); + $(document).trigger('hz:sse_setNotificationsStatus', [$(this).data('b64mids')]); }); $(window).scrollTop(scroll_position); - if(followUpPageLoad) - sse_bs_counts(); - else - sse_bs_init(); + if(followUpPageLoad) { + $(document).trigger('hz:sse_bs_counts'); + } + else { + $(document).trigger('hz:sse_bs_init'); + } if(commentBusy) { commentBusy = false; @@ -897,7 +891,7 @@ function updateInit() { liveUpdate(); } else { - sse_bs_init(); + $(document).trigger('hz:sse_bs_init'); } if($('#live-photos').length || $('#live-cards').length || $('#live-articles').length ) { @@ -908,6 +902,20 @@ function updateInit() { } } +function prepareLiveUpdate(b64mid, notify_id) { + $(document).scrollTop(0); + $('.thread-wrapper').remove(); + bParam_mid = b64mid; + mode = 'replace'; + page_load = true; + if (module == 'hq') { + liveUpdate(notify_id); + } + if (module == 'display') { + liveUpdate(); + } +} + function liveUpdate(notify_id) { if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */ @@ -991,9 +999,9 @@ function liveUpdate(notify_id) { // else data was valid - reset the recursion counter liveRecurse = 0; - if(typeof notify_id !== 'undefined' && notify_id !== 'undefined') { + if(notify_id) { $.post( - "hq", + "notify", { "notify_id" : notify_id } @@ -1027,7 +1035,7 @@ function liveUpdate(notify_id) { //console.log('all images loaded, at least one is broken'); }) .progress( function( instance, image ) { - $('#image_counter').html(instance.progressedCount + '/' + instance.images.length); + $('#image_counter').html(Math.floor((instance.progressedCount*100)/instance.images.length) + '%'); //var result = image.isLoaded ? 'loaded' : 'broken'; //console.log( 'image is ' + result + ' for ' + image.img.src ); }); @@ -1155,8 +1163,18 @@ function dolike(ident, verb) { if(typeof page_mode == typeof undefined) page_mode = ''; - $.get('like/' + ident.toString() + '?verb=' + verb + '&conv_mode=' + conv_mode + '&page_mode=' + page_mode, function (data) { + var reload = ''; + if(module == 'photos') + reload = 1; + + $.get('like/' + ident.toString() + '?verb=' + verb + '&conv_mode=' + conv_mode + '&page_mode=' + page_mode + '&reload=' + reload, function (data) { if(data.success) { + + // mod photos + if (data.reload) { + window.location.href = window.location.href; + } + // this is a bit tricky since the top level thread wrapper wraps the whole thread if($('#thread-wrapper-' + data.orig_id).hasClass('toplevel_item')) { var wrapper = $('<div></div>').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); @@ -1218,7 +1236,7 @@ function doscroll(parent, hidden) { }); $('html, body').animate({scrollTop:(id.offset().top) - 50}, 'slow'); - $('<a href="javascript:doscrollback(' + pos + ');" id="back-to-reply" class="float-right" title="' + aStr['to_reply'] + '"><i class="fa fa-angle-double-down"> </i></a>').insertBefore('#wall-item-info-' + id.attr('id').replace(/\D/g,'')); + $('<a href="javascript:doscrollback(' + pos + ');" id="back-to-reply" class="float-end" title="' + aStr['to_reply'] + '"><i class="fa fa-angle-double-down"> </i></a>').insertBefore('#wall-item-info-' + id.attr('id').replace(/\D/g,'')); } function doscrollback(pos) { @@ -1243,7 +1261,7 @@ function dopin(id) { $('.dropdown-item-pinnable').html($('.dropdown-item-pinnable').html().replace(aStr['unpin_item'],aStr['pin_item'])); $('.wall-item-pinned').remove() if(i.length == 0) { - $('<span class="float-right wall-item-pinned" title="' + aStr['pinned'] + '" id="wall-item-pinned-' + id + '"><i class="fa fa-thumb-tack"> </i></span>').insertBefore('#wall-item-info-' + id); + $('<span class="float-end wall-item-pinned" title="' + aStr['pinned'] + '" id="wall-item-pinned-' + id + '"><i class="fa fa-thumb-tack"> </i></span>').insertBefore('#wall-item-info-' + id); me.html(me.html().replace(aStr['pin_item'],aStr['unpin_item'])); }; }) @@ -1255,7 +1273,7 @@ function dopin(id) { }); } -function dropItem(url, object) { +function dropItem(url, object, b64mid) { var confirm = confirmDelete(); if(confirm) { var id = url.split('/')[2]; @@ -1265,13 +1283,20 @@ function dropItem(url, object) { $.get(url, function() { $(object + ', #pinned-wrapper-' + id).remove(); $('body').css('cursor', 'auto'); + + if (typeof b64mid !== typeof undefined) { + $('[data-b64mid=\'' + b64mid + '\']').fadeOut(function() { + this.remove(); + }); + } }); - if($('#wall-item-pinned-' + id).length) + if($('#wall-item-pinned-' + id).length) { $.post('pin/pin', { 'id' : id }); + } return true; - } + } else { return false; } @@ -1371,7 +1396,14 @@ function post_comment(id) { "item", form_data + '&conv_mode=' + conv_mode, function(data) { - if(data.success) { + if (data.success) { + + //mod photos + if (data.reload) { + window.location.href = data.reload; + } + + localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); @@ -1382,7 +1414,7 @@ function post_comment(id) { commentBusy = false; var tarea = document.getElementById("comment-edit-text-" + id); - if(tarea) { + if (tarea) { commentClose(tarea, id); $(document).off( "click.commentOpen"); } @@ -1446,54 +1478,22 @@ function preview_post() { return true; } -function preview_mail() { - $("#mail-preview").val("1"); - $("#mail-preview-content").show(); - $.post( - "mail", - $("#prvmail-form").serialize(), - function(data) { - if(data.preview) { - $("#mail-preview-content").html(data.preview); - $("#mail-preview-content" + " a").click(function() { return false; }); - } - }, - "json" - ); - $("#mail-preview").val("0"); - return true; -} - function bin2hex(s) { - // Converts the binary representation of data to hex - // - // version: 812.316 - // discuss at: http://phpjs.org/functions/bin2hex - // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) - // + bugfixed by: Onno Marsman - // + bugfixed by: Linuxworld - // * example 1: bin2hex('Kev'); - // * returns 1: '4b6576' - // * example 2: bin2hex(String.fromCharCode(0x00)); - // * returns 2: '00' - var v,i, f = 0, a = []; - s += ''; - f = s.length; - - for (i = 0; i<f; i++) { - a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1"); - } - - return a.join(''); + // UTF-8 encoding to hex is supported + var bytes = new TextEncoder().encode(s); + return Array.from( + bytes, + byte => byte.toString(16).padStart(2, "0") + ).join(""); } function hex2bin(hex) { - var bytes = [], str; - - for(var i=0; i< hex.length-1; i+=2) - bytes.push(parseInt(hex.substr(i, 2), 16)); - - return String.fromCharCode.apply(String, bytes); + // UTF-8 decoding from hex is supported + var bytes = new Uint8Array(hex.length / 2); + for (i = 0; i !== bytes.length; i++) { + bytes[i] = parseInt(hex.substr(i * 2, 2), 16); + } + return new TextDecoder().decode(bytes); } function groupChangeMember(gid, cid, sec_token) { @@ -1719,294 +1719,47 @@ function zid(s) { return s; } -function sse_bs_init() { - if(sessionStorage.getItem('notification_open') !== null || typeof sse_type !== 'undefined' ) { - if(typeof sse_type === 'undefined') - sse_type = sessionStorage.getItem('notification_open'); - - $("#nav-" + sse_type + "-sub").addClass('show'); - sse_bs_notifications(sse_type, true, false); - } - else { - sse_bs_counts(); - } -} - -function sse_bs_counts() { - if(sse_bs_active) - return; - - sse_bs_active = true; - - $.ajax({ - type: 'post', - url: '/sse_bs', - data: { sse_rmids } - }).done( function(obj) { - console.log(obj); - sse_bs_active = false; - sse_rmids = []; - sse_handleNotifications(obj, true, false); - }); -} - -function sse_bs_notifications(e, replace, followup) { - - if(sse_bs_active) - return; - - - var manual = false; - - if(typeof replace === 'undefined') - replace = e.data.replace; - - if(typeof followup === 'undefined') - followup = e.data.followup; - - if(typeof e === 'string') { - sse_type = e; - } - else { - manual = true; - sse_offset = 0; - sse_type = e.target.dataset.sse_type; - } - - if(typeof sse_type === 'undefined') - return; - - if(followup || !manual || !($('#nav-' + sse_type + '-sub').hasClass('collapse') && $('#nav-' + sse_type + '-sub').hasClass('show'))) { - - if(sse_offset >= 0) { - $("#nav-" + sse_type + "-loading").show(); - } - - sessionStorage.setItem('notification_open', sse_type); - if(sse_offset !== -1 || replace) { - - var cn_val = (($('#cn-' + sse_type + '-input').length && sse_partial_result) ? $('#cn-' + sse_type + '-input').val().toString().toLowerCase() : ''); - - $("#nav-" + sse_type + "-loading").show(); - - sse_bs_active = true; - - $.ajax({ - type: 'post', - url: '/sse_bs/' + sse_type + '/' + sse_offset, - nquery: encodeURIComponent(cn_val), - data: { sse_rmids } - }).done(function(obj) { - console.log('sse: bootstraping ' + sse_type); - console.log(obj); - sse_bs_active = false; - sse_rmids = []; - $("#nav-" + sse_type + "-loading").hide(); - sse_offset = obj[sse_type].offset; - sse_handleNotifications(obj, replace, followup); - }); - } - else - $("#nav-" + sse_type + "-loading").hide(); - - } - else { - sessionStorage.removeItem('notification_open'); +function makeid(length) { + var result = ''; + var characters = 'abcdef0123456789'; + var charactersLength = characters.length; + for ( var i = 0; i < length; i++ ) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); } + return result; } -function sse_handleNotifications(obj, replace, followup) { - - var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files']; - var secondary_notifications = ['network', 'forums', 'all_events', 'pubs']; - var all_notifications = primary_notifications.concat(secondary_notifications); - - all_notifications.forEach(function(type, index) { - if(typeof obj[type] === typeof undefined) - return true; - - if(obj[type].count) { - $('.' + type + '-button').fadeIn(); - if(replace || followup) - $('.' + type + '-update').html(Number(obj[type].count)); - else - $('.' + type + '-update').html(Number(obj[type].count) + Number($('.' + type + '-update').html())); - } - else { - $('.' + type + '-update').html('0'); - $('.' + type + '-button').fadeOut(function() { - sse_setNotificationsStatus(); - }); - } - if(obj[type].notifications.length) - sse_handleNotificationsItems(type, obj[type].notifications, replace, followup); - }); - - sse_setNotificationsStatus(); - - // notice and info - $.jGrowl.defaults.closerTemplate = '<div>[ ' + aStr.closeAll + ']</div>'; - - if(obj.notice) { - $(obj.notice.notifications).each(function() { - $.jGrowl(this, { sticky: true, theme: 'notice' }); - }); - } - - if(obj.info) { - $(obj.info.notifications).each(function(){ - $.jGrowl(this, { sticky: false, theme: 'info', life: 10000 }); +function push_notification_request(e) { + if (!('Notification' in window)) { + alert('This browser does not support push notifications'); + } + else if (Notification.permission !== 'granted') { + Notification.requestPermission(function(permission) { + if(permission === 'granted') { + $(e.target).closest('div').hide(); + } }); - } - - // load more notifications if visible notifications count becomes low - if(sse_type && sse_offset != -1 && $('#nav-' + sse_type + '-menu').children().length <= 20) { - sse_offset = 0; - sse_bs_notifications(sse_type, false, true); - } - - + } } -function sse_handleNotificationsItems(notifyType, data, replace, followup) { - var notifications_tpl = ((notifyType == 'forums') ? decodeURIComponent($("#nav-notifications-forums-template[rel=template]").html().replace('data-src', 'src')) : decodeURIComponent($("#nav-notifications-template[rel=template]").html().replace('data-src', 'src'))); - var notify_menu = $("#nav-" + notifyType + "-menu"); - var notify_loading = $("#nav-" + notifyType + "-loading"); - var notify_count = $("." + notifyType + "-update"); - - if(replace && !followup) { - notify_menu.html(''); - notify_loading.hide(); +function push_notification(title, body, b64mid) { + let options = { + body: body, + data: b64mid, + icon: '/images/app/hz-96.png', + silent: false } - $(data).each(function() { - - // do not add a notification if it is already present - if($('#nav-' + notifyType + '-menu .notification[data-b64mid=\'' + this.b64mid + '\']').length) - return true; - - html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.addr,this.message,this.when,this.hclass,this.b64mid,this.notify_id,this.thread_top,this.unseen,this.private_forum, encodeURIComponent(this.mids), this.body); - notify_menu.append(html); - }); - - if(!replace && !followup) { - $("#nav-" + notifyType + "-menu .notification").sort(function(a,b) { - a = new Date(a.dataset.when); - b = new Date(b.dataset.when); - return a > b ? -1 : a < b ? 1 : 0; - }).appendTo('#nav-' + notifyType + '-menu'); - } - - $(document.body).trigger("sticky_kit:recalc"); - $("#nav-" + notifyType + "-menu .notifications-autotime").timeago(); - - if($('#tt-' + notifyType + '-only').hasClass('active')) - $('#nav-' + notifyType + '-menu [data-thread_top=false]').addClass('tt-filter-active'); - - if($('#cn-' + notifyType + '-input').length) { - var filter = $('#cn-' + notifyType + '-input').val().toString().toLowerCase(); - if(filter) { - filter = filter.indexOf('%') == 0 ? filter.substring(1) : filter; - - $('#nav-' + notifyType + '-menu .notification').each(function(i, el) { - var cn = $(el).data('contact_name').toString().toLowerCase(); - var ca = $(el).data('contact_addr').toString().toLowerCase(); - if(cn.indexOf(filter) === -1 && ca.indexOf(filter) === -1) - $(el).addClass('cn-filter-active'); - else - $(el).removeClass('cn-filter-active'); - }); + let n = new Notification(title, options); + n.onclick = function (e) { + if(module === 'hq') { + prepareLiveUpdate(e.target.data); } - } -} - -function sse_updateNotifications(type, mid) { - - if(type === 'pubs') - return true; - - if(type === 'notify' && (mid !== bParam_mid || sse_type !== 'notify')) - return true; -/* - var count = Number($('.' + type + '-update').html()); - - count--; - - if(count < 1) { - $('.' + type + '-update').html(count); - $('.' + type + '-button').fadeOut(function() { - sse_setNotificationsStatus(); - }); - } - else { - $('.' + type + '-update').html(count); - } -*/ - - $('#nav-' + type + '-menu .notification[data-b64mid=\'' + mid + '\']').fadeOut(function() { - this.remove(); - }); - -} - -function sse_setNotificationsStatus() { - var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files']; - var secondary_notifications = ['network', 'forums', 'all_events', 'pubs']; - var all_notifications = primary_notifications.concat(secondary_notifications); - - var primary_available = false; - var any_available = false; - - all_notifications.forEach(function(type, index) { - if($('.' + type + '-button').css('display') == 'block') { - any_available = true; - if(primary_notifications.indexOf(type) > -1) - primary_available = true; + else { + window.location.href = baseurl + '/hq/' + e.target.data; } - }); - - if(primary_available) { - $('.notifications-btn-icon').removeClass('fa-exclamation-circle'); - $('.notifications-btn-icon').addClass('fa-exclamation-triangle'); } - else { - $('.notifications-btn-icon').removeClass('fa-exclamation-triangle'); - $('.notifications-btn-icon').addClass('fa-exclamation-circle'); - } - - if(any_available) { - $('.notifications-btn').css('opacity', 1); - $('#no_notifications').hide(); - $('#notifications').show(); - } - else { - $('.notifications-btn').css('opacity', 0.5); - $('#navbar-collapse-1').removeClass('show'); - $('#no_notifications').show(); - $('#notifications').hide(); - } - } -function sse_fallback() { - $.get('/sse', function(obj) { - if(! obj) - return; - - console.log('sse fallback'); - console.log(obj); - sse_handleNotifications(obj, false, false); - }); -} - -function makeid(length) { - var result = ''; - var characters = 'abcdef0123456789'; - var charactersLength = characters.length; - for ( var i = 0; i < length; i++ ) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; -} diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 5ca1f52a9..1f444e4fe 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -47,7 +47,7 @@ $(document).ready(function () { let id = $(this).data('id'); activate_id(id); $('#id_categories_' + id).tagsinput({ - tagClass: 'badge badge-pill badge-warning text-dark' + tagClass: 'badge rounded-pill bg-warning text-dark' }); $('#cloud-tool-categories-' + id).show(); }); @@ -278,7 +278,7 @@ $(document).ready(function () { disable_multi_acl(); $('#id_categories').tagsinput({ - tagClass: 'badge badge-pill badge-warning text-dark' + tagClass: 'badge rounded-pill bg-warning text-dark' }); $('#cloud-multi-tool-submit, #cloud-multi-tool-categories').show(); @@ -402,74 +402,85 @@ $(document).ready(function () { function UploadInit() { var submit = $("#upload-submit"); - var count = 1; + var idx = 0; var filedrag = $(".cloud-index.attach-drop"); + var reload = false; $('#invisible-cloud-file-upload').fileupload({ - url: 'file_upload', - dataType: 'json', - dropZone: filedrag, - maxChunkSize: 4 * 1024 * 1024, - - add: function(e,data) { - $(data.files).each( function() { this.count = ++ count; prepareHtml(this); }); - - var allow_cid = ($('#ajax-upload-files').data('allow_cid') || []); - var allow_gid = ($('#ajax-upload-files').data('allow_gid') || []); - var deny_cid = ($('#ajax-upload-files').data('deny_cid') || []); - var deny_gid = ($('#ajax-upload-files').data('deny_gid') || []); - - $('.acl-field').remove(); - - $(allow_gid).each(function(i,v) { - $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='group_allow[]' value='"+v+"'>"); - }); - $(allow_cid).each(function(i,v) { - $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='contact_allow[]' value='"+v+"'>"); - }); - $(deny_gid).each(function(i,v) { - $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='group_deny[]' value='"+v+"'>"); - }); - $(deny_cid).each(function(i,v) { - $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='contact_deny[]' value='"+v+"'>"); - }); - - data.formData = $('#ajax-upload-files').serializeArray(); - data.submit(); - }, - + url: 'file_upload', + dataType: 'json', + dropZone: filedrag, + maxChunkSize: 4 * 1024 * 1024, + add: function(e,data) { - progress: function(e,data) { + idx++; + data.files[0].idx = idx; + prepareHtml(data.files[0]); - // there will only be one file, the one we are looking for + var allow_cid = ($('#ajax-upload-files').data('allow_cid') || []); + var allow_gid = ($('#ajax-upload-files').data('allow_gid') || []); + var deny_cid = ($('#ajax-upload-files').data('deny_cid') || []); + var deny_gid = ($('#ajax-upload-files').data('deny_gid') || []); - $(data.files).each( function() { - var idx = this.count; + $('.acl-field').remove(); - // Dynamically update the percentage complete displayed in the file upload list - $('#upload-progress-' + idx).html(Math.round(data.loaded / data.total * 100) + '%'); - $('#upload-progress-bar-' + idx).css('background-size', Math.round(data.loaded / data.total * 100) + '%'); + $(allow_gid).each(function(i,v) { + $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='group_allow[]' value='"+v+"'>"); + }); + $(allow_cid).each(function(i,v) { + $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='contact_allow[]' value='"+v+"'>"); + }); + $(deny_gid).each(function(i,v) { + $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='group_deny[]' value='"+v+"'>"); + }); + $(deny_cid).each(function(i,v) { + $('#ajax-upload-files').append("<input class='acl-field' type='hidden' name='contact_deny[]' value='"+v+"'>"); + }); - }); + data.formData = $('#ajax-upload-files').serializeArray(); + // trick it into not uploadiong all files at once + $('#new-upload-' + data.files[0].idx).one('fileupload_trigger', function () { + data.submit(); + }); - }, + $('#new-upload-1').trigger('fileupload_trigger'); + }, - stop: function(e,data) { - window.location.href = window.location.href; + progress: function(e,data) { + var id = data.files[0].idx; + if(data.loaded == data.total) { + if(id == data.originalFiles.length) { + reload = true; + } + else { + // trigger uploading the next file + var next_id = id + 1; + setTimeout(function(){ $('#new-upload-' + next_id).trigger('fileupload_trigger'); }, 1000); + } } - }); + // Dynamically update the percentage complete displayed in the file upload list + $('#upload-progress-' + id).html(Math.round(data.loaded / data.total * 100) + '%'); + $('#upload-progress-bar-' + id).css('width', Math.round(data.loaded / data.total * 100) + '%'); - $('#upload-submit').click(function(event) { event.preventDefault(); $('#invisible-cloud-file-upload').trigger('click'); return false;}); + }, -} + stop: function(e,data) { + if(reload) { + console.log('Upload completed'); + window.location.href = window.location.href; + } + } + }); + $('#upload-submit').click(function(event) { event.preventDefault(); $('#invisible-cloud-file-upload').trigger('click');}); +} function prepareHtml(f) { - var num = f.count - 1; - var i = f.count; + var num = f.idx - 1; + var i = f.idx; $('#cloud-index #new-upload-progress-bar-' + num.toString()).after( '<tr id="new-upload-' + i + '" class="new-upload">' + '<td></td>' + @@ -479,7 +490,11 @@ function prepareHtml(f) { '<td class="d-none d-md-table-cell">' + formatSizeUnits(f.size) + '</td><td class="d-none d-md-table-cell"></td>' + '</tr>' + '<tr id="new-upload-progress-bar-' + i + '" class="new-upload">' + - '<td id="upload-progress-bar-' + i + '" colspan="9" class="upload-progress-bar"></td>' + + '<td colspan="9" class="upload-progress-bar">' + + '<div class="progress" style="height: 1px;">' + + '<div id="upload-progress-bar-' + i + '" class="progress-bar bg-info" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>' + + '</div>' + + '</td>' + '</tr>' ); } diff --git a/view/js/mod_connections.js b/view/js/mod_connections.js index db18e078d..848e9ed9f 100644 --- a/view/js/mod_connections.js +++ b/view/js/mod_connections.js @@ -1,5 +1,5 @@ $(document).ready(function() { $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true); $(".autotime").timeago(); -}); +}); diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js index b321382bd..5f8430b4d 100644 --- a/view/js/mod_hq.js +++ b/view/js/mod_hq.js @@ -1,10 +1,17 @@ -$(document).on('click', '#jot-toggle', function(e) { - e.preventDefault(); - e.stopPropagation(); +$(document).ready(function() { - $(this).toggleClass('active'); - $(window).scrollTop(0); - $('#jot-popup').toggle(); - $('#profile-jot-text').focus(); + $(document).on('click', '.jot-toggle', function(e) { + $(window).scrollTop(0); + $(document).trigger('hz:hqControlsClickAction'); + $('#jot-popup').toggle(); + $('#profile-jot-text').focus(); + }); + + $(document).on('click', '.notes-toggle', function(e) { + $(window).scrollTop(0); + $(document).trigger('hz:hqControlsClickAction'); + $('#personal-notes').toggleClass('d-none'); + $('#note-text').focus(); + }); }); diff --git a/view/js/mod_import_progress.js b/view/js/mod_import_progress.js new file mode 100644 index 000000000..7aed56365 --- /dev/null +++ b/view/js/mod_import_progress.js @@ -0,0 +1,54 @@ +$(document).ready(function() { + setInterval(get_progress, 5000); + + function get_progress(){ + $.get('import_progress', function(data) { + update_progress(data); + }); + } + + function update_progress(data){ + + // items + if (typeof data.cprogress == 'number') { + $('#cprogress-label').html(data.cprogress + '%'); + $('#cprogress-bar').css('width', data.cprogress + '%'); + + if (data.cprogress == 100) { + $('#cprogress-resume').addClass('d-none'); + $('#cprogress-completed').removeClass('d-none'); + $('#cprogress-bar').removeClass('progress-bar-animated'); + } + else if (data.cprogress < 100) { + $('#cprogress-resume').removeClass('d-none'); + $('#cprogress-completed').addClass('d-none'); + $('#cprogress-bar').addClass('progress-bar-animated'); + } + } + else { + $('#cprogress-label').html(data.cprogress); + $('#cprogress-bar').css('width', '0%'); + } + + // files + if (typeof data.fprogress == 'number') { + $('#fprogress-label').html(data.fprogress + '%'); + $('#fprogress-bar').css('width', data.fprogress + '%'); + + if (data.fprogress == 100) { + $('#fprogress-resume').addClass('d-none'); + $('#fprogress-completed').removeClass('d-none'); + $('#fprogress-bar').removeClass('progress-bar-animated'); + } + else if (data.fprogress < 100) { + $('#fprogress-resume').removeClass('d-none'); + $('#fprogress-completed').addClass('d-none'); + $('#fprogress-bar').addClass('progress-bar-animated'); + } + } + else { + $('#fprogress-label').html(data.fprogress); + $('#fprogress-bar').css('width', '0%'); + } + } +}); diff --git a/view/js/mod_mail.js b/view/js/mod_mail.js deleted file mode 100644 index 917e5414c..000000000 --- a/view/js/mod_mail.js +++ /dev/null @@ -1,7 +0,0 @@ -$(document).ready(function() { - $("#recip").name_autocomplete(baseurl + '/acl', 'm', false, function(data) { - $("#recip-complete").val(data.xid); - }); - $('#prvmail-text').bbco_autocomplete('bbcode'); - $("#prvmail-text").editor_autocomplete(baseurl+"/acl"); -}); diff --git a/view/js/mod_photos.js b/view/js/mod_photos.js index af675e31c..c487fc417 100644 --- a/view/js/mod_photos.js +++ b/view/js/mod_photos.js @@ -8,23 +8,11 @@ $(document).ready(function() { UploadInit(); } - $("#photo-edit-newtag").contact_autocomplete(baseurl + '/acl', 'a', false, function(data) { - $("#photo-edit-newtag").val('@' + data.name); - }); - $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl?f=&n=1"); + $('textarea').editor_autocomplete(baseurl+"/acl"); $('textarea').bbco_autocomplete('bbcode'); - showHideBodyTextarea(); - }); -function showHideBodyTextarea() { - if( $('#id_visible').is(':checked')) - $('#body-textarea').slideDown(); - else - $('#body-textarea').slideUp(); -} - // initialize function UploadInit() { @@ -32,151 +20,101 @@ function UploadInit() { var fileselect = $("#photos-upload-choose"); var filedrag = $("#photos-upload-form"); var submit = $("#dbtn-submit"); - var count = 1; - - $('#invisible-photos-file-upload').fileupload({ - url: 'photos/' + nickname, - dataType: 'json', - dropZone: filedrag, - maxChunkSize: 4 * 1024 * 1024, - - add: function(e,data) { - $(data.files).each( function() { this.count = ++ count; prepareHtml(this); }); - - var allow_cid = ($('#photos-upload-form').data('allow_cid') || []); - var allow_gid = ($('#photos-upload-form').data('allow_gid') || []); - var deny_cid = ($('#photos-upload-form').data('deny_cid') || []); - var deny_gid = ($('#photos-upload-form').data('deny_gid') || []); - - $('.acl-field').remove(); - - $(allow_gid).each(function(i,v) { - $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='group_allow[]' value='"+v+"'>"); - }); - $(allow_cid).each(function(i,v) { - $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='contact_allow[]' value='"+v+"'>"); - }); - $(deny_gid).each(function(i,v) { - $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='group_deny[]' value='"+v+"'>"); - }); - $(deny_cid).each(function(i,v) { - $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='contact_deny[]' value='"+v+"'>"); - }); - - data.formData = $('#photos-upload-form').serializeArray(); - - data.submit(); - }, - - progress: function(e,data) { - - // there will only be one file, the one we are looking for - - $(data.files).each( function() { - var idx = this.count; - - // Dynamically update the percentage complete displayed in the file upload list - $('#upload-progress-' + idx).html(Math.round(data.loaded / data.total * 100) + '%'); - $('#upload-progress-bar-' + idx).css('background-size', Math.round(data.loaded / data.total * 100) + '%'); - - }); - - - }, - - - stop: function(e,data) { - window.location.href = window.location.href; - } - - }); - - $('#dbtn-submit').click(function(event) { event.preventDefault(); $('#invisible-photos-file-upload').trigger('click'); return false;}); - - - - - // is XHR2 available? -// var xhr = new XMLHttpRequest(); -// if (xhr.upload) { - - // file select -// fileselect.attr("multiple", 'multiple'); -// fileselect.on("change", UploadFileSelectHandler); - - // file submit -// submit.on("click", fileselect, UploadFileSelectHandler); + var idx = 0; + var reload = false; + + + $('#invisible-photos-file-upload').fileupload({ + url: 'photos/' + nickname, + dataType: 'json', + dropZone: filedrag, + maxChunkSize: 4 * 1024 * 1024, + + add: function(e,data) { + + idx++; + data.files[0].idx = idx; + prepareHtml(data.files[0]); + + var allow_cid = ($('#photos-upload-form').data('allow_cid') || []); + var allow_gid = ($('#photos-upload-form').data('allow_gid') || []); + var deny_cid = ($('#photos-upload-form').data('deny_cid') || []); + var deny_gid = ($('#photos-upload-form').data('deny_gid') || []); + + $('.acl-field').remove(); + + $(allow_gid).each(function(i,v) { + $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='group_allow[]' value='"+v+"'>"); + }); + $(allow_cid).each(function(i,v) { + $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='contact_allow[]' value='"+v+"'>"); + }); + $(deny_gid).each(function(i,v) { + $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='group_deny[]' value='"+v+"'>"); + }); + $(deny_cid).each(function(i,v) { + $('#photos-upload-form').append("<input class='acl-field' type='hidden' name='contact_deny[]' value='"+v+"'>"); + }); + + data.formData = $('#photos-upload-form').serializeArray(); + + // trick it into not uploadiong all files at once + $('#new-upload-' + data.files[0].idx).one('fileupload_trigger', function () { + data.submit(); + }); + + $('#new-upload-1').trigger('fileupload_trigger'); + }, + + progress: function(e,data) { + + var id = data.files[0].idx; + if(data.loaded == data.total) { + if(id == data.originalFiles.length) { + reload = true; + } + else { + // trigger uploading the next file + var next_id = id + 1; + setTimeout(function(){ $('#new-upload-' + next_id).trigger('fileupload_trigger'); }, 1000); + } + } + + // Dynamically update the percentage complete displayed in the file upload list + $('#upload-progress-' + id).html(Math.round(data.loaded / data.total * 100) + '%'); + $('#upload-progress-bar-' + id).css('width', Math.round(data.loaded / data.total * 100) + '%'); + }, + + stop: function(e,data) { + if(reload) { + console.log('Upload completed'); + window.location.href = window.location.href; + } + } + }); - // file drop -// filedrag.on("dragover", DragDropUploadFileHover); -// filedrag.on("dragleave", DragDropUploadFileHover); -// filedrag.on("drop", DragDropUploadFileSelectHandler); -// } + $('#dbtn-submit').click(function(event) { event.preventDefault(); $('#invisible-photos-file-upload').trigger('click'); return false;}); -// window.filesToUpload = 0; -// window.fileUploadsCompleted = 0; } -// file drag hover -function DragDropUploadFileHover(e) { - e.stopPropagation(); - e.preventDefault(); - e.currentTarget.className = (e.type == "dragover" ? "hover" : ""); -} - -// file selection via drag/drop -function DragDropUploadFileSelectHandler(e) { - // cancel event and hover styling - DragDropUploadFileHover(e); - - // fetch FileList object - var files = e.target.files || e.originalEvent.dataTransfer.files; - - $('.new-upload').remove(); - - // process all File objects - for (var i = 0, f; f = files[i]; i++) { - prepareHtml(f, i); - UploadFile(f, i); - } -} - -// file selection via input -function UploadFileSelectHandler(e) { - // fetch FileList object - if(e.target.id === 'dbtn-submit') { - e.preventDefault(); - var files = e.data[0].files; - } - if(e.target.id === 'photos-upload-choose') { - $('.new-upload').remove(); - var files = e.target.files; - } - - // process all File objects - for (var i = 0, f; f = files[i]; i++) { - if(e.target.id === 'photos-upload-choose') - prepareHtml(f, i); - if(e.target.id === 'dbtn-submit') { - UploadFile(f, i); - } - } -} function prepareHtml(f) { - - var num = f.count - 1; - var i = f.count; - + var num = f.idx - 1; + var i = f.idx; $('#upload-index #new-upload-progress-bar-' + num.toString()).after( '<tr id="new-upload-' + i + '" class="new-upload">' + - '<td width="1%"><i class="fa ' + getIconFromType(f.type) + '" title="' + f.type + '"></i></td>' + - '<td width="96%">' + f.name + '</td>' + - '<td id="upload-progress-' + i + '" width="1%"></td>' + - '<td class="d-none d-md-table-cell" width="1%">' + formatSizeUnits(f.size) + '</td>' + + '<td></td>' + + '<td><i class="fa fa-fw ' + getIconFromType(f.type) + '" title="' + f.type + '"></i></td>' + + '<td>' + f.name + '</td>' + + '<td id="upload-progress-' + i + '"></td><td></td><td></td>' + + '<td class="d-none d-md-table-cell">' + formatSizeUnits(f.size) + '</td><td class="d-none d-md-table-cell"></td>' + '</tr>' + '<tr id="new-upload-progress-bar-' + i + '" class="new-upload">' + - '<td id="upload-progress-bar-' + i + '" colspan="4" class="upload-progress-bar"></td>' + + '<td colspan="8" class="upload-progress-bar">' + + '<div class="progress" style="height: 1px;">' + + '<div id="upload-progress-bar-' + i + '" class="progress-bar bg-info" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>' + + '</div>' + + '</td>' + '</tr>' ); } @@ -236,63 +174,3 @@ function getIconFromType(type) { return iconFromType; } - -// upload files -function UploadFile(file, idx) { - - window.filesToUpload = window.filesToUpload + 1; - - var xhr = new XMLHttpRequest(); - - xhr.withCredentials = true; // Include the SESSION cookie info for authentication - - (xhr.upload || xhr).addEventListener('progress', function (e) { - - var done = e.position || e.loaded; - var total = e.totalSize || e.total; - // Dynamically update the percentage complete displayed in the file upload list - $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); - $('#upload-progress-bar-' + idx).css('background-size', Math.round(done / total * 100) + '%'); - - if(done == total) { - $('#upload-progress-' + idx).html('Processing...'); - } - - }); - - - xhr.addEventListener('load', function (e) { - //we could possibly turn the filenames to real links here and add the delete and edit buttons to avoid page reload... - $('#upload-progress-' + idx).html('Ready!'); - - //console.log('xhr upload complete', e); - window.fileUploadsCompleted = window.fileUploadsCompleted + 1; - - // When all the uploads have completed, refresh the page - if (window.filesToUpload > 0 && window.fileUploadsCompleted === window.filesToUpload) { - - window.fileUploadsCompleted = window.filesToUpload = 0; - - // After uploads complete, refresh browser window to display new files - window.location.href = window.location.href; - } - }); - - - xhr.addEventListener('error', function (e) { - $('#upload-progress-' + idx).html('<span style="color: red;">ERROR</span>'); - }); - - // POST to the entire cloud path - xhr.open('post', $('#photos-upload-form').attr( 'action' ), true); - - var formfields = $("#photos-upload-form").serializeArray(); - - var data = new FormData(); - $.each(formfields, function(i, field) { - data.append(field.name, field.value); - }); - data.append('userfile', file); - - xhr.send(data); -} diff --git a/view/js/mod_register.js b/view/js/mod_register.js index 1fc5ad2fa..f54dd2570 100644 --- a/view/js/mod_register.js +++ b/view/js/mod_register.js @@ -3,7 +3,7 @@ $(document).ready(function() { typeof(window.tao) == 'undefined' ? window.tao = {} : ''; tao.zar = { vsn: '2.0.0', form: {}, msg: {} }; tao.zar.patano = /^d[0-9]{5,10}$/; - tao.zar.patema = /^[a-z0-9.-]{1,64}@[a-z0-9.-]{2,32}\.[a-z]{2,12}$/; + tao.zar.patema = /^[^@\s]{1,64}@[a-z0-9.-]{2,32}\.[a-z]{2,12}$/; $('.register_date').each( function () { var date = new Date($(this).data('utc')); diff --git a/view/js/mod_settings.js b/view/js/mod_settings.js index d3392c748..3e91dac9a 100644 --- a/view/js/mod_settings.js +++ b/view/js/mod_settings.js @@ -24,8 +24,14 @@ $(document).ready(function() { loadPermcat(permName); }); + if (Notification.permission !== 'granted') { + $('#desktop-notifications-info').show(); + } - + $('#desktop-notifications-request').on('click', function(e) { + e.preventDefault(); + push_notification_request(e); + }); }); |