diff options
Diffstat (limited to 'p/scripts/global_view.js')
| -rw-r--r-- | p/scripts/global_view.js | 128 |
1 files changed, 74 insertions, 54 deletions
diff --git a/p/scripts/global_view.js b/p/scripts/global_view.js index c5aaa48b1..b1581614a 100644 --- a/p/scripts/global_view.js +++ b/p/scripts/global_view.js @@ -1,6 +1,6 @@ "use strict"; -/* globals init_load_more, init_posts, init_stream */ -/* jshint globalstrict: true */ +/* globals context, init_load_more, init_posts, init_stream */ +/* jshint esversion:6, strict:global */ var panel_loading = false; @@ -11,68 +11,88 @@ function load_panel(link) { panel_loading = true; - $.get(link, function (data) { - $("#panel").append($(".nav_menu, #stream .day, #stream .flux, #stream .pagination, #stream.prompt", data)); - - $("#panel .nav_menu").children().not("#nav_menu_read_all").remove(); - - init_load_more($("#panel")); - init_posts(); - - $("#overlay").fadeIn(); - $("#panel").slideToggle(); - - // force le démarrage du scroll en haut. - // Sans ça, si l'on scroll en lisant une catégorie par exemple, - // en en ouvrant une autre ensuite, on se retrouve au même point de scroll - $("#panel").scrollTop(0); - $(window).scrollTop(0); - - $('#panel').on('click', '#nav_menu_read_all button, #bigMarkAsRead', function () { - console.log($(this).attr("formaction")); - $.ajax({ - type: "POST", - url: $(this).attr("formaction"), - data: { - _csrf: context.csrf, - }, - async: false - }); - window.location.reload(false); - return false; - }); - - panel_loading = false; - }); + const req = new XMLHttpRequest(); + req.open('GET', link, true); + req.responseType = 'document'; + req.onload = function (e) { + if (this.status != 200) { + return; + } + const html = this.response, + foreign = html.querySelectorAll('.nav_menu, #stream .day, #stream .flux, #stream .pagination, #stream.prompt'), + panel = document.getElementById('panel'); + foreign.forEach(function (el) { + panel.appendChild(document.adoptNode(el)); + }); + panel.querySelectorAll('.nav_menu > :not([id="nav_menu_read_all"])').forEach(function (el) { + el.remove(); + }); + + init_load_more(panel); + init_posts(); + + document.getElementById('overlay').classList.add('visible'); + panel.classList.add('visible'); + + // force le démarrage du scroll en haut. + // Sans ça, si l'on scroll en lisant une catégorie par exemple, + // en en ouvrant une autre ensuite, on se retrouve au même point de scroll + panel.scrollTop = 0; + document.documentElement.scrollTop = 0; + + //We already have a click listener in main.js + panel.addEventListener('click', function (ev) { + const b = ev.target.closest('#nav_menu_read_all button, #bigMarkAsRead'); + if (b) { + console.log(b.formAction); + + const req2 = new XMLHttpRequest(); + req2.open('POST', b.formAction, false); + req2.setRequestHeader('Content-Type', 'application/json'); + req2.send(JSON.stringify({ + _csrf: context.csrf, + })); + if (req2.status == 200) { + location.reload(false); + return false; + } + } + }); + + panel_loading = false; + }; + req.send(); } function init_close_panel() { - $("#overlay .close").click(function () { - $("#panel").html(''); - $("#panel").slideToggle(); - $("#overlay").fadeOut(); - - return false; - }); + const panel = document.getElementById('panel'); + document.querySelector('#overlay .close').onclick = function (ev) { + panel.innerHTML = ''; + panel.classList.remove('visible'); + document.getElementById('overlay').classList.remove('visible'); + return false; + }; } function init_global_view() { - // TODO: should be based on generic classes. - $(".box a").click(function () { - var link = $(this).attr("href"); - - load_panel(link); - - return false; - }); + // TODO: should be based on generic classes + document.querySelectorAll('.box a').forEach(function (a) { + a.onclick = function (ev) { + load_panel(a.href); + return false; + }; + }); - $(".nav_menu #nav_menu_read_all, .nav_menu .toggle_aside").remove(); + document.querySelectorAll('.nav_menu #nav_menu_read_all, .nav_menu .toggle_aside').forEach(function (el) { + el.remove(); + }); - init_stream($("#panel")); + const panel = document.getElementById('panel'); + init_stream(panel); } function init_all_global_view() { - if (!(window.$ && window.init_stream)) { + if (!window.context) { if (window.console) { console.log('FreshRSS Global view waiting for JS…'); } @@ -85,7 +105,7 @@ function init_all_global_view() { if (document.readyState && document.readyState !== 'loading') { init_all_global_view(); -} else if (document.addEventListener) { +} else { document.addEventListener('DOMContentLoaded', function () { init_all_global_view(); }, false); |
