From b63c5f27853aded30c492bdb94a680e5a9c9648b Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 14 Nov 2020 21:28:50 +0000 Subject: Polling fallback to server sent events. Polling is the default. SSE must be enabled in /admin/site > Advanced > Enable SSE Notifications if desired. --- view/js/main.js | 82 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 25 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 8ceb0b143..560868046 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -31,6 +31,7 @@ var sse_offset = 0; var sse_type; var sse_partial_result = false; var sse_rmids = []; +var sse_fallback_interval; var page_cache = {}; @@ -94,37 +95,56 @@ $(document).ready(function() { jQuery.timeago.settings.allowFuture = true; - 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); + 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'); - document.addEventListener('visibilitychange', function() { - if (!document.hidden) { - sse_offset = 0; - sse_bs_init(); - } - }, false); + evtSource.addEventListener('notifications', function(e) { + var obj = JSON.parse(e.data); + sse_handleNotifications(obj, false, false); + }, false); - } - else { - var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser); + document.addEventListener('visibilitychange', function() { + if (!document.hidden) { + sse_offset = 0; + sse_bs_init(); + } + }, false); - myWorker.port.onmessage = function(e) { - obj = e.data; - console.log(obj); - sse_handleNotifications(obj, false, false); } + else { + var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser); - myWorker.onerror = function(e) { - myWorker.port.close(); + myWorker.port.onmessage = function(e) { + obj = e.data; + console.log(obj); + sse_handleNotifications(obj, false, false); + } + + myWorker.onerror = function(e) { + myWorker.port.close(); + } + + myWorker.port.start(); } + } + else { + if (!document.hidden) + sse_fallback_interval = setInterval(sse_fallback, updateInterval); - myWorker.port.start(); + 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); + } + + }, false); } $('.notification-link').on('click', { replace: true, followup: false }, sse_bs_notifications); @@ -224,6 +244,8 @@ $(document).ready(function() { cache_next_page(); }); + + }); function getConversationSettings() { @@ -1763,8 +1785,6 @@ function sse_bs_init() { } function sse_bs_counts() { - - if(sse_bs_active) return; @@ -2022,3 +2042,15 @@ function sse_setNotificationsStatus() { } } + +function sse_fallback() { + $.get('/sse', function(obj) { + if(! obj) + return; + + console.log('sse fallback'); + console.log(obj); + + sse_handleNotifications(obj, false, false); + }); +} -- cgit v1.2.3 From 35c4deb88481fafe37eefab120438d68082568be Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 16 Nov 2020 09:28:18 +0000 Subject: work around an edge case in acl selector (cherry picked from commit e7c83a81c79235327cbbcb5382146332ba14a684) --- view/js/acl.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/acl.js b/view/js/acl.js index 4597184ea..940fdaa44 100644 --- a/view/js/acl.js +++ b/view/js/acl.js @@ -340,7 +340,13 @@ ACL.prototype.update_view = function(value) { that.list.hide(); //hide acl-list that.info.hide(); //show acl-info that.selected_id = that.contact_ids[that.allow_cid[0]]; - that.update_select('\\^' + that.selected_id); + + if(that.acl_select.find('option[id="\\^' + that.selected_id + '"]').length === 0) { + that.update_view('custom'); + } + else { + that.update_select('\\^' + that.selected_id); + } /* jot acl */ $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('fa-unlock').addClass('fa-lock'); -- cgit v1.2.3 From b5ab77908e357b027a9298e0258f3c0737f3c721 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 17 Nov 2020 09:09:36 +0000 Subject: implement submit on ctrl-enter for post editor and comments --- view/js/main.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 560868046..3dae45cff 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -56,7 +56,7 @@ $.ajaxSetup({cache: false}); $(document).ready(function() { - $(document).on('click focus', '.comment-edit-form', handle_comment_form); + $(document).on('click', '.comment-edit-form', handle_comment_form); $(document).on('click', '.conversation-settings-link', getConversationSettings); $(document).on('click', '#settings_module_ajax_submit', postConversationSettings); @@ -95,7 +95,6 @@ $(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 @@ -244,8 +243,6 @@ $(document).ready(function() { cache_next_page(); }); - - }); function getConversationSettings() { @@ -325,7 +322,8 @@ function handle_comment_form(e) { } // handle click outside of form (close empty forms) - $(document).on('click', function(e) { + $(document).one('click', function(e) { + fields.each(function() { if($(this).val() != '') fields_empty = false; @@ -344,23 +342,30 @@ function handle_comment_form(e) { form.find(':button[type=submit]').prop('title', ''); } }); - + var commentSaveTimer = null; var emptyCommentElm = form.find('.comment-edit-text').attr('id'); var convId = emptyCommentElm.replace('comment-edit-text-',''); - $(document).on('focusout','#' + emptyCommentElm,function(e){ + $('#' + emptyCommentElm).on('focusout',function(e){ if(commentSaveTimer) clearTimeout(commentSaveTimer); commentSaveChanges(convId,true); commentSaveTimer = null; + $('#' + emptyCommentElm).off(); }); - $(document).on('focusin','#' + emptyCommentElm,function(e){ + $('#' + emptyCommentElm).on('focusin', function (e){ commentSaveTimer = setTimeout(function () { commentSaveChanges(convId,false); },10000); }); + $('#' + emptyCommentElm).on('keydown', function (e) { + if (e.ctrlKey && e.keyCode === 13) { + post_comment(convId); + } + }); + function commentSaveChanges(convId, isFinal) { if(typeof isFinal === 'undefined') @@ -379,8 +384,11 @@ function handle_comment_form(e) { } } } + } + + function commentClose(obj, id) { if(obj.value === '') { obj.value = aStr.comment; @@ -1414,7 +1422,7 @@ function post_comment(id) { $(document).unbind( "click.commentOpen"); } if(timer) clearTimeout(timer); - timer = setTimeout(updateInit,1500); + timer = setTimeout(updateInit, 500); } if(data.reload) { window.location.href=data.reload; @@ -1425,6 +1433,8 @@ function post_comment(id) { return false; } + + function preview_comment(id) { $("#comment-preview-inp-" + id).val("1"); $("#comment-edit-preview-" + id).show(); -- cgit v1.2.3 From f2fd12fbe544d5e87680aed98489698b4ca9ddd6 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 18 Nov 2020 09:52:44 +0000 Subject: Do away with auto updates except for our own actions. We might consider to re-implement this for single thread view like eg /display. Instead of calculating scroll positions during updates, keep track of expanded items and set the expanded state when updating - this fixes issue #1488 --- view/js/main.js | 109 +++++++++----------------------------------------------- 1 file changed, 16 insertions(+), 93 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 3dae45cff..f807fb366 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -20,11 +20,11 @@ var pageHasMoreContent = true; var divmore_height = 400; var last_filestorage_id = null; var mediaPlaying = false; -var contentHeightDiff = 0; var liveRecurse = 0; var savedTitle = ''; var followUpPageLoad = false; var window_needs_alert = true; +var expanded_items = []; var sse_bs_active = false; var sse_offset = 0; @@ -207,33 +207,6 @@ $(document).ready(function() { updateInit(); - // Allow folks to stop the ajax page updates with the pause/break key - $(document).keydown(function(event) { - if(event.keyCode == '8') { - var target = event.target || event.srcElement; - if (!/input|textarea/i.test(target.nodeName)) { - return false; - } - } - - if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) { - event.preventDefault(); - if(stopped === false) { - stopped = true; - if (event.ctrlKey) { - totStopped = true; - } - $('#pause').html('pause'); - } else { - unpause(); - } - } else { - if (!totStopped) { - unpause(); - } - } - }); - var e = document.getElementById('content-complete'); if(e) pageHasMoreContent = false; @@ -646,7 +619,8 @@ function updatePageItems(mode, data) { function updateConvItems(mode,data) { - $(document).trigger('hz:updateConvItems'); + if(mode !== 'update') + $(document).trigger('hz:updateConvItems'); if(mode === 'update' || mode === 'replace') { prev = 'threads-begin'; @@ -871,25 +845,16 @@ function scrollToItem() { } function collapseHeight() { - var origContentHeight = Math.ceil($("#region_2").height()); - var cDiff = 0; - var i = 0; - var position = $(window).scrollTop(); $(".wall-item-content, .directory-collapse").each(function() { var orgHeight = $(this).outerHeight(true); + var id = $(this).attr('id') + var open = ((expanded_items.indexOf($(this).attr('id')) === -1) ? false : true); if(orgHeight > divmore_height) { if(! $(this).hasClass('divmore') && $(this).has('div.no-collapse').length == 0) { - - // check if we will collapse some content above the visible content and compensate the diff later - if($(this).offset().top + divmore_height - $(window).scrollTop() + cDiff - ($(".divgrow-showmore").outerHeight() * i) < 65) { - diff = orgHeight - divmore_height; - cDiff = cDiff + diff; - i++; - } - $(this).readmore({ speed: 0, + startOpen: open, heightMargin: 50, collapsedHeight: divmore_height, moreLink: '' + aStr.divgrowmore + '', @@ -899,6 +864,10 @@ function collapseHeight() { if((($(element).offset().top + divmore_height) - $(window).scrollTop()) < 65 ) { $(window).scrollTop($(window).scrollTop() - ($(element).outerHeight(true) - divmore_height)); } + expanded_items = expanded_items.filter(expanded_items => expanded_items !== id); + } + else { + expanded_items.push(id); } } }); @@ -907,15 +876,6 @@ function collapseHeight() { } }); - var collapsedContentHeight = Math.ceil($("#region_2").height()); - contentHeightDiff = liking ? 0 : origContentHeight - collapsedContentHeight; - console.log('collapseHeight() - contentHeightDiff: ' + contentHeightDiff + 'px'); - - if(i && !liking){ - var sval = position - cDiff + ($(".divgrow-showmore").outerHeight() * i); - console.log('collapsed above viewport count: ' + i); - $(window).scrollTop(sval); - } } function updateInit() { @@ -950,12 +910,7 @@ function liveUpdate(notify_id) { if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } - // if auto updates are enabled and a comment box is open, - // prevent live updates until the comment is submitted - - var lockUpdates = (($('.comment-edit-text.expanded').length && (! bParam_static)) ? true : false); - - if(lockUpdates || in_progress || mediaPlaying) { + if(in_progress || mediaPlaying) { if(livetime) { clearTimeout(livetime); } @@ -1057,11 +1012,6 @@ function liveUpdate(notify_id) { scroll_next = false; updateConvItems(update_mode,data); - // adjust scroll position if new content was added above viewport - if(update_mode === 'update' && !justifiedGalleryActive) { - $(window).scrollTop($(window).scrollTop() + $("#region_2").height() - orgHeight + contentHeightDiff); - } - in_progress = false; $('#image_counter').html(''); @@ -1202,7 +1152,6 @@ function justifyPhotosAjax(id) { // trickery. This still could cause confusion if the "like" ajax call // is delayed and updateInit runs before it completes. function dolike(ident, verb) { - unpause(); $('#like-rotator-' + ident.toString()).show(); $.get('like/' + ident.toString() + '?verb=' + verb, updateInit ); liking = 1; @@ -1309,14 +1258,12 @@ function dropItem(url, object) { } function dosubthread(ident) { - unpause(); $('#like-rotator-' + ident.toString()).show(); $.get('subthread/sub/' + ident.toString(), updateInit ); liking = 1; } function dounsubthread(ident) { - unpause(); $('#like-rotator-' + ident.toString()).show(); $.get('subthread/unsub/' + ident.toString(), updateInit ); liking = 1; @@ -1395,18 +1342,18 @@ function submitPoll(id) { function(data) { $.jGrowl(data.message, { sticky: false, theme: ((data.success) ? 'info' : 'notice'), life: 10000 }); if(timer) clearTimeout(timer); - timer = setTimeout(updateInit,1500); + timer = setTimeout(updateInit, 500); } ); } - function post_comment(id) { - unpause(); + commentBusy = true; $('body').css('cursor', 'wait'); $("#comment-preview-inp-" + id).val("0"); + $.post( "item", $("#comment-edit-form-" + id).serialize(), @@ -1430,7 +1377,9 @@ function post_comment(id) { }, "json" ); + return false; + } @@ -1502,13 +1451,6 @@ function preview_mail() { return true; } -function unpause() { - // unpause auto reloads if they are currently stopped - totStopped = false; - stopped = false; - $('#pause').html(''); -} - function bin2hex(s) { // Converts the binary representation of data to hex // @@ -1605,7 +1547,6 @@ function zFormError(elm,x) { } } - $(window).scroll(function () { if(typeof buildCmd == 'function') { // This is a content page with items and/or conversations @@ -1631,22 +1572,6 @@ $(window).scroll(function () { } }); -var chanviewFullSize = false; - -function chanviewFull() { - if(chanviewFullSize) { - chanviewFullSize = false; - $('#chanview-iframe-border').css({ 'position' : 'relative', 'z-index' : '10' }); - $('#remote-channel').css({ 'position' : 'relative' , 'z-index' : '10' }); - } - else { - chanviewFullSize = true; - $('#chanview-iframe-border').css({ 'position' : 'fixed', 'top' : '0', 'left' : '0', 'z-index' : '150001' }); - $('#remote-channel').css({ 'position' : 'fixed', 'top' : '0', 'left' : '0', 'z-index' : '150000' }); - resize_iframe(); - } -} - function addhtmltext(data) { data = h2b(data); addeditortext(data); @@ -1877,8 +1802,6 @@ function sse_bs_notifications(e, replace, followup) { } } - - function sse_handleNotifications(obj, replace, followup) { var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files']; -- cgit v1.2.3 From 791d5098a047adf67b6da705552e64ef966d0453 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 18 Nov 2020 12:28:20 +0000 Subject: fix regression --- view/js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index f807fb366..6d39adc39 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1171,7 +1171,7 @@ function doreply(parent, ident, owner, hint) { var sel = 'wall-item-body-' + ident.toString(); var quote = window.getSelection().toString().trim(); form.find('textarea').val("@{" + owner + "}" + ((($(window.getSelection().anchorNode).closest("#" + sel).attr("id") != sel) || (quote.length === 0))? " " : "\n[quote]" + quote + "[/quote]\n")); - $('#comment-edit-text-' + parent.toString()).focus(); + $('#comment-edit-text-' + parent.toString()).focus().trigger('click'); } function doscroll(parent, hidden) { -- cgit v1.2.3 From 852e456d44d2bffeadd2a22a7d47bb9e2e7f125f Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 18 Nov 2020 20:34:41 +0000 Subject: this is silly but it seems to be required for firefox to stop scrolling in certain conditions --- view/js/main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 6d39adc39..09afb4da4 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -364,7 +364,6 @@ function handle_comment_form(e) { function commentClose(obj, id) { if(obj.value === '') { - obj.value = aStr.comment; $("#comment-edit-text-" + id).removeClass("expanded"); $("#mod-cmnt-wrap-" + id).hide(); $("#comment-tools-" + id).hide(); @@ -619,6 +618,8 @@ function updatePageItems(mode, data) { function updateConvItems(mode,data) { + var scroll_position = $(window).scrollTop(); + if(mode !== 'update') $(document).trigger('hz:updateConvItems'); @@ -750,6 +751,8 @@ function updateConvItems(mode,data) { }); + $(window).scrollTop(scroll_position); + if(followUpPageLoad) sse_bs_counts(); else -- cgit v1.2.3 From 011de75706ddd407cadfde89eec891b17db17211 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 20 Nov 2020 09:14:46 +0000 Subject: returning the rendered html when posting a comment will make the following update (and its implication in mod pubstream) obsolete --- view/js/main.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 09afb4da4..380b2bbf7 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1364,15 +1364,20 @@ function post_comment(id) { if(data.success) { localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); - $("#comment-edit-wrapper-" + id).hide(); - $("#comment-edit-text-" + id).val(''); + //$("#comment-edit-wrapper-" + id).hide(); + + $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); var tarea = document.getElementById("comment-edit-text-" + id); if(tarea) { commentClose(tarea, id); $(document).unbind( "click.commentOpen"); } - if(timer) clearTimeout(timer); - timer = setTimeout(updateInit, 500); + + $('#wall-item-comment-wrapper-' + id).before(data.html); + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + $('body').css('cursor', 'unset'); + //if(timer) clearTimeout(timer); + //timer = setTimeout(updateInit, 500); } if(data.reload) { window.location.href=data.reload; -- cgit v1.2.3 From 4c0a26dbf9fca5358320ad11911aac1d5cc530b3 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 20 Nov 2020 10:45:35 +0000 Subject: move post_comment() handling via ctrl-enter out of handle_comment_form() - to many issues with multiple triggers --- view/js/main.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 380b2bbf7..bd595dbb3 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -56,7 +56,7 @@ $.ajaxSetup({cache: false}); $(document).ready(function() { - $(document).on('click', '.comment-edit-form', handle_comment_form); + $(document).on('click focus', '.comment-edit-form', handle_comment_form); $(document).on('click', '.conversation-settings-link', getConversationSettings); $(document).on('click', '#settings_module_ajax_submit', postConversationSettings); @@ -69,6 +69,13 @@ $(document).ready(function() { this.autocomplete_handled = true; } + + }); + + $(document).on('keydown', '.comment-edit-form textarea.expanded', function (e) { + if (e.ctrlKey && e.keyCode === 13) { + post_comment(this.id.replace('comment-edit-text-','')); + } }); var tf = new Function('n', 's', 'var k = s.split("/")['+aStr['plural_func']+']; return (k ? k : s);'); @@ -280,6 +287,7 @@ function handle_comment_form(e) { // handle clicked form var form = $(this); + var fields = form.find(':input[type=text], textarea'); var fields_empty = true; @@ -294,9 +302,9 @@ function handle_comment_form(e) { form.find(':not(:visible)').show(); } + // handle click outside of form (close empty forms) $(document).one('click', function(e) { - fields.each(function() { if($(this).val() != '') fields_empty = false; @@ -333,12 +341,6 @@ function handle_comment_form(e) { },10000); }); - $('#' + emptyCommentElm).on('keydown', function (e) { - if (e.ctrlKey && e.keyCode === 13) { - post_comment(convId); - } - }); - function commentSaveChanges(convId, isFinal) { if(typeof isFinal === 'undefined') @@ -1174,7 +1176,7 @@ function doreply(parent, ident, owner, hint) { var sel = 'wall-item-body-' + ident.toString(); var quote = window.getSelection().toString().trim(); form.find('textarea').val("@{" + owner + "}" + ((($(window.getSelection().anchorNode).closest("#" + sel).attr("id") != sel) || (quote.length === 0))? " " : "\n[quote]" + quote + "[/quote]\n")); - $('#comment-edit-text-' + parent.toString()).focus().trigger('click'); + $('#comment-edit-text-' + parent.toString()).focus(); } function doscroll(parent, hidden) { -- cgit v1.2.3 From 337d8ea78c2e799257fa4cbaf0ba96bc7c3d05d3 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 20 Nov 2020 14:42:46 +0000 Subject: minor cleanup --- view/js/main.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index bd595dbb3..c6460f356 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1366,20 +1366,18 @@ function post_comment(id) { if(data.success) { localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); - //$("#comment-edit-wrapper-" + id).hide(); - $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); + $('#wall-item-comment-wrapper-' + id).before(data.html); + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + $('body').css('cursor', 'unset'); + commentBusy = false; + var tarea = document.getElementById("comment-edit-text-" + id); if(tarea) { commentClose(tarea, id); - $(document).unbind( "click.commentOpen"); + $(document).off( "click.commentOpen"); } - $('#wall-item-comment-wrapper-' + id).before(data.html); - $('#wall-item-ago-' + data.id + ' .autotime').timeago(); - $('body').css('cursor', 'unset'); - //if(timer) clearTimeout(timer); - //timer = setTimeout(updateInit, 500); } if(data.reload) { window.location.href=data.reload; -- cgit v1.2.3 From 2d4064aca4517eac695ba0f0f3618f4a7f7a08cb Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 20 Nov 2020 20:38:10 +0000 Subject: returning the rendered html when liking a post or comment --- view/js/main.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index c6460f356..133d71863 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -633,12 +633,11 @@ function updateConvItems(mode,data) { } if(mode === 'replace') { - $('.thread-wrapper').remove(); // clear existing content + $('.thread-parent').remove(); // clear existing content } $('.thread-wrapper', data).each(function() { if(this.classList.contains('toplevel_item')) { - var ident = this.id; var convId = ident.replace('thread-wrapper-',''); var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); @@ -1158,7 +1157,21 @@ function justifyPhotosAjax(id) { // is delayed and updateInit runs before it completes. function dolike(ident, verb) { $('#like-rotator-' + ident.toString()).show(); - $.get('like/' + ident.toString() + '?verb=' + verb, updateInit ); + $.get('like/' + ident.toString() + '?verb=' + verb, function (data) { + data = JSON.parse(data); + if(data.success) { + // this is a bit tricky since the top level thread wrapper wraps the whole thread + if($('#thread-wrapper-' + data.id).hasClass('toplevel_item')) { + var wrapper = $('
').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.id).html(wrapper[0].innerHTML); + } + else { + $('#thread-wrapper-' + data.id).replaceWith(data.html); + } + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + liking = 0; + } + }); liking = 1; } -- cgit v1.2.3 From f74cfaec5f48ec37cc1f51e5381a45998ebc70e3 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 21 Nov 2020 10:22:23 +0000 Subject: fix pubstream id issue --- view/js/main.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 133d71863..b7cfb75db 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1146,27 +1146,21 @@ function justifyPhotosAjax(id) { $('#' + id).justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; }); } -// Since our ajax calls are asynchronous, we will give a few -// seconds for the first ajax call (setting like/dislike), then -// run the updater to pick up any changes and display on the page. -// The updater will turn any rotators off when it's done. -// This function will have returned long before any of these -// events have completed and therefore there won't be any -// visible feedback that anything changed without all this -// trickery. This still could cause confusion if the "like" ajax call -// is delayed and updateInit runs before it completes. function dolike(ident, verb) { $('#like-rotator-' + ident.toString()).show(); $.get('like/' + ident.toString() + '?verb=' + verb, function (data) { data = JSON.parse(data); if(data.success) { // this is a bit tricky since the top level thread wrapper wraps the whole thread - if($('#thread-wrapper-' + data.id).hasClass('toplevel_item')) { + if($('#thread-wrapper-' + data.orig_id).hasClass('toplevel_item')) { var wrapper = $('
').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); - $('#wall-item-outside-wrapper-' + data.id).html(wrapper[0].innerHTML); + $('#wall-item-outside-wrapper-' + data.orig_id).html(wrapper[0].innerHTML); + // those were not replaced - swap the id + $('#thread-wrapper-' + data.orig_id).attr('id', 'thread-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).attr('id', 'wall-item-outside-wrapper-' + data.id); } else { - $('#thread-wrapper-' + data.id).replaceWith(data.html); + $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); } $('#wall-item-ago-' + data.id + ' .autotime').timeago(); liking = 0; -- cgit v1.2.3 From 7639157a4907e9dbdffe6dd24f4f687f4cce6f01 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 21 Nov 2020 20:15:05 +0000 Subject: restrict returned html usage to local_channel() until some issues will be worked out --- view/js/main.js | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index b7cfb75db..5b6431858 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1148,24 +1148,30 @@ function justifyPhotosAjax(id) { function dolike(ident, verb) { $('#like-rotator-' + ident.toString()).show(); - $.get('like/' + ident.toString() + '?verb=' + verb, function (data) { - data = JSON.parse(data); - if(data.success) { - // 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 = $('
').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); - $('#wall-item-outside-wrapper-' + data.orig_id).html(wrapper[0].innerHTML); - // those were not replaced - swap the id - $('#thread-wrapper-' + data.orig_id).attr('id', 'thread-wrapper-' + data.id); - $('#wall-item-outside-wrapper-' + data.orig_id).attr('id', 'wall-item-outside-wrapper-' + data.id); - } - else { - $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); + + if(! localUser) { + $.get('like/' + ident.toString() + '?verb=' + verb, updateInit); + } + else { + $.get('like/' + ident.toString() + '?verb=' + verb, function (data) { + data = JSON.parse(data); + if(data.success) { + // 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 = $('
').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).html(wrapper[0].innerHTML); + // those were not replaced - swap the id + $('#thread-wrapper-' + data.orig_id).attr('id', 'thread-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).attr('id', 'wall-item-outside-wrapper-' + data.id); + } + else { + $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); + } + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + liking = 0; } - $('#wall-item-ago-' + data.id + ' .autotime').timeago(); - liking = 0; - } - }); + }); + } liking = 1; } @@ -1374,10 +1380,16 @@ function post_comment(id) { localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); - $('#wall-item-comment-wrapper-' + id).before(data.html); - $('#wall-item-ago-' + data.id + ' .autotime').timeago(); - $('body').css('cursor', 'unset'); - commentBusy = false; + + if(! localUser) { + updateInit(); + } + else { + $('#wall-item-comment-wrapper-' + id).before(data.html); + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + $('body').css('cursor', 'unset'); + commentBusy = false; + } var tarea = document.getElementById("comment-edit-text-" + id); if(tarea) { -- cgit v1.2.3 From 6c94bbc93fcdbcb729e119bea55f87b5334f650f Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 21 Nov 2020 20:52:38 +0000 Subject: collase the updated content --- view/js/main.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 5b6431858..0bc4261f5 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1168,6 +1168,7 @@ function dolike(ident, verb) { $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); } $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + collapseHeight(); liking = 0; } }); @@ -1388,6 +1389,7 @@ function post_comment(id) { $('#wall-item-comment-wrapper-' + id).before(data.html); $('#wall-item-ago-' + data.id + ' .autotime').timeago(); $('body').css('cursor', 'unset'); + collapseHeight(); commentBusy = false; } -- cgit v1.2.3 From c0adf31da9a0d8f897dc68ab632c736891318ad5 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 22 Nov 2020 13:07:03 +0000 Subject: fix like issue with remote channels --- view/js/main.js | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 0bc4261f5..4c8cd0adf 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1149,30 +1149,28 @@ function justifyPhotosAjax(id) { function dolike(ident, verb) { $('#like-rotator-' + ident.toString()).show(); - if(! localUser) { - $.get('like/' + ident.toString() + '?verb=' + verb, updateInit); - } - else { - $.get('like/' + ident.toString() + '?verb=' + verb, function (data) { - data = JSON.parse(data); - if(data.success) { - // 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 = $('
').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); - $('#wall-item-outside-wrapper-' + data.orig_id).html(wrapper[0].innerHTML); - // those were not replaced - swap the id - $('#thread-wrapper-' + data.orig_id).attr('id', 'thread-wrapper-' + data.id); - $('#wall-item-outside-wrapper-' + data.orig_id).attr('id', 'wall-item-outside-wrapper-' + data.id); - } - else { - $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); - } - $('#wall-item-ago-' + data.id + ' .autotime').timeago(); - collapseHeight(); - liking = 0; + if(typeof conv_mode == typeof undefined) + conv_mode = ''; + + $.get('like/' + ident.toString() + '?verb=' + verb + '&conv_mode=' + conv_mode, function (data) { + data = JSON.parse(data); + if(data.success) { + // 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 = $('
').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).html(wrapper[0].innerHTML); + // those were not replaced - swap the id + $('#thread-wrapper-' + data.orig_id).attr('id', 'thread-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).attr('id', 'wall-item-outside-wrapper-' + data.id); } - }); - } + else { + $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); + } + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + collapseHeight(); + liking = 0; + } + }); liking = 1; } -- cgit v1.2.3 From 451468d1297ba41a6c9ea29709444ceb15185bfb Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 22 Nov 2020 16:37:20 +0000 Subject: fix mod item issue with remote channels --- view/js/main.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 4c8cd0adf..35b03e03b 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1371,25 +1371,25 @@ function post_comment(id) { $('body').css('cursor', 'wait'); $("#comment-preview-inp-" + id).val("0"); + if(typeof conv_mode == typeof undefined) + conv_mode = ''; + + var form_data = $("#comment-edit-form-" + id).serialize(); + $.post( "item", - $("#comment-edit-form-" + id).serialize(), + form_data + '&conv_mode=' + conv_mode, function(data) { if(data.success) { + localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); - - if(! localUser) { - updateInit(); - } - else { - $('#wall-item-comment-wrapper-' + id).before(data.html); - $('#wall-item-ago-' + data.id + ' .autotime').timeago(); - $('body').css('cursor', 'unset'); - collapseHeight(); - commentBusy = false; - } + $('#wall-item-comment-wrapper-' + id).before(data.html); + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + $('body').css('cursor', 'unset'); + collapseHeight(); + commentBusy = false; var tarea = document.getElementById("comment-edit-text-" + id); if(tarea) { -- cgit v1.2.3 From 34d54fd3099217ccabcd812b1883ee7882caad77 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 23 Nov 2020 19:57:28 +0000 Subject: simplify code and fix issue with categories --- view/js/main.js | 1 - 1 file changed, 1 deletion(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 35b03e03b..d39e22b1a 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1153,7 +1153,6 @@ function dolike(ident, verb) { conv_mode = ''; $.get('like/' + ident.toString() + '?verb=' + verb + '&conv_mode=' + conv_mode, function (data) { - data = JSON.parse(data); if(data.success) { // this is a bit tricky since the top level thread wrapper wraps the whole thread if($('#thread-wrapper-' + data.orig_id).hasClass('toplevel_item')) { -- cgit v1.2.3 From 4419c93d8062794e5c2bbc222699881e5b97fc99 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 26 Nov 2020 07:58:57 +0000 Subject: this should not be required anymore --- view/js/main.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index d39e22b1a..ca82e3101 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1380,7 +1380,6 @@ function post_comment(id) { form_data + '&conv_mode=' + conv_mode, function(data) { if(data.success) { - localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); @@ -1395,10 +1394,6 @@ function post_comment(id) { commentClose(tarea, id); $(document).off( "click.commentOpen"); } - - } - if(data.reload) { - window.location.href=data.reload; } }, "json" -- cgit v1.2.3 From 2a154f8c9a772d61e7dabb5e3fd110ba00cc6007 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 14 Dec 2020 11:02:20 +0000 Subject: merge branch files_ng into dev --- view/js/acl.js | 4 +- view/js/main.js | 83 +++++----- view/js/mod_cloud.js | 441 ++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 366 insertions(+), 162 deletions(-) (limited to 'view/js') diff --git a/view/js/acl.js b/view/js/acl.js index 940fdaa44..ee6cb062f 100644 --- a/view/js/acl.js +++ b/view/js/acl.js @@ -30,7 +30,7 @@ function ACL(backend_url) { that.custom = $("#acl-custom"); that.acl_select = $("#acl-select"); - // set the initial ACL lists in case the enclosing form gets submitted before the ajax loader completes. + // set the initial ACL lists in case the enclosing form gets submitted before the ajax loader completes. //that.on_submit(); /*events*/ @@ -90,7 +90,7 @@ ACL.prototype.get_form_data = function(event) { } -// no longer called only on submit - call to update whenever a change occurs to the acl list. +// no longer called only on submit - call to update whenever a change occurs to the acl list. ACL.prototype.on_submit = function() { $('.acl-field').remove(); diff --git a/view/js/main.js b/view/js/main.js index ca82e3101..7df705603 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -44,7 +44,7 @@ if(localStorage.getItem('uid') !== localUser.toString()) { window.onstorage = function(e) { if(e.key === 'uid' && parseInt(e.newValue) !== localUser) { if(window_needs_alert) { - window_needs_alert = false; + window_needs_alert = false; alert("Your identity has changed. Page reload required!"); window.location.reload(); return; @@ -99,12 +99,12 @@ $(document).ready(function() { wordSeparator : aStr['t16'], numbers : aStr['t17'], }; - + 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 + // notifications with multiple tabs open will not work very well in this scenario var evtSource = new EventSource('/sse'); evtSource.addEventListener('notifications', function(e) { @@ -298,7 +298,7 @@ function handle_comment_form(e) { $('#' + commentElm).addClass('expanded').removeAttr('placeholder'); $('#' + commentElm).attr('tabindex','9'); $('#' + submitElm).attr('tabindex','10'); - + form.find(':not(:visible)').show(); } @@ -452,7 +452,7 @@ function insertCommentAttach(comment,id) { $('body').css('cursor', 'wait'); $('#invisible-comment-upload').trigger('click'); - + return false; } @@ -631,7 +631,7 @@ function updateConvItems(mode,data) { if(mode === 'append') { next = 'threads-end'; } - + if(mode === 'replace') { $('.thread-parent').remove(); // clear existing content } @@ -652,7 +652,7 @@ function updateConvItems(mode,data) { if($('#collapsed-comments-'+itmId).is(':visible')) isVisible = true; - // insert the content according to the mode and first_page + // insert the content according to the mode and first_page // and whether or not the content exists already (overwrite it) if($('#' + ident).length == 0) { @@ -765,7 +765,7 @@ function updateConvItems(mode,data) { } // Setup to determine if the media player is playing. This affects - // some content loading decisions. + // some content loading decisions. $('video').off('playing'); $('video').off('pause'); @@ -1253,24 +1253,25 @@ function dopin(id) { } function dropItem(url, object) { + var confirm = confirmDelete(); + if(confirm) { + var id = url.split('/')[2]; + $('body').css('cursor', 'wait'); + $(object + ', #pinned-wrapper-' + id).css('opacity', 0.33); - var confirm = confirmDelete(); - if(confirm) { - var id = url.split('/')[2]; - $('body').css('cursor', 'wait'); - $(object + ', #pinned-wrapper-' + id).fadeTo('fast', 0.33, function () { - $.get(url).done(function() { - $(object + ', #pinned-wrapper-' + id).remove(); - $('body').css('cursor', 'auto'); - }); - }); - if($('#wall-item-pinned-' + id).length) - $.post('pin/pin', { 'id' : id }); - return true; - } - else { - return false; + $.get(url, function() { + $(object + ', #pinned-wrapper-' + id).remove(); + $('body').css('cursor', 'auto'); + }); + + if($('#wall-item-pinned-' + id).length) + $.post('pin/pin', { 'id' : id }); + + return true; } + else { + return false; + } } function dosubthread(ident) { @@ -1339,18 +1340,6 @@ function lockview(type, id) { }); } -function filestorage(event, nick, id) { - $('#cloud-index-' + last_filestorage_id).removeClass('cloud-index-active'); - $('#perms-panel-' + last_filestorage_id).hide().html(''); - $('#file-edit-' + id).show(); - $.get('filestorage/' + nick + '/' + id + '/edit', function(data) { - $('#cloud-index-' + id).addClass('cloud-index-active'); - $('#perms-panel-' + id).html(data).show(); - $('#file-edit-' + id).hide(); - last_filestorage_id = id; - }); -} - function submitPoll(id) { $.post('vote/' + id, @@ -1473,17 +1462,17 @@ function preview_mail() { } 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' + // 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; diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 031895caf..7f2bdfab7 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -3,22 +3,341 @@ */ $(document).ready(function () { + // call initialization file if (window.File && window.FileList && window.FileReader) { UploadInit(); } + + var attach_drop_id; + var attach_draging; + + // Per File Tools + + $('.cloud-tool-perms-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + }); + + $('.cloud-tool-rename-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + $('#cloud-tool-rename-' + id).show(); + }); + + $('.cloud-tool-move-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + $('#cloud-tool-move-' + id).show(); + }); + + $('.cloud-tool-categories-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + $('#id_categories_' + id).tagsinput({ + tagClass: 'badge badge-pill badge-warning text-dark' + }); + $('#cloud-tool-categories-' + id).show(); + }); + + $('.cloud-tool-download-btn').on('click', function (e) { + close_and_deactivate_all_panels(); + }); + + $('.cloud-tool-delete-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + + close_and_deactivate_all_panels(); + + let confirm = confirmDelete(); + if (confirm) { + $('body').css('cursor', 'wait'); + $('#cloud-index-' + id).css('opacity', 0.33); + + let form = $('#attach_edit_form_' + id).serializeArray(); + form.push({name: 'delete', value: 1}); + + $.post('attach_edit', form, function (data) { + if (data.success) { + $('#cloud-index-' + id + ', #cloud-tools-' + id).remove(); + $('body').css('cursor', 'auto'); + } + return true; + }); + + } + return false; + }); + + $('.cloud-tool-cancel-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + close_and_deactivate_all_panels(); + $('#attach_edit_form_' + id).trigger('reset'); + $('#id_categories_' + id).tagsinput('destroy'); + }); + + // Per File Tools Eend + + // DnD + + $(document).on('drop', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $(document).on('dragover', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $(document).on('dragleave', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $('.cloud-index.attach-drop').on('drop', function (e) { + + let target = $(this); + let folder = target.data('folder'); + let id = target.data('id'); + + + if(typeof folder === typeof undefined) { + return false; + } + + // Check if it's a file + if (e.dataTransfer.files[0]) { + $('#file-folder').val(folder); + return true; + } + + if(id === attach_drop_id) { + return false; + } + + if(target.hasClass('attach-drop-zone') && attach_draging) { + return false; + } + + target.removeClass('attach-drop-ok'); + + $.post('attach_edit', {'channel_id': channelId, 'dnd': 1, 'attach_id': attach_drop_id, ['newfolder_' + attach_drop_id]: folder }, function (data) { + if (data.success) { + $('#cloud-index-' + attach_drop_id + ', #cloud-tools-' + attach_drop_id).remove(); + attach_drop_id = null; + } + }); + }); + + $('.cloud-index.attach-drop').on('dragover', function (e) { + let target = $(this); + + if(target.hasClass('attach-drop-zone') && attach_draging) { + return false; + } + + target.addClass('attach-drop-ok'); + }); + + $('.cloud-index').on('dragleave', function (e) { + let target = $(this); + target.removeClass('attach-drop-ok'); + }); + + $('.cloud-index').on('dragstart', function (e) { + let target = $(this); + attach_drop_id = target.data('id'); + // dragstart is not fired if a file is draged onto the window + // we use this to distinguish between drags and file drops + attach_draging = true; + }); + + $('.cloud-index').on('dragend', function (e) { + let target = $(this); + target.removeClass('attach-drop-ok'); + attach_draging = false; + }); + + // DnD End + + // Multi Tools + + $('#cloud-multi-tool-select-all').on('change', function (e) { + if ($(this).is(':checked')) { + $('.cloud-multi-tool-checkbox').prop('checked', true); + $('.cloud-index:not(#cloud-index-up)').addClass('cloud-index-selected cloud-index-active'); + $('.cloud-tools').addClass('cloud-index-selected'); + } + else { + $('.cloud-multi-tool-checkbox').prop('checked', false); + $('.cloud-index').removeClass('cloud-index-selected cloud-index-active'); + $('.cloud-tools').removeClass('cloud-index-selected'); + } + + $('.cloud-multi-tool-checkbox').trigger('change'); + }); + + + $('.cloud-multi-tool-checkbox').on('change', function (e) { + let id = $(this).val(); + + if ($(this).is(':checked')) { + $('#cloud-index-' + id).addClass('cloud-index-selected cloud-index-active'); + $('#cloud-tools-' + id).addClass('cloud-index-selected'); + $('').prependTo('#attach_multi_edit_form'); + } + else { + $('#cloud-index-' + id).removeClass('cloud-index-selected cloud-index-active'); + $('#cloud-tools-' + id).removeClass('cloud-index-selected'); + if ($('#cloud-multi-tool-select-all').is(':checked')) + $('#cloud-multi-tool-select-all').prop('checked', false); + + $('#aid_' + id).remove(); + } + + if($('.cloud-multi-tool-checkbox:checked').length) { + close_all_panels(); + $('#cloud-multi-actions').addClass('bg-warning'); + $('#multi-dropdown-button').fadeIn(); + } + else { + $('#cloud-multi-actions').removeClass('bg-warning'); + $('#multi-dropdown-button').fadeOut(); + close_and_deactivate_all_panels(); + disable_multi_acl(); + } + + }); + + $('#cloud-multi-tool-perms-btn').on('click', function (e) { + e.preventDefault(); + + close_all_panels(); + enable_multi_acl(); + + $('#cloud-multi-tool-submit').show(); + }); + + $('#cloud-multi-tool-move-btn').on('click', function (e) { + e.preventDefault(); + + close_all_panels(); + disable_multi_acl(); + + $('#cloud-multi-tool-submit, #cloud-multi-tool-move').show(); + }); + + $('#cloud-multi-tool-categories-btn').on('click', function (e) { + e.preventDefault(); + + close_all_panels(); + disable_multi_acl(); + + $('#id_categories').tagsinput({ + tagClass: 'badge badge-pill badge-warning text-dark' + }); + + $('#cloud-multi-tool-submit, #cloud-multi-tool-categories').show(); + }); + + $('#cloud-multi-tool-delete-btn').on('click', function (e) { + e.preventDefault(); + + let post_data = $('.cloud-multi-tool-checkbox').serializeArray(); + + if(! post_data.length) { + return false; + } + let confirm = confirmDelete(); + if (confirm) { + $('body').css('cursor', 'wait'); + $('.cloud-index-selected').css('opacity', 0.33); + + post_data.push( + { name: 'channel_id', value: channelId }, + { name: 'delete', value: 1}, + ); + + $.post('attach_edit', post_data, function (data) { + if (data.success) { + console.log(data); + $('.cloud-index-selected').remove(); + $('body').css('cursor', 'auto'); + } + return true; + }); + } + return false; + + }); + + $('.cloud-multi-tool-cancel-btn').on('click', function (e) { + e.preventDefault(); + + close_and_deactivate_all_panels(); + disable_multi_acl(); + + $('#attach_multi_edit_form').trigger('reset'); + $('#id_categories').tagsinput('destroy'); + }); + + // Multi Tools End + + // Helper Functions + + function disable_multi_acl() { + $('#multi-perms').val(0); + $('#multi-dbtn-acl, #recurse_container').hide(); + $('#attach-multi-edit-perms').removeClass('btn-group'); + } + + function enable_multi_acl() { + $('#multi-perms').val(1); + $('#multi-dbtn-acl, #recurse_container').show(); + $('#attach-multi-edit-perms').addClass('btn-group'); + } + + function close_all_panels() { + $('.cloud-tool, .cloud-multi-tool').hide(); + } + + function deactivate_all_panels() { + $('.cloud-index').removeClass('cloud-index-active'); + } + + function close_and_deactivate_all_panels() { + close_all_panels(); + deactivate_all_panels(); + } + + function activate_id(id) { + close_and_deactivate_all_panels(); + $('#cloud-multi-tool-select-all, .cloud-multi-tool-checkbox').prop('checked', false).trigger('change'); + + $('#cloud-tool-submit-' + id).show(); + $('#cloud-index-' + id).addClass('cloud-index-active'); + $('#cloud-tool-submit-' + id).show(); + } + }); -// + + + // initialize function UploadInit() { - var fileselect = $("#files-upload"); - var filedrag = $("#cloud-drag-area"); var submit = $("#upload-submit"); var count = 1; + var filedrag = $(".cloud-index.attach-drop"); - $('#invisible-cloud-file-upload').fileupload({ url: 'file_upload', dataType: 'json', @@ -26,8 +345,8 @@ function UploadInit() { maxChunkSize: 4 * 1024 * 1024, add: function(e,data) { - $(data.files).each( function() { this.count = ++ count; prepareHtml(this); }); - + $(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') || []); @@ -49,7 +368,6 @@ function UploadInit() { }); data.formData = $('#ajax-upload-files').serializeArray(); - data.submit(); }, @@ -58,7 +376,7 @@ function UploadInit() { // there will only be one file, the one we are looking for - $(data.files).each( function() { + $(data.files).each( function() { var idx = this.count; // Dynamically update the percentage complete displayed in the file upload list @@ -70,7 +388,6 @@ function UploadInit() { }, - stop: function(e,data) { window.location.href = window.location.href; } @@ -81,60 +398,17 @@ function UploadInit() { } -// 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 === 'upload-submit') { - e.preventDefault(); - var files = e.data[0].files; - } - if(e.target.id === 'files-upload') { - $('.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 === 'files-upload') - prepareHtml(f, i); - if(e.target.id === 'upload-submit') { - UploadFile(f, i); - } - } -} function prepareHtml(f) { var num = f.count - 1; var i = f.count; $('#cloud-index #new-upload-progress-bar-' + num.toString()).after( '' + + '' + '' + '' + f.name + '' + - '' + + '' + '' + formatSizeUnits(f.size) + '' + '' + '' + @@ -199,63 +473,4 @@ 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('ERROR'); - }); - - // POST to the entire cloud path -// xhr.open('post', 'file_upload', true); - -// var formfields = $("#ajax-upload-files").serializeArray(); - -// var data = new FormData(); -// $.each(formfields, function(i, field) { -// data.append(field.name, field.value); -// }); -// data.append('userfile', file); - -// xhr.send(data); -} -- cgit v1.2.3 From b4b566318a0e52b6396445ddc21c20c0abcc8ce4 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 16 Dec 2020 16:57:56 +0000 Subject: files_ng: fix regression in finding the right path in certain situations and add a info panel with attach and zrl bbcode --- view/js/mod_cloud.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 7f2bdfab7..cbd9c2a08 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -14,6 +14,14 @@ $(document).ready(function () { // Per File Tools + $('.cloud-tool-info-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + close_and_deactivate_all_panels(); + $('#cloud-tool-info-' + id).toggle(); + $('#cloud-index-' + id).addClass('cloud-index-active'); + }); + $('.cloud-tool-perms-btn').on('click', function (e) { e.preventDefault(); let id = $(this).data('id'); @@ -323,7 +331,6 @@ $(document).ready(function () { $('#cloud-tool-submit-' + id).show(); $('#cloud-index-' + id).addClass('cloud-index-active'); - $('#cloud-tool-submit-' + id).show(); } }); @@ -406,7 +413,7 @@ function prepareHtml(f) { $('#cloud-index #new-upload-progress-bar-' + num.toString()).after( '' + '' + - '' + + '' + '' + f.name + '' + '' + '' + formatSizeUnits(f.size) + '' + -- cgit v1.2.3 From 8640e6d1df1004191a1cac9a2d894c73aa06f84a Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 18 Dec 2020 13:26:51 +0000 Subject: deprecate ! and !! forum tags --- view/js/autocomplete.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 27011b4d4..dc757d5c8 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -171,6 +171,7 @@ function string2bb(element) { template: contact_format }; +/* // Autocomplete forums forums = { match: /(^|\s)(\!\!*)([^ \n]{2,})$/, @@ -180,7 +181,7 @@ function string2bb(element) { replace: editor_replace, template: contact_format }; - +*/ // Autocomplete hashtags tags = { -- cgit v1.2.3 From d118ab71e6aa4f300ba6e42663d13a63a2323122 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 21 Dec 2020 21:37:10 +0000 Subject: files_ng: implement directory and bulk file download --- view/js/mod_cloud.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index cbd9c2a08..736dec471 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -56,6 +56,24 @@ $(document).ready(function () { close_and_deactivate_all_panels(); }); + $('.cloud-tool-dir-download-btn').on('click', function (e) { + e.preventDefault(); + close_and_deactivate_all_panels() + + let id = $(this).data('id'); + if(! id) { + return false; + } + + close_and_deactivate_all_panels(); + + // some trickery to trigger download action via ajax + let form = $('
').attr('action', 'attach').attr('method', 'post'); + form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); + form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', id)); + form.appendTo('body').submit().remove(); + }); + $('.cloud-tool-delete-btn').on('click', function (e) { e.preventDefault(); let id = $(this).data('id'); @@ -255,14 +273,37 @@ $(document).ready(function () { $('#cloud-multi-tool-submit, #cloud-multi-tool-categories').show(); }); + $('#cloud-multi-tool-download-btn').on('click', function (e) { + e.preventDefault(); + + let post_data = $('.cloud-multi-tool-checkbox:checked'); + + if(! post_data.length) { + return false; + } + + close_and_deactivate_all_panels(); + + // some trickery to trigger download action via ajax + var form = $('
').attr('action', 'attach').attr('method', 'post'); + form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); + post_data.each(function () { + form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', this.value)); + }); + form.appendTo('body').submit().remove(); + }); + $('#cloud-multi-tool-delete-btn').on('click', function (e) { e.preventDefault(); - let post_data = $('.cloud-multi-tool-checkbox').serializeArray(); + close_and_deactivate_all_panels(); + + let post_data = $('.cloud-multi-tool-checkbox:checked').serializeArray(); if(! post_data.length) { return false; } + let confirm = confirmDelete(); if (confirm) { $('body').css('cursor', 'wait'); -- cgit v1.2.3 From 60cbb65d84cdc2854bdcf1613cf67180878c44dd Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 22 Dec 2020 09:01:52 +0000 Subject: files_ng: omit parent folders of a download --- view/js/mod_cloud.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 736dec471..516284d9b 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -69,6 +69,7 @@ $(document).ready(function () { // some trickery to trigger download action via ajax let form = $('
').attr('action', 'attach').attr('method', 'post'); + form.append($("").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname)); form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', id)); form.appendTo('body').submit().remove(); @@ -286,6 +287,7 @@ $(document).ready(function () { // some trickery to trigger download action via ajax var form = $('
').attr('action', 'attach').attr('method', 'post'); + form.append($("").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname)); form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); post_data.each(function () { form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', this.value)); -- cgit v1.2.3 From 3a38292bab234e531e0bda6055325d0e1eed37de Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 22 Dec 2020 13:23:20 +0000 Subject: =?UTF-8?q?files=5Fng:=20improve=20download=20handl=C3=83ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/js/mod_cloud.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 516284d9b..35a28d3b9 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -67,12 +67,21 @@ $(document).ready(function () { close_and_deactivate_all_panels(); - // some trickery to trigger download action via ajax - let form = $('
').attr('action', 'attach').attr('method', 'post'); - form.append($("").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname)); - form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); - form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', id)); - form.appendTo('body').submit().remove(); + $('body').css('cursor', 'wait'); + + let data = [ + {name: 'attach_path', value: window.location.pathname}, + {name: 'channel_id', value: channelId}, + {name: 'attach_ids[]', value: id} + ] + + $.post('attach', data, function (data) { + if (data.success) { + $('body').css('cursor', 'auto'); + window.location.href = '/attach/download?token=' + data.token; + } + }); + }); $('.cloud-tool-delete-btn').on('click', function (e) { @@ -277,7 +286,7 @@ $(document).ready(function () { $('#cloud-multi-tool-download-btn').on('click', function (e) { e.preventDefault(); - let post_data = $('.cloud-multi-tool-checkbox:checked'); + let post_data = $('.cloud-multi-tool-checkbox:checked').serializeArray(); if(! post_data.length) { return false; @@ -285,6 +294,20 @@ $(document).ready(function () { close_and_deactivate_all_panels(); + $('body').css('cursor', 'wait'); + + post_data.push( + {name: 'attach_path', value: window.location.pathname}, + {name: 'channel_id', value: channelId}, + ); + + $.post('attach', post_data, function (data) { + if (data.success) { + $('body').css('cursor', 'auto'); + window.location.href = '/attach/download?token=' + data.token; + } + }); +/* // some trickery to trigger download action via ajax var form = $('
').attr('action', 'attach').attr('method', 'post'); form.append($("").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname)); @@ -293,6 +316,7 @@ $(document).ready(function () { form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', this.value)); }); form.appendTo('body').submit().remove(); +*/ }); $('#cloud-multi-tool-delete-btn').on('click', function (e) { -- cgit v1.2.3 From 7ee2192c29ea3da08fe2c6ba361388eb6e3a6877 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 22 Dec 2020 13:33:54 +0000 Subject: provide some info and remove unused code --- view/js/mod_cloud.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 35a28d3b9..5e7740264 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -68,6 +68,7 @@ $(document).ready(function () { close_and_deactivate_all_panels(); $('body').css('cursor', 'wait'); + $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); let data = [ {name: 'attach_path', value: window.location.pathname}, @@ -295,6 +296,7 @@ $(document).ready(function () { close_and_deactivate_all_panels(); $('body').css('cursor', 'wait'); + $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); post_data.push( {name: 'attach_path', value: window.location.pathname}, @@ -307,16 +309,7 @@ $(document).ready(function () { window.location.href = '/attach/download?token=' + data.token; } }); -/* - // some trickery to trigger download action via ajax - var form = $('
').attr('action', 'attach').attr('method', 'post'); - form.append($("").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname)); - form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); - post_data.each(function () { - form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', this.value)); - }); - form.appendTo('body').submit().remove(); -*/ + }); $('#cloud-multi-tool-delete-btn').on('click', function (e) { -- cgit v1.2.3 From 9fa3dee522b2dc967e23d3543750a877a0c60c15 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 23 Dec 2020 08:19:11 +0000 Subject: remove deprecated forum autocomplete code --- view/js/autocomplete.js | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'view/js') diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index dc757d5c8..92db42f6d 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -171,18 +171,6 @@ function string2bb(element) { template: contact_format }; -/* - // Autocomplete forums - forums = { - match: /(^|\s)(\!\!*)([^ \n]{2,})$/, - index: 3, - cache: true, - search: function(term, callback) { contact_search(term, callback, backend_url, 'f', extra_channels, spinelement=false); }, - replace: editor_replace, - template: contact_format - }; -*/ - // Autocomplete hashtags tags = { match: /(^|\s)(\#)([^ \n]{2,})$/, @@ -194,7 +182,6 @@ function string2bb(element) { template: tag_format }; - smilies = { match: /(^|\s)(:[a-z0-9_:]{2,})$/, index: 2, @@ -215,7 +202,7 @@ function string2bb(element) { maxCount: 100 } }); - textcomplete.register([contacts,forums,smilies,tags]); + textcomplete.register([contacts,smilies,tags]); }); }; })( jQuery ); @@ -239,16 +226,6 @@ function string2bb(element) { template: contact_format, }; - // Autocomplete forums - forums = { - match: /(^\!)([^\n]{2,})$/, - index: 2, - cache: true, - search: function(term, callback) { contact_search(term, callback, backend_url, 'f', [], spinelement='#nav-search-spinner'); }, - replace: basic_replace, - template: contact_format - }; - // Autocomplete hashtags tags = { match: /(^\#)([^ \n]{2,})$/, @@ -272,7 +249,7 @@ function string2bb(element) { maxCount: 100 } }); - textcomplete.register([contacts,forums,tags]); + textcomplete.register([contacts,tags]); }); textcomplete.on('selected', function() { this.editor.el.form.submit(); }); -- cgit v1.2.3 From d56bf34326cec24b8d6ad72f77543f4722788ef6 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 23 Dec 2020 08:22:31 +0000 Subject: fix javascript warning --- view/js/mod_cloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 5e7740264..aa9d308eb 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -150,7 +150,7 @@ $(document).ready(function () { } // Check if it's a file - if (e.dataTransfer.files[0]) { + if (typeof e.dataTransfer !== typeof undefined && e.dataTransfer.files[0]) { $('#file-folder').val(folder); return true; } -- cgit v1.2.3 From 9670833a5ddc3c24343202fda6f29875e9b3b10b Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 28 Dec 2020 10:12:25 +0000 Subject: files_ng: provide a fallback in case the server timed out on compressing the zip file --- view/js/main.js | 10 ++++++++++ view/js/mod_cloud.js | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index 7df705603..3e3fd057c 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1997,3 +1997,13 @@ function sse_fallback() { 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 aa9d308eb..aeaac8c69 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -70,8 +70,11 @@ $(document).ready(function () { $('body').css('cursor', 'wait'); $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); + var download_token = makeid(32); + let data = [ {name: 'attach_path', value: window.location.pathname}, + {name: 'download_token', value: download_token}, {name: 'channel_id', value: channelId}, {name: 'attach_ids[]', value: id} ] @@ -79,10 +82,22 @@ $(document).ready(function () { $.post('attach', data, function (data) { if (data.success) { $('body').css('cursor', 'auto'); - window.location.href = '/attach/download?token=' + data.token; + window.location.href = '/attach/download?token=' + data.token + '&download_token=' + download_token; + clearInterval(fallback); } }); + // fallback if server timed out + + var fallback = setInterval(function(){ $.get('/attach/check?download_token=' + download_token, function(data){ + if (data.success) { + $('body').css('cursor', 'auto'); + window.location.href = '/attach/download?token=' + data.token; + clearInterval(fallback); + } + + }); }, 30000); + }); $('.cloud-tool-delete-btn').on('click', function (e) { @@ -298,18 +313,34 @@ $(document).ready(function () { $('body').css('cursor', 'wait'); $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); + var download_token = makeid(32); + post_data.push( {name: 'attach_path', value: window.location.pathname}, + {name: 'download_token', value: download_token}, {name: 'channel_id', value: channelId}, ); $.post('attach', post_data, function (data) { if (data.success) { $('body').css('cursor', 'auto'); - window.location.href = '/attach/download?token=' + data.token; + window.location.href = '/attach/download?token=' + data.token + '&download_token=' + download_token; + clearInterval(fallback); } }); + // fallback if server timed out + + var fallback = setInterval(function(){ $.get('/attach/check?download_token=' + download_token, function(data){ + if (data.success) { + $('body').css('cursor', 'auto'); + window.location.href = '/attach/download?token=' + data.token; + clearInterval(fallback); + } + + }); }, 30000); + + }); $('#cloud-multi-tool-delete-btn').on('click', function (e) { -- cgit v1.2.3 From 8db367c74353f2b86d0effeebfe84c7cc4f512ab Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 30 Dec 2020 14:30:39 +0000 Subject: remove fallback code - it will not be required if compression is dismissed --- view/js/mod_cloud.js | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index aeaac8c69..8fb66c5aa 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -70,33 +70,18 @@ $(document).ready(function () { $('body').css('cursor', 'wait'); $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); - var download_token = makeid(32); - let data = [ {name: 'attach_path', value: window.location.pathname}, - {name: 'download_token', value: download_token}, {name: 'channel_id', value: channelId}, {name: 'attach_ids[]', value: id} ] $.post('attach', data, function (data) { - if (data.success) { - $('body').css('cursor', 'auto'); - window.location.href = '/attach/download?token=' + data.token + '&download_token=' + download_token; - clearInterval(fallback); - } - }); - - // fallback if server timed out - - var fallback = setInterval(function(){ $.get('/attach/check?download_token=' + download_token, function(data){ if (data.success) { $('body').css('cursor', 'auto'); window.location.href = '/attach/download?token=' + data.token; - clearInterval(fallback); } - - }); }, 30000); + }); }); @@ -313,33 +298,17 @@ $(document).ready(function () { $('body').css('cursor', 'wait'); $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); - var download_token = makeid(32); - post_data.push( {name: 'attach_path', value: window.location.pathname}, - {name: 'download_token', value: download_token}, - {name: 'channel_id', value: channelId}, + {name: 'channel_id', value: channelId} ); $.post('attach', post_data, function (data) { - if (data.success) { - $('body').css('cursor', 'auto'); - window.location.href = '/attach/download?token=' + data.token + '&download_token=' + download_token; - clearInterval(fallback); - } - }); - - // fallback if server timed out - - var fallback = setInterval(function(){ $.get('/attach/check?download_token=' + download_token, function(data){ if (data.success) { $('body').css('cursor', 'auto'); window.location.href = '/attach/download?token=' + data.token; - clearInterval(fallback); } - - }); }, 30000); - + }); }); -- cgit v1.2.3 From cff5859c595ae3d758072b11aa60190e210cb490 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 3 Jan 2021 14:28:02 +0000 Subject: mod cloud strings --- view/js/mod_cloud.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 8fb66c5aa..5ca1f52a9 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -68,7 +68,7 @@ $(document).ready(function () { close_and_deactivate_all_panels(); $('body').css('cursor', 'wait'); - $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); + $.jGrowl(aStr.download_info, { sticky: false, theme: 'info', life: 10000 }); let data = [ {name: 'attach_path', value: window.location.pathname}, @@ -296,7 +296,7 @@ $(document).ready(function () { close_and_deactivate_all_panels(); $('body').css('cursor', 'wait'); - $.jGrowl('Please stand by while your download is being prepared...', { sticky: false, theme: 'info', life: 10000 }); + $.jGrowl(aStr.download_info, { sticky: false, theme: 'info', life: 10000 }); post_data.push( {name: 'attach_path', value: window.location.pathname}, -- cgit v1.2.3