2019-10-20 22:10:24 +02:00
|
|
|
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
|
2021-10-21 11:44:03 +02:00
|
|
|
|
'use strict';
|
2018-12-25 05:11:38 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// <Polyfills>
|
2019-04-04 00:02:23 +02:00
|
|
|
|
if (!document.scrollingElement) document.scrollingElement = document.documentElement;
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (!NodeList.prototype.forEach) NodeList.prototype.forEach = Array.prototype.forEach;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (!Element.prototype.matches) {
|
|
|
|
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
|
|
|
}
|
|
|
|
|
if (!Element.prototype.closest) {
|
|
|
|
|
Element.prototype.closest = function (s) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
let el = this;
|
|
|
|
|
do {
|
|
|
|
|
if (el.matches(s)) return el;
|
2018-12-27 03:34:56 +01:00
|
|
|
|
el = el.parentElement;
|
|
|
|
|
} while (el);
|
2018-12-25 05:11:38 +01:00
|
|
|
|
return null;
|
|
|
|
|
};
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (!Element.prototype.remove) Element.prototype.remove = function () { if (this.parentNode) this.parentNode.removeChild(this); };
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// </Polyfills>
|
2018-12-25 05:11:38 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// <Utils>
|
2019-02-13 15:06:28 +01:00
|
|
|
|
function xmlHttpRequestJson(req) {
|
|
|
|
|
let json = req.response;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (req.responseType !== 'json') { // IE11
|
2021-02-28 12:26:24 +01:00
|
|
|
|
try {
|
|
|
|
|
json = JSON.parse(req.responseText);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
json = null;
|
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
|
|
|
|
return json;
|
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// </Utils>
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// <Global context>
|
2021-10-21 12:47:31 +02:00
|
|
|
|
/* eslint-disable no-var */
|
|
|
|
|
var context;
|
|
|
|
|
/* eslint-enable no-var */
|
2018-12-25 05:11:38 +01:00
|
|
|
|
|
|
|
|
|
(function parseJsonVars() {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const jsonVars = document.getElementById('jsonVars');
|
|
|
|
|
const json = JSON.parse(jsonVars.innerHTML);
|
2018-12-25 05:11:38 +01:00
|
|
|
|
jsonVars.outerHTML = '';
|
|
|
|
|
context = json.context;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
context.ajax_loading = false;
|
|
|
|
|
context.i18n = json.i18n;
|
|
|
|
|
context.shortcuts = json.shortcuts;
|
|
|
|
|
context.urls = json.urls;
|
|
|
|
|
context.icons = json.icons;
|
|
|
|
|
context.icons.read = decodeURIComponent(context.icons.read);
|
|
|
|
|
context.icons.unread = decodeURIComponent(context.icons.unread);
|
2021-01-07 21:45:48 +01:00
|
|
|
|
context.extensions = json.extensions;
|
2018-12-25 05:11:38 +01:00
|
|
|
|
}());
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// </Global context>
|
2013-10-13 17:55:03 +02:00
|
|
|
|
|
2019-04-06 09:24:22 +02:00
|
|
|
|
function badAjax(reload) {
|
2019-03-22 19:05:38 +01:00
|
|
|
|
openNotification(context.i18n.notif_request_failed, 'bad');
|
2019-04-06 09:24:22 +02:00
|
|
|
|
if (reload) {
|
|
|
|
|
setTimeout(function () { location.reload(); }, 2000);
|
|
|
|
|
}
|
2019-03-22 19:05:38 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 03:34:56 +01:00
|
|
|
|
function needsScroll(elem) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const winBottom = document.scrollingElement.scrollTop + document.scrollingElement.clientHeight;
|
|
|
|
|
const elemTop = elem.offsetParent.offsetTop + elem.offsetTop;
|
|
|
|
|
const elemBottom = elemTop + elem.offsetHeight;
|
|
|
|
|
if (elemTop < document.scrollingElement.scrollTop || elemBottom > winBottom) {
|
|
|
|
|
return elemTop - (document.scrollingElement.clientHeight / 2);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2014-02-04 17:47:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 00:18:30 +01:00
|
|
|
|
function str2int(str) {
|
2014-10-05 01:43:29 +02:00
|
|
|
|
if (!str) {
|
2014-01-28 00:18:30 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return parseInt(str.replace(/\D/g, ''), 10) || 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 19:53:54 +01:00
|
|
|
|
function numberFormat(nStr) {
|
2014-01-28 00:18:30 +01:00
|
|
|
|
if (nStr < 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-01-27 22:35:27 +01:00
|
|
|
|
// http://www.mredkj.com/javascript/numberFormat.html
|
2014-01-26 19:53:54 +01:00
|
|
|
|
nStr += '';
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const x = nStr.split('.');
|
|
|
|
|
const x2 = x.length > 1 ? '.' + x[1] : '';
|
|
|
|
|
const rgx = /(\d+)(\d{3})/;
|
2018-12-25 05:11:38 +01:00
|
|
|
|
let x1 = x[0];
|
2014-01-26 19:53:54 +01:00
|
|
|
|
while (rgx.test(x1)) {
|
2021-02-28 12:26:24 +01:00
|
|
|
|
x1 = x1.replace(rgx, '$1 $2');
|
2014-01-26 19:53:54 +01:00
|
|
|
|
}
|
|
|
|
|
return x1 + x2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-13 22:42:33 +02:00
|
|
|
|
function incLabel(p, inc, spaceAfter) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
const i = str2int(p) + inc;
|
2016-08-06 13:18:46 +02:00
|
|
|
|
return i > 0 ? ((spaceAfter ? '' : ' ') + '(' + numberFormat(i) + ')' + (spaceAfter ? ' ' : '')) : '';
|
2014-01-26 20:31:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-09 23:17:35 +01:00
|
|
|
|
function incUnreadsFeed(article, feed_id, nb) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Update unread: feed
|
|
|
|
|
let elem = document.getElementById(feed_id);
|
|
|
|
|
let feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
|
|
|
|
|
const feed_priority = elem ? str2int(elem.getAttribute('data-priority')) : 0;
|
2014-01-09 23:17:35 +01:00
|
|
|
|
if (elem) {
|
2014-10-23 10:44:45 +02:00
|
|
|
|
elem.setAttribute('data-unread', feed_unreads + nb);
|
2018-12-25 05:11:38 +01:00
|
|
|
|
elem = elem.querySelector('.item-title');
|
2014-07-26 13:56:44 +02:00
|
|
|
|
if (elem) {
|
2014-10-23 10:44:45 +02:00
|
|
|
|
elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
|
2014-07-26 13:56:44 +02:00
|
|
|
|
}
|
2014-01-09 23:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Update unread: category
|
2018-12-25 05:11:38 +01:00
|
|
|
|
elem = document.getElementById(feed_id).closest('.category');
|
2014-01-28 00:18:30 +01:00
|
|
|
|
feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
|
2014-01-09 23:17:35 +01:00
|
|
|
|
if (elem) {
|
2014-10-23 10:44:45 +02:00
|
|
|
|
elem.setAttribute('data-unread', feed_unreads + nb);
|
2018-12-25 05:11:38 +01:00
|
|
|
|
elem = elem.querySelector('.title');
|
2014-07-26 13:56:44 +02:00
|
|
|
|
if (elem) {
|
2014-10-23 10:44:45 +02:00
|
|
|
|
elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
|
2014-07-26 13:56:44 +02:00
|
|
|
|
}
|
2014-01-09 23:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Update unread: all
|
2014-01-09 23:17:35 +01:00
|
|
|
|
if (feed_priority > 0) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
elem = document.querySelector('#aside_feed .all .title');
|
2014-01-09 23:17:35 +01:00
|
|
|
|
if (elem) {
|
2014-01-28 00:18:30 +01:00
|
|
|
|
feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
|
|
|
|
|
elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
|
2014-01-09 23:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Update unread: favourites
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (article && article.closest('div').classList.contains('favorite')) {
|
|
|
|
|
elem = document.querySelector('#aside_feed .favorites .title');
|
2014-01-09 23:17:35 +01:00
|
|
|
|
if (elem) {
|
2014-01-28 00:18:30 +01:00
|
|
|
|
feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
|
|
|
|
|
elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
|
2014-01-09 23:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 05:11:38 +01:00
|
|
|
|
let isCurrentView = false;
|
2014-10-23 10:44:45 +02:00
|
|
|
|
// Update unread: title
|
2021-10-21 11:44:03 +02:00
|
|
|
|
document.title = document.title.replace(/^((?:\([\s0-9]+\) )?)/, function (m, p1) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
const feed = document.getElementById(feed_id);
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (article || feed.closest('.active')) {
|
2014-01-25 16:07:50 +01:00
|
|
|
|
isCurrentView = true;
|
2014-08-09 22:00:20 +02:00
|
|
|
|
return incLabel(p1, nb, true);
|
2018-12-25 05:11:38 +01:00
|
|
|
|
} else if (document.querySelector('.all.active')) {
|
2014-07-14 00:30:55 +02:00
|
|
|
|
isCurrentView = feed_priority > 0;
|
2014-08-09 22:00:20 +02:00
|
|
|
|
return incLabel(p1, feed_priority > 0 ? nb : 0, true);
|
2014-01-12 20:26:26 +01:00
|
|
|
|
} else {
|
2014-08-09 22:00:20 +02:00
|
|
|
|
return p1;
|
2014-01-12 20:26:26 +01:00
|
|
|
|
}
|
2014-01-09 23:17:35 +01:00
|
|
|
|
});
|
2014-01-25 16:07:50 +01:00
|
|
|
|
return isCurrentView;
|
2014-01-09 23:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-29 20:47:17 +02:00
|
|
|
|
function incUnreadsTag(tag_id, nb) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
let t = document.getElementById(tag_id);
|
|
|
|
|
if (t) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const unreads = str2int(t.getAttribute('data-unread'));
|
2018-12-25 05:11:38 +01:00
|
|
|
|
t.setAttribute('data-unread', unreads + nb);
|
|
|
|
|
t.querySelector('.item-title').setAttribute('data-unread', numberFormat(unreads + nb));
|
|
|
|
|
}
|
|
|
|
|
t = document.querySelector('.category.tags .title');
|
|
|
|
|
if (t) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const unreads = str2int(t.getAttribute('data-unread'));
|
2018-12-25 05:11:38 +01:00
|
|
|
|
t.setAttribute('data-unread', numberFormat(unreads + nb));
|
|
|
|
|
}
|
2018-09-29 20:47:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-06 15:51:39 +02:00
|
|
|
|
function removeArticle(div) {
|
2019-04-07 00:29:37 +02:00
|
|
|
|
if (!div || div.classList.contains('not_read') || (context.auto_mark_article && div.classList.contains('active'))) {
|
2019-04-06 16:45:21 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-06 15:51:39 +02:00
|
|
|
|
let scrollTop = box_to_follow.scrollTop;
|
|
|
|
|
let dirty = false;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const p = div.previousElementSibling;
|
|
|
|
|
const n = div.nextElementSibling;
|
2019-04-06 15:51:39 +02:00
|
|
|
|
if (p && p.classList.contains('day') && n && n.classList.contains('day')) {
|
|
|
|
|
scrollTop -= p.offsetHeight;
|
|
|
|
|
dirty = true;
|
|
|
|
|
p.remove();
|
|
|
|
|
}
|
|
|
|
|
if (div.offsetHeight > 0 && div.offsetParent.offsetTop + div.offsetTop + div.offsetHeight < scrollTop) {
|
|
|
|
|
scrollTop -= div.offsetHeight;
|
|
|
|
|
dirty = true;
|
|
|
|
|
}
|
|
|
|
|
div.remove();
|
|
|
|
|
if (dirty) {
|
|
|
|
|
box_to_follow.scrollTop = scrollTop;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const pending_entries = {};
|
|
|
|
|
let mark_read_queue = [];
|
2018-12-25 05:11:38 +01:00
|
|
|
|
|
2019-03-25 08:46:31 +01:00
|
|
|
|
function send_mark_read_queue(queue, asRead, callback) {
|
2021-11-04 22:22:39 +01:00
|
|
|
|
if (!queue || queue.length === 0) {
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('POST', '.?c=entry&a=read' + (asRead ? '' : '&is_read=0'), true);
|
|
|
|
|
req.responseType = 'json';
|
|
|
|
|
req.onerror = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
for (let i = queue.length - 1; i >= 0; i--) {
|
|
|
|
|
delete pending_entries['flux_' + queue[i]];
|
|
|
|
|
}
|
|
|
|
|
badAjax(this.status == 403);
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.onload = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (this.status != 200) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
const json = xmlHttpRequestJson(this);
|
|
|
|
|
if (!json) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
for (let i = queue.length - 1; i >= 0; i--) {
|
|
|
|
|
const div = document.getElementById('flux_' + queue[i]);
|
|
|
|
|
const myIcons = context.icons;
|
|
|
|
|
let inc = 0;
|
|
|
|
|
if (div.classList.contains('not_read')) {
|
|
|
|
|
div.classList.remove('not_read');
|
|
|
|
|
div.querySelectorAll('a.read').forEach(function (a) {
|
|
|
|
|
a.href = a.href.replace('&is_read=0', '') + '&is_read=1';
|
|
|
|
|
});
|
|
|
|
|
div.querySelectorAll('a.read > .icon').forEach(function (img) { img.outerHTML = myIcons.read; });
|
|
|
|
|
inc--;
|
|
|
|
|
if (context.auto_remove_article) {
|
|
|
|
|
removeArticle(div);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
} else {
|
|
|
|
|
div.classList.add('not_read');
|
|
|
|
|
div.classList.add('keep_unread'); // Split for IE11
|
|
|
|
|
div.querySelectorAll('a.read').forEach(function (a) {
|
|
|
|
|
a.href = a.href.replace('&is_read=1', '');
|
|
|
|
|
});
|
|
|
|
|
div.querySelectorAll('a.read > .icon').forEach(function (img) { img.outerHTML = myIcons.unread; });
|
|
|
|
|
inc++;
|
2018-09-29 20:47:17 +02:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const feed_link = div.querySelector('.website > a, a.website');
|
|
|
|
|
if (feed_link) {
|
|
|
|
|
const feed_url = feed_link.href;
|
|
|
|
|
const feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
|
|
|
|
|
incUnreadsFeed(div, feed_id, inc);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
delete pending_entries['flux_' + queue[i]];
|
|
|
|
|
}
|
|
|
|
|
faviconNbUnread();
|
|
|
|
|
if (json.tags) {
|
|
|
|
|
const tagIds = Object.keys(json.tags);
|
|
|
|
|
for (let i = tagIds.length - 1; i >= 0; i--) {
|
|
|
|
|
const tagId = tagIds[i];
|
|
|
|
|
incUnreadsTag(tagId, (asRead ? -1 : 1) * json.tags[tagId].length);
|
2019-03-25 08:46:31 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
onScroll();
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req.send(JSON.stringify({
|
2021-10-21 11:44:03 +02:00
|
|
|
|
ajax: true,
|
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
id: queue,
|
|
|
|
|
}));
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let send_mark_read_queue_timeout = 0;
|
2018-12-25 15:34:25 +01:00
|
|
|
|
|
2019-03-25 08:46:31 +01:00
|
|
|
|
function send_mark_queue_tick(callback) {
|
|
|
|
|
send_mark_read_queue_timeout = 0;
|
|
|
|
|
const queue = mark_read_queue.slice(0);
|
|
|
|
|
mark_read_queue = [];
|
|
|
|
|
send_mark_read_queue(queue, true, callback);
|
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const delayedFunction = send_mark_queue_tick;
|
2019-03-25 08:46:31 +01:00
|
|
|
|
|
|
|
|
|
function delayedClick(a) {
|
|
|
|
|
if (a) {
|
2019-04-06 09:24:22 +02:00
|
|
|
|
delayedFunction(function () { a.click(); });
|
2019-03-25 08:46:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-06 15:51:39 +02:00
|
|
|
|
function mark_read(div, only_not_read, asBatch) {
|
2018-12-25 15:34:25 +01:00
|
|
|
|
if (!div || !div.id || context.anonymous ||
|
|
|
|
|
(only_not_read && !div.classList.contains('not_read'))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (pending_entries[div.id]) {
|
2018-12-25 15:34:25 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
pending_entries[div.id] = true;
|
2018-12-25 15:34:25 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const asRead = div.classList.contains('not_read');
|
|
|
|
|
const entryId = div.id.replace(/^flux_/, '');
|
2019-04-06 15:51:39 +02:00
|
|
|
|
if (asRead && asBatch) {
|
2018-12-25 15:34:25 +01:00
|
|
|
|
mark_read_queue.push(entryId);
|
|
|
|
|
if (send_mark_read_queue_timeout == 0) {
|
2019-03-25 08:46:31 +01:00
|
|
|
|
send_mark_read_queue_timeout = setTimeout(function () { send_mark_queue_tick(null); }, 1000);
|
2018-12-25 15:34:25 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const queue = [entryId];
|
2018-12-25 15:34:25 +01:00
|
|
|
|
send_mark_read_queue(queue, asRead);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 23:05:01 +01:00
|
|
|
|
function mark_previous_read(div) {
|
|
|
|
|
while (div) {
|
|
|
|
|
mark_read(div, true, true);
|
|
|
|
|
div = div.previousElementSibling;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 05:11:38 +01:00
|
|
|
|
function mark_favorite(div) {
|
|
|
|
|
if (!div) {
|
2013-10-13 17:55:03 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const a = div.querySelector('a.bookmark');
|
|
|
|
|
const url = a ? a.href : '';
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (!url) {
|
2013-10-13 17:55:03 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (pending_entries[div.id]) {
|
2014-02-15 14:57:18 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-25 05:11:38 +01:00
|
|
|
|
pending_entries[div.id] = true;
|
2014-02-15 14:57:18 +01:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('POST', url, true);
|
|
|
|
|
req.responseType = 'json';
|
|
|
|
|
req.onerror = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
delete pending_entries[div.id];
|
|
|
|
|
badAjax(this.status == 403);
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.onload = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (this.status != 200) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
const json = xmlHttpRequestJson(this);
|
|
|
|
|
if (!json) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
let inc = 0;
|
|
|
|
|
if (div.classList.contains('favorite')) {
|
|
|
|
|
div.classList.remove('favorite');
|
|
|
|
|
inc--;
|
|
|
|
|
} else {
|
|
|
|
|
div.classList.add('favorite');
|
|
|
|
|
inc++;
|
|
|
|
|
}
|
|
|
|
|
div.querySelectorAll('a.bookmark').forEach(function (a) { a.href = json.url; });
|
|
|
|
|
div.querySelectorAll('a.bookmark > .icon').forEach(function (img) { img.outerHTML = json.icon; });
|
2013-10-26 17:21:11 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const favourites = document.querySelector('#aside_feed .favorites .title');
|
|
|
|
|
if (favourites) {
|
|
|
|
|
favourites.textContent = favourites.textContent.replace(/((?: \([\s0-9]+\))?\s*)$/, function (m, p1) {
|
|
|
|
|
return incLabel(p1, inc, false);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-11-09 00:46:43 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (div.classList.contains('not_read')) {
|
|
|
|
|
const elem = document.querySelector('#aside_feed .favorites .title');
|
|
|
|
|
const feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.setAttribute('data-unread', numberFormat(feed_unreads + inc));
|
2014-01-18 19:29:44 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2014-02-15 14:57:18 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
delete pending_entries[div.id];
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req.send(JSON.stringify({
|
2021-10-21 11:44:03 +02:00
|
|
|
|
ajax: true,
|
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
}));
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const freshrssOpenArticleEvent = document.createEvent('Event');
|
2019-01-24 19:43:28 +01:00
|
|
|
|
freshrssOpenArticleEvent.initEvent('freshrss:openArticle', true, true);
|
|
|
|
|
|
2018-12-27 03:34:56 +01:00
|
|
|
|
function toggleContent(new_active, old_active, skipping) {
|
2018-11-18 14:08:27 +01:00
|
|
|
|
// If skipping, move current without activating or marking as read
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (!new_active) {
|
2014-01-13 20:07:43 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-18 14:08:27 +01:00
|
|
|
|
if (context.does_lazyload && !skipping) {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
new_active.querySelectorAll('img[data-original], iframe[data-original]').forEach(function (el) {
|
|
|
|
|
el.src = el.getAttribute('data-original');
|
|
|
|
|
el.removeAttribute('data-original');
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (old_active !== new_active) {
|
|
|
|
|
if (!skipping) {
|
|
|
|
|
new_active.classList.add('active');
|
2013-11-26 18:44:03 +01:00
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
new_active.classList.add('current');
|
|
|
|
|
if (old_active) {
|
|
|
|
|
old_active.classList.remove('active');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
old_active.classList.remove('current'); // Split for IE11
|
2019-04-06 16:45:21 +02:00
|
|
|
|
if (context.auto_remove_article) {
|
|
|
|
|
removeArticle(old_active);
|
|
|
|
|
}
|
2014-12-04 00:35:42 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
} else {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
new_active.classList.toggle('active');
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const relative_move = context.current_view === 'global';
|
|
|
|
|
const box_to_move = relative_move ? document.getElementById('panel') : document.scrollingElement;
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (context.sticky_post) { // Stick the article to the top when opened
|
|
|
|
|
const prev_article = new_active.previousElementSibling;
|
|
|
|
|
let new_pos = new_active.offsetParent.offsetTop + new_active.offsetTop;
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (prev_article && new_active.offsetTop - prev_article.offsetTop <= 150) {
|
2019-04-03 23:10:33 +02:00
|
|
|
|
new_pos = prev_article.offsetParent.offsetTop + prev_article.offsetTop;
|
2016-01-26 22:00:18 +01:00
|
|
|
|
if (relative_move) {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
new_pos -= box_to_move.offsetTop;
|
2016-01-26 22:00:18 +01:00
|
|
|
|
}
|
2014-09-16 17:23:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-18 19:31:36 +01:00
|
|
|
|
if (skipping) {
|
2022-01-08 21:58:55 +01:00
|
|
|
|
// when skipping, this feels more natural if it’s not so near the top
|
2018-12-27 03:34:56 +01:00
|
|
|
|
new_pos -= document.body.clientHeight / 4;
|
2018-11-18 14:08:27 +01:00
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (relative_move) {
|
2019-04-03 23:10:33 +02:00
|
|
|
|
new_pos += box_to_move.scrollTop;
|
2014-02-25 01:51:57 +01:00
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
box_to_move.scrollTop = new_pos;
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-26 21:08:27 +01:00
|
|
|
|
if (new_active.classList.contains('active') && !skipping) {
|
2019-01-24 19:43:28 +01:00
|
|
|
|
if (context.auto_mark_article) {
|
2019-04-06 15:51:39 +02:00
|
|
|
|
mark_read(new_active, true, true);
|
2019-01-24 19:43:28 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
new_active.dispatchEvent(freshrssOpenArticleEvent);
|
2018-11-18 14:08:27 +01:00
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
onScroll();
|
2018-11-18 14:08:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 03:34:56 +01:00
|
|
|
|
function prev_entry(skipping) {
|
2019-02-23 14:39:20 +01:00
|
|
|
|
const old_active = document.querySelector('.flux.current');
|
|
|
|
|
let new_active = old_active;
|
|
|
|
|
if (new_active) {
|
|
|
|
|
do new_active = new_active.previousElementSibling;
|
|
|
|
|
while (new_active && !new_active.classList.contains('flux'));
|
|
|
|
|
if (!new_active) {
|
|
|
|
|
prev_feed();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
new_active = document.querySelector('.flux');
|
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
toggleContent(new_active, old_active, skipping);
|
2018-11-18 14:08:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 03:34:56 +01:00
|
|
|
|
function next_entry(skipping) {
|
2019-02-23 14:39:20 +01:00
|
|
|
|
const old_active = document.querySelector('.flux.current');
|
|
|
|
|
let new_active = old_active;
|
|
|
|
|
if (new_active) {
|
|
|
|
|
do new_active = new_active.nextElementSibling;
|
|
|
|
|
while (new_active && !new_active.classList.contains('flux'));
|
|
|
|
|
if (!new_active) {
|
|
|
|
|
next_feed();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
new_active = document.querySelector('.flux');
|
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
toggleContent(new_active, old_active, skipping);
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 10:46:39 +02:00
|
|
|
|
function next_unread_entry(skipping) {
|
|
|
|
|
const old_active = document.querySelector('.flux.current');
|
|
|
|
|
let new_active = old_active;
|
|
|
|
|
if (new_active) {
|
|
|
|
|
do new_active = new_active.nextElementSibling;
|
|
|
|
|
while (new_active && !new_active.classList.contains('not_read'));
|
|
|
|
|
if (!new_active) {
|
|
|
|
|
next_feed();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
new_active = document.querySelector('.not_read');
|
|
|
|
|
}
|
|
|
|
|
toggleContent(new_active, old_active, skipping);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 16:02:45 +01:00
|
|
|
|
function prev_feed() {
|
2019-02-23 14:39:20 +01:00
|
|
|
|
let found = false;
|
2019-12-04 08:29:20 +01:00
|
|
|
|
let adjacent = null;
|
2019-02-23 14:39:20 +01:00
|
|
|
|
const feeds = document.querySelectorAll('#aside_feed .feed');
|
|
|
|
|
for (let i = feeds.length - 1; i >= 0; i--) {
|
|
|
|
|
const feed = feeds[i];
|
2019-12-04 08:29:20 +01:00
|
|
|
|
if (feed.classList.contains('active')) {
|
2019-02-23 14:39:20 +01:00
|
|
|
|
found = true;
|
2019-12-04 08:29:20 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (getComputedStyle(feed).display === 'none') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (feed.dataset.unread != 0) {
|
|
|
|
|
return delayedClick(feed.querySelector('a.item-title'));
|
|
|
|
|
} else if (adjacent === null) {
|
|
|
|
|
adjacent = feed;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2019-02-23 14:39:20 +01:00
|
|
|
|
}
|
2019-12-04 08:29:20 +01:00
|
|
|
|
if (found) {
|
|
|
|
|
delayedClick(adjacent.querySelector('a.item-title'));
|
|
|
|
|
} else {
|
2014-02-15 20:24:07 +01:00
|
|
|
|
last_feed();
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function next_feed() {
|
2019-02-23 14:39:20 +01:00
|
|
|
|
let found = false;
|
2019-12-04 08:29:20 +01:00
|
|
|
|
let adjacent = null;
|
2019-02-23 14:39:20 +01:00
|
|
|
|
const feeds = document.querySelectorAll('#aside_feed .feed');
|
|
|
|
|
for (let i = 0; i < feeds.length; i++) {
|
|
|
|
|
const feed = feeds[i];
|
2019-12-04 08:29:20 +01:00
|
|
|
|
if (feed.classList.contains('active')) {
|
2019-02-23 14:39:20 +01:00
|
|
|
|
found = true;
|
2019-12-04 08:29:20 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (getComputedStyle(feed).display === 'none') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (feed.dataset.unread != 0) {
|
|
|
|
|
return delayedClick(feed.querySelector('a.item-title'));
|
|
|
|
|
} else if (adjacent === null) {
|
|
|
|
|
adjacent = feed;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2019-02-23 14:39:20 +01:00
|
|
|
|
}
|
2019-12-04 08:29:20 +01:00
|
|
|
|
if (found) {
|
|
|
|
|
delayedClick(adjacent.querySelector('a.item-title'));
|
|
|
|
|
} else {
|
2014-02-15 20:24:07 +01:00
|
|
|
|
first_feed();
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function first_feed() {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const a = document.querySelector('#aside_feed .category.active .feed:not([data-unread="0"]) a.item-title');
|
2019-03-27 00:08:59 +01:00
|
|
|
|
delayedClick(a);
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function last_feed() {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const links = document.querySelectorAll('#aside_feed .category.active .feed:not([data-unread="0"]) a.item-title');
|
|
|
|
|
if (links && links.length > 0) {
|
2019-03-25 08:46:31 +01:00
|
|
|
|
delayedClick(links[links.length - 1]);
|
2014-02-15 20:24:07 +01:00
|
|
|
|
}
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prev_category() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const active_cat = document.querySelector('#aside_feed .category.active');
|
|
|
|
|
if (active_cat) {
|
|
|
|
|
let cat = active_cat;
|
|
|
|
|
do cat = cat.previousElementSibling;
|
|
|
|
|
while (cat && getComputedStyle(cat).display === 'none');
|
|
|
|
|
if (cat) {
|
2019-03-25 08:46:31 +01:00
|
|
|
|
delayedClick(cat.querySelector('a.title'));
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-02-15 20:24:07 +01:00
|
|
|
|
last_category();
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function next_category() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const active_cat = document.querySelector('#aside_feed .category.active');
|
|
|
|
|
if (active_cat) {
|
|
|
|
|
let cat = active_cat;
|
|
|
|
|
do cat = cat.nextElementSibling;
|
|
|
|
|
while (cat && getComputedStyle(cat).display === 'none');
|
|
|
|
|
if (cat) {
|
2019-03-25 08:46:31 +01:00
|
|
|
|
delayedClick(cat.querySelector('a.title'));
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-02-15 20:24:07 +01:00
|
|
|
|
first_category();
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 10:46:39 +02:00
|
|
|
|
function next_unread_category() {
|
|
|
|
|
const active_cat = document.querySelector('#aside_feed .category.active');
|
|
|
|
|
if (active_cat) {
|
|
|
|
|
let cat = active_cat;
|
|
|
|
|
do cat = cat.nextElementSibling;
|
|
|
|
|
while (cat && cat.getAttribute('data-unread') <= 0);
|
|
|
|
|
if (cat) {
|
|
|
|
|
delayedClick(cat.querySelector('a.title'));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
first_category();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 16:02:45 +01:00
|
|
|
|
function first_category() {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const a = document.querySelector('#aside_feed .category:not([data-unread="0"]) a.title');
|
2019-03-27 00:08:59 +01:00
|
|
|
|
delayedClick(a);
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function last_category() {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const links = document.querySelectorAll('#aside_feed .category:not([data-unread="0"]) a.title');
|
|
|
|
|
if (links && links.length > 0) {
|
2019-03-25 08:46:31 +01:00
|
|
|
|
delayedClick(links[links.length - 1]);
|
2014-02-15 20:24:07 +01:00
|
|
|
|
}
|
2014-02-02 16:02:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 01:30:02 +01:00
|
|
|
|
function collapse_entry() {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const flux_current = document.querySelector('.flux.current');
|
|
|
|
|
toggleContent(flux_current, flux_current, false);
|
2013-11-26 18:44:03 +01:00
|
|
|
|
}
|
2013-11-26 01:30:02 +01:00
|
|
|
|
|
2020-06-05 23:37:05 +02:00
|
|
|
|
function toggle_media() {
|
|
|
|
|
const media = document.querySelector('.flux.current video,.flux.current audio');
|
|
|
|
|
if (media === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (media.paused) {
|
|
|
|
|
media.play();
|
|
|
|
|
} else {
|
|
|
|
|
media.pause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 17:34:58 +02:00
|
|
|
|
function user_filter(key) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const filter = document.getElementById('dropdown-query');
|
|
|
|
|
const filters = filter.parentElement.querySelectorAll('.dropdown-menu > .query > a');
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (typeof key === 'undefined') {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (!filters.length) {
|
2014-08-24 17:34:58 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Display the filter div
|
2019-02-13 15:06:28 +01:00
|
|
|
|
location.hash = filter.id;
|
2014-08-24 17:34:58 +02:00
|
|
|
|
// Force scrolling to the filter div
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const scroll = needsScroll(document.querySelector('.header'));
|
2014-08-24 17:34:58 +02:00
|
|
|
|
if (scroll !== 0) {
|
2019-04-04 00:02:23 +02:00
|
|
|
|
document.scrollingElement.scrollTop = scroll;
|
2014-08-24 17:34:58 +02:00
|
|
|
|
}
|
|
|
|
|
// Force the key value if there is only one action, so we can trigger it automatically
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (filters.length === 1) {
|
2014-08-24 17:34:58 +02:00
|
|
|
|
key = 1;
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Trigger selected share action
|
|
|
|
|
key = parseInt(key);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (key <= filters.length) {
|
|
|
|
|
filters[key - 1].click();
|
2014-08-24 17:34:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-01 17:40:20 +01:00
|
|
|
|
function auto_share(key) {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const share = document.querySelector('.flux.current.active .dropdown-target[id^="dropdown-share"]');
|
|
|
|
|
if (!share) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const shares = share.parentElement.querySelectorAll('.dropdown-menu .item a');
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (typeof key === 'undefined') {
|
2014-02-01 17:40:20 +01:00
|
|
|
|
// Display the share div
|
2018-12-27 03:34:56 +01:00
|
|
|
|
location.hash = share.id;
|
2014-02-05 04:56:46 +01:00
|
|
|
|
// Force scrolling to the share div
|
2018-12-27 03:34:56 +01:00
|
|
|
|
const scrollTop = needsScroll(share.closest('.bottom'));
|
|
|
|
|
if (scrollTop !== 0) {
|
2019-04-04 00:02:23 +02:00
|
|
|
|
document.scrollingElement.scrollTop = scrollTop;
|
2014-02-04 17:47:01 +01:00
|
|
|
|
}
|
2014-02-01 17:40:20 +01:00
|
|
|
|
// Force the key value if there is only one action, so we can trigger it automatically
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (shares.length === 1) {
|
2014-02-01 17:40:20 +01:00
|
|
|
|
key = 1;
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Trigger selected share action and hide the share div
|
|
|
|
|
key = parseInt(key);
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (key <= shares.length) {
|
|
|
|
|
shares[key - 1].click();
|
|
|
|
|
share.parentElement.querySelector('.dropdown-menu .dropdown-close a').click();
|
2014-01-03 06:01:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let box_to_follow;
|
2018-12-27 03:34:56 +01:00
|
|
|
|
|
|
|
|
|
function onScroll() {
|
|
|
|
|
if (!box_to_follow) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (context.auto_mark_scroll) {
|
|
|
|
|
const minTop = 40 + box_to_follow.scrollTop;
|
|
|
|
|
document.querySelectorAll('.not_read:not(.keep_unread)').forEach(function (div) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (div.offsetHeight > 0 &&
|
2018-12-27 03:34:56 +01:00
|
|
|
|
div.offsetParent.offsetTop + div.offsetTop + div.offsetHeight < minTop) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
mark_read(div, true, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-12-27 03:34:56 +01:00
|
|
|
|
}
|
|
|
|
|
if (context.auto_load_more) {
|
2022-02-06 17:29:56 +01:00
|
|
|
|
const streamFooter = document.getElementById('stream-footer');
|
|
|
|
|
if (streamFooter && box_to_follow.offsetHeight > 0 &&
|
|
|
|
|
box_to_follow.scrollTop + box_to_follow.offsetHeight + (window.innerHeight / 2) >= streamFooter.offsetTop) {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
load_more_posts();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-16 15:10:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
function init_posts() {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
if (context.auto_load_more || context.auto_mark_scroll || context.auto_remove_article) {
|
2019-04-04 00:02:23 +02:00
|
|
|
|
box_to_follow = context.current_view === 'global' ? document.getElementById('panel') : document.scrollingElement;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let lastScroll = 0; // Throttle
|
|
|
|
|
let timerId = 0;
|
2019-04-04 00:02:23 +02:00
|
|
|
|
(box_to_follow === document.scrollingElement ? window : box_to_follow).onscroll = function () {
|
2018-12-25 16:09:48 +01:00
|
|
|
|
clearTimeout(timerId);
|
2016-10-16 12:31:13 +02:00
|
|
|
|
if (lastScroll + 500 < Date.now()) {
|
|
|
|
|
lastScroll = Date.now();
|
2018-12-27 03:34:56 +01:00
|
|
|
|
onScroll();
|
2016-10-16 15:10:21 +02:00
|
|
|
|
} else {
|
2018-12-27 03:34:56 +01:00
|
|
|
|
timerId = setTimeout(onScroll, 500);
|
2016-10-16 12:31:13 +02:00
|
|
|
|
}
|
2018-12-27 03:34:56 +01:00
|
|
|
|
};
|
|
|
|
|
onScroll();
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 12:03:16 +01:00
|
|
|
|
function rememberOpenCategory(category_id, isOpen) {
|
|
|
|
|
if (context.display_categories === 'remember') {
|
|
|
|
|
const open_categories = JSON.parse(localStorage.getItem('FreshRSS_open_categories') || '{}');
|
|
|
|
|
if (isOpen) {
|
|
|
|
|
open_categories[category_id] = true;
|
|
|
|
|
} else {
|
|
|
|
|
delete open_categories[category_id];
|
|
|
|
|
}
|
|
|
|
|
localStorage.setItem('FreshRSS_open_categories', JSON.stringify(open_categories));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openCategory(category_id) {
|
|
|
|
|
const category_element = document.getElementById(category_id);
|
|
|
|
|
category_element.querySelector('.tree-folder-items').classList.add('active');
|
|
|
|
|
const img = category_element.querySelector('a.dropdown-toggle img');
|
|
|
|
|
img.src = img.src.replace('/icons/down.', '/icons/up.');
|
|
|
|
|
img.alt = '△';
|
|
|
|
|
}
|
|
|
|
|
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
function init_column_categories() {
|
2018-12-15 10:56:38 +01:00
|
|
|
|
if (context.current_view !== 'normal' && context.current_view !== 'reader') {
|
2013-10-13 17:55:03 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-10-23 10:44:45 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Restore sidebar scroll position
|
2020-10-19 11:38:27 +02:00
|
|
|
|
document.getElementById('sidebar').scrollTop = +sessionStorage.getItem('FreshRSS_sidebar_scrollTop');
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Restore open categories
|
2020-11-02 12:03:16 +01:00
|
|
|
|
if (context.display_categories === 'remember') {
|
|
|
|
|
const open_categories = JSON.parse(localStorage.getItem('FreshRSS_open_categories') || '{}');
|
|
|
|
|
Object.keys(open_categories).forEach(function (category_id) {
|
|
|
|
|
openCategory(category_id);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
document.getElementById('aside_feed').onclick = function (ev) {
|
|
|
|
|
let a = ev.target.closest('.tree-folder > .tree-folder-title > a.dropdown-toggle');
|
|
|
|
|
if (a) {
|
|
|
|
|
const img = a.querySelector('img');
|
2020-11-02 12:03:16 +01:00
|
|
|
|
const category_id = a.closest('.category').id;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (img.alt === '▽') {
|
|
|
|
|
img.src = img.src.replace('/icons/down.', '/icons/up.');
|
|
|
|
|
img.alt = '△';
|
2020-11-02 12:03:16 +01:00
|
|
|
|
rememberOpenCategory(category_id, true);
|
2013-11-25 00:40:35 +01:00
|
|
|
|
} else {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
img.src = img.src.replace('/icons/up.', '/icons/down.');
|
|
|
|
|
img.alt = '▽';
|
2020-11-02 12:03:16 +01:00
|
|
|
|
rememberOpenCategory(category_id, false);
|
2013-11-25 00:40:35 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
|
|
|
|
const ul = a.closest('li').querySelector('.tree-folder-items');
|
|
|
|
|
let nbVisibleItems = 0;
|
|
|
|
|
for (let i = ul.children.length - 1; i >= 0; i--) {
|
|
|
|
|
if (ul.children[i].offsetHeight) {
|
|
|
|
|
nbVisibleItems++;
|
|
|
|
|
}
|
2018-12-16 12:49:23 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
ul.classList.toggle('active');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// CSS transition does not work on max-height:auto
|
2019-02-13 15:06:28 +01:00
|
|
|
|
ul.style.maxHeight = ul.classList.contains('active') ? (nbVisibleItems * 4) + 'em' : 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
Decouple scrolling of feeds and articles (#2117)
* Remove Sticky Kit
Remove sticky-kit, as functionality is unsuitable for separate scrolling.
* Remove sticky-kit load in main.js
Further removing the sticky-kit kruft
* Finish removal of references to Sticky-kit
* CSS Changes to template for Independent Scrolling
* Addition of JS and supporting CSS and html
* More CSS fixes to establish expected behavior
Should be able to scroll navbar without it being in sticky mode now.
* Fix typo in main.js
sortcut.js -> shortcut.js
* Fix unexpected tree scrolling behavior
* Change name of generic JS function
* Improve sticky-aside
* CSS changes in themes to accommodate independent Scroll
In themes where .aside's width is not the standard 300px, .tree's width must be specified to be equal to .aside
* Remove Sticky-Kit from README files
* Updates to Sticky-Aside
* Update Template to fix screwup
* Make Recalculating height actually work
* Let sidebar fill height if nav buttons aren't visible
* Make accommodating for nav buttons actually work
* update Swage theme for Independent Scroll feature
* Integrate sticky_aside into main.js
* Add Simple Scrollbar
* Patch scrollbar color for themes with dark colored asides
* Increase Visibility of scrollbar on Dark Themes
* Improve async loading, events, and performance
* CSS typo
* Fix double scrollbar on mobile
* Fix regression causing sticky to not be removed
* No $ for non-jQuery variables
* Fix strange condition + option for nice scrollbar
* Initial attempt to use css sticky
* Add stickyfill
* make the correct element sticky
* re-add incorrectly removed sidebar code
* Continue fixing mistaken deletions
* decrease frequency of recalc
* use minified version of simple-scrollbar.
* Load stickyfill instead of injecting
* put recalc back where it belongs
* re-remove script injector
* remove padding
bottom padding was causing the last item in the feed to be hidden under the nav buttons
* Manual merge of css_scrollbar
Add auto-detection of -webkit-scrollbar-thumb, otherwise fall back to
simple-scrollbar.js
* Fix Regression
Sticky recalc is still needed when using css scrollbars
* Replace method of closing dropdowns
Changed from an overlay href to a javascript solution, for better compatibility
* Remove Treepadding
Treepadding was causing dropdown menus at the bottom of the tree to be obscured.
* Undo unnecessary move of dropdown-target
* Move Dropdown Handler to a sensibleish place
* Fix light Scrollbar color not picking up on Firefox
* Minor syntax
* Minor Clarification of CSS/ patch BlueLagoon
* Change logic for native WebKit scrollbar detection
Fix
https://github.com/FreshRSS/FreshRSS/pull/2117#issuecomment-444251419
Tested with Firefox 63, Firefox 65, Chrome 71, IE11, Edge 42
* Fixes for other views
E.g. reader view
* Cleaner way of generating hash for dropdowns
* Make dropdown-toggle an actual toggle
* Prepare for CSS Scrollbars Module Level 1
* Fix regression causing my labels dropdown not to appear
* remove unneeded dropdown-close css rule
* Re-apply some lost changes
https://github.com/FreshRSS/FreshRSS/pull/2117/commits/3c509989e890b88852e52c67c1c5507d1e0bf28c
* Add standard scrollbar compatibility
E.g. Firefox 64+
* Make All dropdowns click-to-close
* Remove BlueLagoon template
* Try to fix Firefox
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r239539984
* Add CSS rules necessary for consistent function of scrollbar in Firefox
* Use inheritance to determine width
* Use overlay scrollbar where possible
* Test Reduced Listener
* Fix Firefox 62
And show subtle scrollbar even when not hovering
* Add margin at bottom
To allow opening the menus
https://github.com/FreshRSS/FreshRSS/pull/2117#issuecomment-444571218
* Minor - tab correction
* Spaces -> tabs
* Remove unneeded inheritance
* Fix indenting
* Revert bad merge
* Messy WIP to make dropdowns work
* Style Cleanup
* Break it down
* Lets try a move-it move-it
* Update p/scripts/main.js
Co-Authored-By: pattems <patrick@crandol.com>
* Update p/themes/BlueLagoon/BlueLagoon.css
Co-Authored-By: pattems <patrick@crandol.com>
* separate ALL THE THINGS
* erroneous commas
* and to or
* removing double condition that doesn't do what I want
* More breaking down
* fix var
* Fix variable name again
* Remove magic number
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240052598
* Suuuuper inelegant solution for dropdowns
* lets try that again
* Inelegant Fix For Dropdowns
Now with 100% more working dropdowns
* Make sidebar dropdowns work correctly?
* Fix reversion
* Make JS scrollbar always visible
* Remove unneeded CSS
Added early in this pull request, didn't get pulled out when it was obsolete
* Fix CSS removal I missed
* CSS comment update/consistency for dark themes
* Clean Up Duplicate code
* Make dropdowns properly hide
Downside: Can no longer click on header/nav buttons to close
* Strip unneeded if statement
* jshint -W018
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240392851
* Half-reversion to old dropdown
* make overlay href scale to sidebar width
* remove init of nonexistent method
* remove trailing tabs
* move #close href where it belongs in index.phtml
* Revert all changes to index.phtml
* remove whitespace
accidentally added in last commit
* Move var's in init_column categories
* Finish putting old style dropdowns back
* Make CSS changes to use support statements
* Cleanup Whitespace
* re-add missing class
* spaces -> tabs in main.js
* tabs -> spaces css
* Minor whitespace
* Cleanup per @Alkarex
* Second attempt to add bottom margin
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240820901
* Fix error in IE11
* Simple-scrollbar color match for dark themes
2018-12-12 12:04:31 +01:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
a = ev.target.closest('.tree-folder-items > .feed .dropdown-toggle');
|
|
|
|
|
if (a) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const itemId = a.closest('.item').id;
|
|
|
|
|
const templateId = itemId.substring(0, 2) === 't_' ? 'tag_config_template' : 'feed_config_template';
|
|
|
|
|
const id = itemId.substr(2);
|
|
|
|
|
const feed_web = a.getAttribute('data-fweb');
|
|
|
|
|
const div = a.parentElement;
|
|
|
|
|
const dropdownMenu = div.querySelector('.dropdown-menu');
|
|
|
|
|
const template = document.getElementById(templateId)
|
|
|
|
|
.innerHTML.replace(/------/g, id).replace('http://example.net/', feed_web);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (!dropdownMenu) {
|
|
|
|
|
a.href = '#dropdown-' + id;
|
|
|
|
|
div.querySelector('.dropdown-target').id = 'dropdown-' + id;
|
|
|
|
|
div.insertAdjacentHTML('beforeend', template);
|
2019-04-06 17:05:53 +02:00
|
|
|
|
const b = div.querySelector('button.confirm');
|
|
|
|
|
if (b) {
|
|
|
|
|
b.disabled = false;
|
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
} else if (getComputedStyle(dropdownMenu).display === 'none') {
|
|
|
|
|
const id2 = div.closest('.item').id.substr(2);
|
|
|
|
|
a.href = '#dropdown-' + id2;
|
Decouple scrolling of feeds and articles (#2117)
* Remove Sticky Kit
Remove sticky-kit, as functionality is unsuitable for separate scrolling.
* Remove sticky-kit load in main.js
Further removing the sticky-kit kruft
* Finish removal of references to Sticky-kit
* CSS Changes to template for Independent Scrolling
* Addition of JS and supporting CSS and html
* More CSS fixes to establish expected behavior
Should be able to scroll navbar without it being in sticky mode now.
* Fix typo in main.js
sortcut.js -> shortcut.js
* Fix unexpected tree scrolling behavior
* Change name of generic JS function
* Improve sticky-aside
* CSS changes in themes to accommodate independent Scroll
In themes where .aside's width is not the standard 300px, .tree's width must be specified to be equal to .aside
* Remove Sticky-Kit from README files
* Updates to Sticky-Aside
* Update Template to fix screwup
* Make Recalculating height actually work
* Let sidebar fill height if nav buttons aren't visible
* Make accommodating for nav buttons actually work
* update Swage theme for Independent Scroll feature
* Integrate sticky_aside into main.js
* Add Simple Scrollbar
* Patch scrollbar color for themes with dark colored asides
* Increase Visibility of scrollbar on Dark Themes
* Improve async loading, events, and performance
* CSS typo
* Fix double scrollbar on mobile
* Fix regression causing sticky to not be removed
* No $ for non-jQuery variables
* Fix strange condition + option for nice scrollbar
* Initial attempt to use css sticky
* Add stickyfill
* make the correct element sticky
* re-add incorrectly removed sidebar code
* Continue fixing mistaken deletions
* decrease frequency of recalc
* use minified version of simple-scrollbar.
* Load stickyfill instead of injecting
* put recalc back where it belongs
* re-remove script injector
* remove padding
bottom padding was causing the last item in the feed to be hidden under the nav buttons
* Manual merge of css_scrollbar
Add auto-detection of -webkit-scrollbar-thumb, otherwise fall back to
simple-scrollbar.js
* Fix Regression
Sticky recalc is still needed when using css scrollbars
* Replace method of closing dropdowns
Changed from an overlay href to a javascript solution, for better compatibility
* Remove Treepadding
Treepadding was causing dropdown menus at the bottom of the tree to be obscured.
* Undo unnecessary move of dropdown-target
* Move Dropdown Handler to a sensibleish place
* Fix light Scrollbar color not picking up on Firefox
* Minor syntax
* Minor Clarification of CSS/ patch BlueLagoon
* Change logic for native WebKit scrollbar detection
Fix
https://github.com/FreshRSS/FreshRSS/pull/2117#issuecomment-444251419
Tested with Firefox 63, Firefox 65, Chrome 71, IE11, Edge 42
* Fixes for other views
E.g. reader view
* Cleaner way of generating hash for dropdowns
* Make dropdown-toggle an actual toggle
* Prepare for CSS Scrollbars Module Level 1
* Fix regression causing my labels dropdown not to appear
* remove unneeded dropdown-close css rule
* Re-apply some lost changes
https://github.com/FreshRSS/FreshRSS/pull/2117/commits/3c509989e890b88852e52c67c1c5507d1e0bf28c
* Add standard scrollbar compatibility
E.g. Firefox 64+
* Make All dropdowns click-to-close
* Remove BlueLagoon template
* Try to fix Firefox
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r239539984
* Add CSS rules necessary for consistent function of scrollbar in Firefox
* Use inheritance to determine width
* Use overlay scrollbar where possible
* Test Reduced Listener
* Fix Firefox 62
And show subtle scrollbar even when not hovering
* Add margin at bottom
To allow opening the menus
https://github.com/FreshRSS/FreshRSS/pull/2117#issuecomment-444571218
* Minor - tab correction
* Spaces -> tabs
* Remove unneeded inheritance
* Fix indenting
* Revert bad merge
* Messy WIP to make dropdowns work
* Style Cleanup
* Break it down
* Lets try a move-it move-it
* Update p/scripts/main.js
Co-Authored-By: pattems <patrick@crandol.com>
* Update p/themes/BlueLagoon/BlueLagoon.css
Co-Authored-By: pattems <patrick@crandol.com>
* separate ALL THE THINGS
* erroneous commas
* and to or
* removing double condition that doesn't do what I want
* More breaking down
* fix var
* Fix variable name again
* Remove magic number
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240052598
* Suuuuper inelegant solution for dropdowns
* lets try that again
* Inelegant Fix For Dropdowns
Now with 100% more working dropdowns
* Make sidebar dropdowns work correctly?
* Fix reversion
* Make JS scrollbar always visible
* Remove unneeded CSS
Added early in this pull request, didn't get pulled out when it was obsolete
* Fix CSS removal I missed
* CSS comment update/consistency for dark themes
* Clean Up Duplicate code
* Make dropdowns properly hide
Downside: Can no longer click on header/nav buttons to close
* Strip unneeded if statement
* jshint -W018
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240392851
* Half-reversion to old dropdown
* make overlay href scale to sidebar width
* remove init of nonexistent method
* remove trailing tabs
* move #close href where it belongs in index.phtml
* Revert all changes to index.phtml
* remove whitespace
accidentally added in last commit
* Move var's in init_column categories
* Finish putting old style dropdowns back
* Make CSS changes to use support statements
* Cleanup Whitespace
* re-add missing class
* spaces -> tabs in main.js
* tabs -> spaces css
* Minor whitespace
* Cleanup per @Alkarex
* Second attempt to add bottom margin
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240820901
* Fix error in IE11
* Simple-scrollbar color match for dark themes
2018-12-12 12:04:31 +01:00
|
|
|
|
} else {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
a.href = '#close';
|
Decouple scrolling of feeds and articles (#2117)
* Remove Sticky Kit
Remove sticky-kit, as functionality is unsuitable for separate scrolling.
* Remove sticky-kit load in main.js
Further removing the sticky-kit kruft
* Finish removal of references to Sticky-kit
* CSS Changes to template for Independent Scrolling
* Addition of JS and supporting CSS and html
* More CSS fixes to establish expected behavior
Should be able to scroll navbar without it being in sticky mode now.
* Fix typo in main.js
sortcut.js -> shortcut.js
* Fix unexpected tree scrolling behavior
* Change name of generic JS function
* Improve sticky-aside
* CSS changes in themes to accommodate independent Scroll
In themes where .aside's width is not the standard 300px, .tree's width must be specified to be equal to .aside
* Remove Sticky-Kit from README files
* Updates to Sticky-Aside
* Update Template to fix screwup
* Make Recalculating height actually work
* Let sidebar fill height if nav buttons aren't visible
* Make accommodating for nav buttons actually work
* update Swage theme for Independent Scroll feature
* Integrate sticky_aside into main.js
* Add Simple Scrollbar
* Patch scrollbar color for themes with dark colored asides
* Increase Visibility of scrollbar on Dark Themes
* Improve async loading, events, and performance
* CSS typo
* Fix double scrollbar on mobile
* Fix regression causing sticky to not be removed
* No $ for non-jQuery variables
* Fix strange condition + option for nice scrollbar
* Initial attempt to use css sticky
* Add stickyfill
* make the correct element sticky
* re-add incorrectly removed sidebar code
* Continue fixing mistaken deletions
* decrease frequency of recalc
* use minified version of simple-scrollbar.
* Load stickyfill instead of injecting
* put recalc back where it belongs
* re-remove script injector
* remove padding
bottom padding was causing the last item in the feed to be hidden under the nav buttons
* Manual merge of css_scrollbar
Add auto-detection of -webkit-scrollbar-thumb, otherwise fall back to
simple-scrollbar.js
* Fix Regression
Sticky recalc is still needed when using css scrollbars
* Replace method of closing dropdowns
Changed from an overlay href to a javascript solution, for better compatibility
* Remove Treepadding
Treepadding was causing dropdown menus at the bottom of the tree to be obscured.
* Undo unnecessary move of dropdown-target
* Move Dropdown Handler to a sensibleish place
* Fix light Scrollbar color not picking up on Firefox
* Minor syntax
* Minor Clarification of CSS/ patch BlueLagoon
* Change logic for native WebKit scrollbar detection
Fix
https://github.com/FreshRSS/FreshRSS/pull/2117#issuecomment-444251419
Tested with Firefox 63, Firefox 65, Chrome 71, IE11, Edge 42
* Fixes for other views
E.g. reader view
* Cleaner way of generating hash for dropdowns
* Make dropdown-toggle an actual toggle
* Prepare for CSS Scrollbars Module Level 1
* Fix regression causing my labels dropdown not to appear
* remove unneeded dropdown-close css rule
* Re-apply some lost changes
https://github.com/FreshRSS/FreshRSS/pull/2117/commits/3c509989e890b88852e52c67c1c5507d1e0bf28c
* Add standard scrollbar compatibility
E.g. Firefox 64+
* Make All dropdowns click-to-close
* Remove BlueLagoon template
* Try to fix Firefox
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r239539984
* Add CSS rules necessary for consistent function of scrollbar in Firefox
* Use inheritance to determine width
* Use overlay scrollbar where possible
* Test Reduced Listener
* Fix Firefox 62
And show subtle scrollbar even when not hovering
* Add margin at bottom
To allow opening the menus
https://github.com/FreshRSS/FreshRSS/pull/2117#issuecomment-444571218
* Minor - tab correction
* Spaces -> tabs
* Remove unneeded inheritance
* Fix indenting
* Revert bad merge
* Messy WIP to make dropdowns work
* Style Cleanup
* Break it down
* Lets try a move-it move-it
* Update p/scripts/main.js
Co-Authored-By: pattems <patrick@crandol.com>
* Update p/themes/BlueLagoon/BlueLagoon.css
Co-Authored-By: pattems <patrick@crandol.com>
* separate ALL THE THINGS
* erroneous commas
* and to or
* removing double condition that doesn't do what I want
* More breaking down
* fix var
* Fix variable name again
* Remove magic number
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240052598
* Suuuuper inelegant solution for dropdowns
* lets try that again
* Inelegant Fix For Dropdowns
Now with 100% more working dropdowns
* Make sidebar dropdowns work correctly?
* Fix reversion
* Make JS scrollbar always visible
* Remove unneeded CSS
Added early in this pull request, didn't get pulled out when it was obsolete
* Fix CSS removal I missed
* CSS comment update/consistency for dark themes
* Clean Up Duplicate code
* Make dropdowns properly hide
Downside: Can no longer click on header/nav buttons to close
* Strip unneeded if statement
* jshint -W018
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240392851
* Half-reversion to old dropdown
* make overlay href scale to sidebar width
* remove init of nonexistent method
* remove trailing tabs
* move #close href where it belongs in index.phtml
* Revert all changes to index.phtml
* remove whitespace
accidentally added in last commit
* Move var's in init_column categories
* Finish putting old style dropdowns back
* Make CSS changes to use support statements
* Cleanup Whitespace
* re-add missing class
* spaces -> tabs in main.js
* tabs -> spaces css
* Minor whitespace
* Cleanup per @Alkarex
* Second attempt to add bottom margin
https://github.com/FreshRSS/FreshRSS/pull/2117#discussion_r240820901
* Fix error in IE11
* Simple-scrollbar color match for dark themes
2018-12-12 12:04:31 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
return true;
|
2014-01-12 20:26:26 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
function init_shortcuts() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
Object.keys(context.shortcuts).forEach(function (k) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
context.shortcuts[k] = (context.shortcuts[k] || '').toUpperCase();
|
|
|
|
|
});
|
2014-08-24 17:34:58 +02:00
|
|
|
|
|
2021-10-19 10:05:30 +02:00
|
|
|
|
document.addEventListener('keydown', ev => {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (ev.target.closest('input, textarea') ||
|
2019-02-13 15:06:28 +01:00
|
|
|
|
ev.ctrlKey || ev.metaKey || (ev.altKey && ev.shiftKey)) {
|
2021-12-03 00:58:40 +01:00
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2016-08-06 13:18:46 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const s = context.shortcuts;
|
|
|
|
|
let k = (ev.key.trim() || ev.code || 'Space').toUpperCase();
|
|
|
|
|
|
|
|
|
|
// IE11
|
|
|
|
|
if (k === 'SPACEBAR') k = 'SPACE';
|
|
|
|
|
else if (k === 'DEL') k = 'DELETE';
|
|
|
|
|
else if (k === 'ESC') k = 'ESCAPE';
|
|
|
|
|
|
|
|
|
|
if (location.hash.match(/^#dropdown-/)) {
|
|
|
|
|
const n = parseInt(k);
|
|
|
|
|
if (n) {
|
|
|
|
|
if (location.hash === '#dropdown-query') {
|
|
|
|
|
user_filter(n);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
} else {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
auto_share(n);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2021-11-02 23:45:38 +01:00
|
|
|
|
if (k === s.actualize) {
|
|
|
|
|
const btn = document.getElementById('actualize');
|
|
|
|
|
if (btn) {
|
|
|
|
|
btn.click();
|
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-11-02 23:45:38 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (k === s.next_entry) {
|
|
|
|
|
if (ev.altKey) {
|
|
|
|
|
next_category();
|
|
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
|
next_feed();
|
|
|
|
|
} else {
|
|
|
|
|
next_entry(false);
|
2021-10-19 10:46:39 +02:00
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.next_unread_entry) {
|
|
|
|
|
if (ev.altKey) {
|
|
|
|
|
next_unread_category();
|
|
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
|
next_feed();
|
|
|
|
|
} else {
|
|
|
|
|
next_unread_entry(false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.prev_entry) {
|
|
|
|
|
if (ev.altKey) {
|
|
|
|
|
prev_category();
|
|
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
|
prev_feed();
|
|
|
|
|
} else {
|
|
|
|
|
prev_entry(false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.mark_read) {
|
|
|
|
|
if (ev.altKey) {
|
|
|
|
|
mark_previous_read(document.querySelector('.flux.current'));
|
|
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
|
document.querySelector('.nav_menu .read_all').click();
|
|
|
|
|
} else { // Toggle the read state
|
|
|
|
|
mark_read(document.querySelector('.flux.current'), false, false);
|
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.first_entry) {
|
|
|
|
|
if (ev.altKey) {
|
|
|
|
|
first_category();
|
|
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
|
first_feed();
|
|
|
|
|
} else {
|
|
|
|
|
const old_active = document.querySelector('.flux.current');
|
|
|
|
|
const first = document.querySelector('.flux');
|
|
|
|
|
if (first.classList.contains('flux')) {
|
|
|
|
|
toggleContent(first, old_active, false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.last_entry) {
|
|
|
|
|
if (ev.altKey) {
|
|
|
|
|
last_category();
|
|
|
|
|
} else if (ev.shiftKey) {
|
|
|
|
|
last_feed();
|
|
|
|
|
} else {
|
|
|
|
|
const old_active = document.querySelector('.flux.current');
|
|
|
|
|
const last = document.querySelector('.flux:last-of-type');
|
|
|
|
|
if (last.classList.contains('flux')) {
|
|
|
|
|
toggleContent(last, old_active, false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2013-10-13 17:55:03 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (ev.altKey || ev.shiftKey) {
|
2021-12-03 00:58:40 +01:00
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.mark_favorite) { // Toggle the favorite state
|
|
|
|
|
mark_favorite(document.querySelector('.flux.current'));
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
if (k === s.go_website) {
|
|
|
|
|
if (context.auto_mark_site) {
|
|
|
|
|
mark_read(document.querySelector('.flux.current'), true, false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const newWindow = window.open();
|
|
|
|
|
if (newWindow) {
|
|
|
|
|
newWindow.opener = null;
|
|
|
|
|
newWindow.location = document.querySelector('.flux.current a.go_website').href;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2021-12-03 00:58:40 +01:00
|
|
|
|
if (k === s.skip_next_entry) { next_entry(true); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.skip_prev_entry) { prev_entry(true); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.collapse_entry) { collapse_entry(); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.auto_share) { auto_share(); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.user_filter) { user_filter(); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.load_more) { load_more_posts(); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.close_dropdown) { location.hash = null; ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.help) { window.open(context.urls.help); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.focus_search) { document.getElementById('search').focus(); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.normal_view) { delayedClick(document.querySelector('#nav_menu_views .view-normal')); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.reading_view) { delayedClick(document.querySelector('#nav_menu_views .view-reader')); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.global_view) { delayedClick(document.querySelector('#nav_menu_views .view-global')); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.rss_view) { delayedClick(document.querySelector('#nav_menu_views .view-rss')); ev.preventDefault(); return; }
|
|
|
|
|
if (k === s.toggle_media) { toggle_media(); ev.preventDefault(); }
|
2021-10-21 11:44:03 +02:00
|
|
|
|
});
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2013-10-13 17:55:03 +02:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
function init_stream(stream) {
|
|
|
|
|
stream.onclick = function (ev) {
|
|
|
|
|
let el = ev.target.closest('.flux a.read');
|
|
|
|
|
if (el) {
|
2019-04-06 15:51:39 +02:00
|
|
|
|
mark_read(el.closest('.flux'), false, false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
return false;
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
el = ev.target.closest('.flux a.bookmark');
|
|
|
|
|
if (el) {
|
|
|
|
|
mark_favorite(el.closest('.flux'));
|
|
|
|
|
return false;
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
el = ev.target.closest('.dynamictags');
|
|
|
|
|
if (el) {
|
|
|
|
|
loadDynamicTags(el);
|
|
|
|
|
return true;
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
el = ev.target.closest('.item.title > a');
|
2022-01-08 16:25:17 +01:00
|
|
|
|
if (el) { // Allow default control-click behaviour such as open in background-tab
|
2019-02-13 15:06:28 +01:00
|
|
|
|
return ev.ctrlKey;
|
2017-05-22 09:33:55 +02:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
|
|
|
|
el = ev.target.closest('.flux .content a');
|
|
|
|
|
if (el) {
|
|
|
|
|
if (!el.closest('div').classList.contains('author')) {
|
|
|
|
|
el.target = '_blank';
|
|
|
|
|
el.rel = 'noreferrer';
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-16 23:23:15 +01:00
|
|
|
|
el = ev.target.closest('.item.share > button[data-type="print"]');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (el) { // Print
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const tmp_window = window.open();
|
2021-10-21 11:44:03 +02:00
|
|
|
|
for (let i = 0; i < document.styleSheets.length; i++) {
|
2019-04-16 08:04:00 +02:00
|
|
|
|
tmp_window.document.writeln('<link href="' + document.styleSheets[i].href + '" rel="stylesheet" type="text/css" />');
|
|
|
|
|
}
|
|
|
|
|
tmp_window.document.writeln(el.closest('.flux_content').querySelector('.content').innerHTML);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
tmp_window.document.close();
|
|
|
|
|
tmp_window.focus();
|
|
|
|
|
tmp_window.print();
|
|
|
|
|
tmp_window.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-13 17:55:03 +02:00
|
|
|
|
|
2022-03-16 23:23:15 +01:00
|
|
|
|
el = ev.target.closest('.item.share > button[data-type="clipboard"]');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (el && navigator.clipboard) { // Clipboard
|
2022-03-16 23:23:15 +01:00
|
|
|
|
navigator.clipboard.writeText(el.dataset.url);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
el = ev.target.closest('.item.share > button[data-type="web-sharing-api"]');
|
|
|
|
|
if (el && navigator.share) { // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
|
|
|
|
|
const shareData = {
|
|
|
|
|
url: el.dataset.url,
|
|
|
|
|
title: decodeURI(el.dataset.title),
|
|
|
|
|
};
|
|
|
|
|
navigator.share(shareData);
|
2021-01-03 18:20:15 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
el = ev.target.closest('.item.share > a[href="POST"]');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (el) { // Share by POST
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const f = el.parentElement.querySelector('form');
|
|
|
|
|
f.disabled = false;
|
|
|
|
|
f.submit();
|
|
|
|
|
return false;
|
2014-09-16 17:44:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
el = ev.target.closest('.flux_header, .flux_content');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (el) { // flux_toggle
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (ev.target.closest('.content, .item.website, .item.link, .dropdown-menu')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (!context.sides_close_article && ev.target.matches('div.flux_content')) {
|
|
|
|
|
// setting for not-closing after clicking outside article area
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const old_active = document.querySelector('.flux.current');
|
|
|
|
|
const new_active = el.parentNode;
|
|
|
|
|
if (ev.target.tagName.toUpperCase() === 'A') { // Leave real links alone
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (context.auto_mark_article) {
|
2019-04-06 15:51:39 +02:00
|
|
|
|
mark_read(new_active, true, false);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
toggleContent(new_active, old_active, false);
|
|
|
|
|
return false;
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
};
|
2013-10-13 17:55:03 +02:00
|
|
|
|
|
2022-03-16 23:23:15 +01:00
|
|
|
|
if (!navigator.share) {
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
|
|
|
|
|
// do not show the menu entry if browser does not support navigator.share
|
|
|
|
|
document.styleSheets[0].insertRule(
|
|
|
|
|
'button.as-link[data-type="web-sharing-api"] {display: none !important;}',
|
|
|
|
|
document.styleSheets[0].cssRules.length
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-02 22:46:56 +02:00
|
|
|
|
stream.onmouseup = function (ev) { // Mouseup enables us to catch middle click, and control+click in IE/Edge
|
|
|
|
|
if (ev.altKey || ev.metaKey || ev.shiftKey) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
let el = ev.target.closest('.item.title > a');
|
|
|
|
|
if (el) {
|
2019-04-02 22:46:56 +02:00
|
|
|
|
if (ev.which == 1) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (ev.ctrlKey) { // Control+click
|
2019-04-02 22:46:56 +02:00
|
|
|
|
if (context.auto_mark_site) {
|
2019-04-06 15:51:39 +02:00
|
|
|
|
mark_read(el.closest('.flux'), true, false);
|
2019-04-02 22:46:56 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
el.parentElement.click(); // Normal click, just toggle article.
|
2019-04-02 22:46:56 +02:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
} else if (ev.which == 2 && !ev.ctrlKey) { // Simple middle click: same behaviour as CTRL+click
|
2019-04-02 22:46:56 +02:00
|
|
|
|
if (context.auto_mark_article) {
|
|
|
|
|
const new_active = el.closest('.flux');
|
2019-04-06 15:51:39 +02:00
|
|
|
|
mark_read(new_active, true, false);
|
2019-04-02 22:46:56 +02:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2019-04-02 22:46:56 +02:00
|
|
|
|
return;
|
2018-09-16 10:46:27 +02:00
|
|
|
|
}
|
2014-01-10 18:15:52 +01:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (context.auto_mark_site) {
|
|
|
|
|
// catch mouseup instead of click so we can have the correct behaviour
|
|
|
|
|
// with middle button click (scroll button).
|
|
|
|
|
el = ev.target.closest('.flux .link > a');
|
|
|
|
|
if (el) {
|
|
|
|
|
if (ev.which == 3) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-06 15:51:39 +02:00
|
|
|
|
mark_read(el.closest('.flux'), true, false);
|
2014-09-16 17:44:51 +02:00
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
2014-09-16 17:44:51 +02:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
stream.onchange = function (ev) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const checkboxTag = ev.target.closest('.checkboxTag');
|
|
|
|
|
if (checkboxTag) { // Dynamic tags
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
const isChecked = checkboxTag.checked;
|
|
|
|
|
const tagId = checkboxTag.name.replace(/^t_/, '');
|
|
|
|
|
const tagName = checkboxTag.nextElementSibling ? checkboxTag.nextElementSibling.value : '';
|
|
|
|
|
const entry = checkboxTag.closest('div.flux');
|
|
|
|
|
const entryId = entry.id.replace(/^flux_/, '');
|
|
|
|
|
checkboxTag.disabled = true;
|
|
|
|
|
|
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('POST', './?c=tag&a=tagEntry', true);
|
|
|
|
|
req.responseType = 'json';
|
|
|
|
|
req.onerror = function (e) {
|
|
|
|
|
checkboxTag.checked = !isChecked;
|
|
|
|
|
badAjax(this.status == 403);
|
|
|
|
|
};
|
|
|
|
|
req.onload = function (e) {
|
|
|
|
|
if (this.status != 200) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
if (entry.classList.contains('not_read')) {
|
|
|
|
|
incUnreadsTag('t_' + tagId, isChecked ? 1 : -1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
req.onloadend = function (e) {
|
|
|
|
|
checkboxTag.disabled = false;
|
|
|
|
|
if (tagId == 0) {
|
|
|
|
|
loadDynamicTags(checkboxTag.closest('div.dropdown'));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
req.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req.send(JSON.stringify({
|
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
id_tag: tagId,
|
|
|
|
|
name_tag: tagId == 0 ? tagName : '',
|
|
|
|
|
id_entry: entryId,
|
|
|
|
|
checked: isChecked,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init_nav_entries() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const nav_entries = document.getElementById('nav_entries');
|
|
|
|
|
if (nav_entries) {
|
|
|
|
|
nav_entries.querySelector('.previous_entry').onclick = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
prev_entry(false);
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
nav_entries.querySelector('.next_entry').onclick = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
next_entry(false);
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
nav_entries.querySelector('.up').onclick = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const active_item = (document.querySelector('.flux.current') || document.querySelector('.flux'));
|
|
|
|
|
const windowTop = document.scrollingElement.scrollTop;
|
|
|
|
|
const item_top = active_item.offsetParent.offsetTop + active_item.offsetTop;
|
2013-10-13 17:55:03 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
document.scrollingElement.scrollTop = windowTop > item_top ? item_top : 0;
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
function loadDynamicTags(div) {
|
|
|
|
|
div.classList.remove('dynamictags');
|
|
|
|
|
div.querySelectorAll('li.item').forEach(function (li) { li.remove(); });
|
|
|
|
|
const entryId = div.closest('div.flux').id.replace(/^flux_/, '');
|
|
|
|
|
|
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('GET', './?c=tag&a=getTagsForEntry&id_entry=' + entryId, true);
|
|
|
|
|
req.responseType = 'json';
|
|
|
|
|
req.onerror = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
div.querySelectorAll('li.item').forEach(function (li) { li.remove(); });
|
|
|
|
|
div.classList.add('dynamictags');
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.onload = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (this.status != 200) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
const json = xmlHttpRequestJson(this);
|
|
|
|
|
if (!json) {
|
|
|
|
|
return req.onerror(e);
|
|
|
|
|
}
|
|
|
|
|
let html = '<li class="item"><label><input class="checkboxTag" name="t_0" type="checkbox" /> <input type="text" name="newTag" /></label></li>';
|
|
|
|
|
if (json && json.length) {
|
|
|
|
|
for (let i = 0; i < json.length; i++) {
|
|
|
|
|
const tag = json[i];
|
|
|
|
|
html += '<li class="item"><label><input class="checkboxTag" name="t_' + tag.id + '" type="checkbox"' +
|
2019-02-13 15:06:28 +01:00
|
|
|
|
(tag.checked ? ' checked="checked"' : '') + '> ' + tag.name + '</label></li>';
|
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
div.querySelector('.dropdown-menu').insertAdjacentHTML('beforeend', html);
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.send();
|
2018-09-29 20:47:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-27 17:51:13 +01:00
|
|
|
|
// <actualize>
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let feed_processed = 0;
|
2016-02-27 17:51:13 +01:00
|
|
|
|
|
|
|
|
|
function updateFeed(feeds, feeds_count) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
const feed = feeds.pop();
|
2016-08-06 13:18:46 +02:00
|
|
|
|
if (!feed) {
|
2016-02-27 17:51:13 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('POST', feed.url, true);
|
|
|
|
|
req.onloadend = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (this.status != 200) {
|
|
|
|
|
return badAjax(false);
|
|
|
|
|
}
|
|
|
|
|
feed_processed++;
|
|
|
|
|
const div = document.getElementById('actualizeProgress');
|
|
|
|
|
div.querySelector('.progress').innerHTML = feed_processed + ' / ' + feeds_count;
|
|
|
|
|
div.querySelector('.title').innerHTML = feed.title;
|
|
|
|
|
if (feed_processed === feeds_count) {
|
|
|
|
|
// Empty request to commit new articles
|
|
|
|
|
const req2 = new XMLHttpRequest();
|
|
|
|
|
req2.open('POST', './?c=feed&a=actualize&id=-1&ajax=1', true);
|
|
|
|
|
req2.onloadend = function (e) {
|
|
|
|
|
delayedFunction(function () { location.reload(); });
|
|
|
|
|
};
|
|
|
|
|
req2.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req2.send(JSON.stringify({
|
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
noCommit: 0,
|
|
|
|
|
}));
|
|
|
|
|
} else {
|
|
|
|
|
updateFeed(feeds, feeds_count);
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req.send(JSON.stringify({
|
2021-10-21 11:44:03 +02:00
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
noCommit: 1,
|
|
|
|
|
}));
|
2016-02-27 17:51:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-13 17:55:03 +02:00
|
|
|
|
function init_actualize() {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
let auto = false;
|
2014-02-15 15:19:03 +01:00
|
|
|
|
|
2020-12-31 00:13:29 +01:00
|
|
|
|
const actualize = document.getElementById('actualize');
|
|
|
|
|
if (!actualize) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actualize.onclick = function () {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (context.ajax_loading) {
|
2014-07-09 20:20:17 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-02-13 15:06:28 +01:00
|
|
|
|
context.ajax_loading = true;
|
|
|
|
|
|
|
|
|
|
const req = new XMLHttpRequest();
|
2019-03-22 19:05:38 +01:00
|
|
|
|
req.open('POST', './?c=javascript&a=actualize', true);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.responseType = 'json';
|
|
|
|
|
req.onload = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (this.status != 200) {
|
|
|
|
|
return badAjax(false);
|
|
|
|
|
}
|
|
|
|
|
const json = xmlHttpRequestJson(this);
|
|
|
|
|
if (!json) {
|
|
|
|
|
return badAjax(false);
|
|
|
|
|
}
|
|
|
|
|
if (auto && json.feeds.length < 1) {
|
|
|
|
|
auto = false;
|
|
|
|
|
context.ajax_loading = false;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (json.feeds.length === 0) {
|
|
|
|
|
openNotification(json.feedback_no_refresh, 'good');
|
|
|
|
|
// Empty request to commit new articles
|
|
|
|
|
const req2 = new XMLHttpRequest();
|
|
|
|
|
req2.open('POST', './?c=feed&a=actualize&id=-1&ajax=1', true);
|
|
|
|
|
req2.onloadend = function (e) {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
context.ajax_loading = false;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
};
|
|
|
|
|
req2.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req2.send(JSON.stringify({
|
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
noCommit: 0,
|
|
|
|
|
}));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Progress bar
|
|
|
|
|
const feeds_count = json.feeds.length;
|
|
|
|
|
document.body.insertAdjacentHTML('beforeend', '<div id="actualizeProgress" class="notification good">' +
|
2019-02-13 15:06:28 +01:00
|
|
|
|
json.feedback_actualize + '<br /><span class="title">/</span><br /><span class="progress">0 / ' +
|
|
|
|
|
feeds_count + '</span></div>');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
for (let i = 10; i > 0; i--) {
|
|
|
|
|
updateFeed(json.feeds, feeds_count);
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-03-22 19:05:38 +01:00
|
|
|
|
req.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
|
req.send(JSON.stringify({
|
2021-10-21 11:44:03 +02:00
|
|
|
|
_csrf: context.csrf,
|
|
|
|
|
}));
|
2014-07-09 20:20:17 +02:00
|
|
|
|
|
2013-10-13 17:55:03 +02:00
|
|
|
|
return false;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
};
|
2013-11-09 23:16:13 +01:00
|
|
|
|
|
2016-08-06 13:18:46 +02:00
|
|
|
|
if (context.auto_actualize_feeds) {
|
2014-02-15 15:19:03 +01:00
|
|
|
|
auto = true;
|
2020-12-31 00:13:29 +01:00
|
|
|
|
actualize.click();
|
2013-11-09 23:16:13 +01:00
|
|
|
|
}
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
2016-02-27 17:51:13 +01:00
|
|
|
|
// </actualize>
|
2014-02-13 21:01:12 +01:00
|
|
|
|
|
|
|
|
|
// <notification>
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let notification = null;
|
|
|
|
|
let notification_interval = null;
|
|
|
|
|
let notification_working = false;
|
2014-02-13 21:01:12 +01:00
|
|
|
|
|
|
|
|
|
function openNotification(msg, status) {
|
|
|
|
|
if (notification_working === true) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
notification_working = true;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
notification.querySelector('.msg').innerHTML = msg;
|
|
|
|
|
notification.className = 'notification';
|
|
|
|
|
notification.classList.add(status);
|
2022-02-04 16:27:42 +01:00
|
|
|
|
if (status == 'good') {
|
|
|
|
|
notification_interval = setTimeout(closeNotification, 4000);
|
|
|
|
|
} else {
|
|
|
|
|
// no status or f.e. status = 'bad', give some more time to read
|
|
|
|
|
notification_interval = setTimeout(closeNotification, 8000);
|
|
|
|
|
}
|
2014-02-13 21:01:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
function closeNotification() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
notification.classList.add('closed');
|
|
|
|
|
clearInterval(notification_interval);
|
|
|
|
|
notification_working = false;
|
2013-10-26 17:29:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init_notifications() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
notification = document.getElementById('notification');
|
2013-10-26 17:29:53 +02:00
|
|
|
|
|
2022-02-04 16:27:42 +01:00
|
|
|
|
notification.querySelector('a.close').addEventListener('click', function (ev) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
closeNotification();
|
2022-02-04 16:27:42 +01:00
|
|
|
|
ev.preventDefault();
|
2021-10-21 11:44:03 +02:00
|
|
|
|
return false;
|
2022-02-04 16:27:42 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notification.addEventListener('mouseenter', function () {
|
|
|
|
|
clearInterval(notification_interval);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notification.addEventListener('mouseleave', function () {
|
|
|
|
|
notification_interval = setTimeout(closeNotification, 3000);
|
|
|
|
|
});
|
2014-02-13 21:01:12 +01:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (notification.querySelector('.msg').innerHTML.length > 0) {
|
2014-02-13 21:01:12 +01:00
|
|
|
|
notification_working = true;
|
2022-02-04 16:27:42 +01:00
|
|
|
|
if (notification.classList.contains('good')) {
|
|
|
|
|
notification_interval = setTimeout(closeNotification, 4000);
|
|
|
|
|
} else {
|
|
|
|
|
// no status or f.e. status = 'bad', give some more time to read
|
|
|
|
|
notification_interval = setTimeout(closeNotification, 8000);
|
|
|
|
|
}
|
2013-10-26 17:29:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-13 21:01:12 +01:00
|
|
|
|
// </notification>
|
2013-10-26 17:29:53 +02:00
|
|
|
|
|
2020-02-13 18:22:35 +01:00
|
|
|
|
// <popup>
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let popup = null;
|
|
|
|
|
let popup_iframe_container = null;
|
|
|
|
|
let popup_iframe = null;
|
|
|
|
|
let popup_txt = null;
|
|
|
|
|
let popup_working = false;
|
|
|
|
|
|
|
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
// TODO: Re-enable no-unused-vars
|
2020-02-13 18:22:35 +01:00
|
|
|
|
function openPopupWithMessage(msg) {
|
|
|
|
|
if (popup_working === true) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popup_working = true;
|
|
|
|
|
|
|
|
|
|
popup_txt.innerHTML = msg;
|
|
|
|
|
|
|
|
|
|
popup_txt.style.display = 'table-row';
|
|
|
|
|
popup.style.display = 'block';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openPopupWithSource(source) {
|
|
|
|
|
if (popup_working === true) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popup_working = true;
|
|
|
|
|
|
|
|
|
|
popup_iframe.src = source;
|
|
|
|
|
|
|
|
|
|
popup_iframe_container.style.display = 'table-row';
|
|
|
|
|
popup.style.display = 'block';
|
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
/* eslint-enable no-unused-vars */
|
2020-02-13 18:22:35 +01:00
|
|
|
|
|
|
|
|
|
function closePopup() {
|
|
|
|
|
popup.style.display = 'none';
|
|
|
|
|
popup_iframe_container.style.display = 'none';
|
|
|
|
|
popup_txt.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
popup_iframe.src = 'about:blank';
|
|
|
|
|
|
|
|
|
|
popup_working = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init_popup() {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// Fetch elements.
|
2020-02-13 18:22:35 +01:00
|
|
|
|
popup = document.getElementById('popup');
|
2021-11-14 23:24:47 +01:00
|
|
|
|
if (popup) {
|
|
|
|
|
popup_iframe_container = document.getElementById('popup-iframe-container');
|
|
|
|
|
popup_iframe = document.getElementById('popup-iframe');
|
2020-02-13 18:22:35 +01:00
|
|
|
|
|
2021-11-14 23:24:47 +01:00
|
|
|
|
popup_txt = document.getElementById('popup-txt');
|
2020-02-13 18:22:35 +01:00
|
|
|
|
|
2021-11-14 23:24:47 +01:00
|
|
|
|
// Configure close button.
|
|
|
|
|
document.getElementById('popup-close').addEventListener('click', function (ev) {
|
2020-02-13 18:22:35 +01:00
|
|
|
|
closePopup();
|
2021-11-14 23:24:47 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Configure close-on-click.
|
|
|
|
|
window.addEventListener('click', function (ev) {
|
|
|
|
|
if (ev.target == popup) {
|
|
|
|
|
closePopup();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-02-13 18:22:35 +01:00
|
|
|
|
}
|
|
|
|
|
// </popup>
|
|
|
|
|
|
2014-08-08 21:30:23 +02:00
|
|
|
|
// <notifs html5>
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let notifs_html5_permission = 'denied';
|
2014-08-08 21:30:23 +02:00
|
|
|
|
|
|
|
|
|
function notifs_html5_is_supported() {
|
|
|
|
|
return window.Notification !== undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function notifs_html5_ask_permission() {
|
|
|
|
|
window.Notification.requestPermission(function () {
|
|
|
|
|
notifs_html5_permission = window.Notification.permission;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-04 15:54:31 +01:00
|
|
|
|
function notifs_html5_show(nb, nb_new) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
if (notifs_html5_permission !== 'granted') {
|
2016-08-06 13:18:46 +02:00
|
|
|
|
return;
|
2014-08-08 21:30:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const notification = new window.Notification(context.i18n.notif_title_articles, {
|
2021-06-28 21:10:12 +02:00
|
|
|
|
icon: '../themes/icons/favicon-256-padding.png',
|
2022-02-04 15:54:31 +01:00
|
|
|
|
body: context.i18n.notif_body_new_articles.replace('%d', nb_new) + ' ' + context.i18n.notif_body_unread_articles.replace('%d', nb),
|
2018-12-25 01:30:28 +01:00
|
|
|
|
tag: 'freshRssNewArticles',
|
2014-08-08 21:30:23 +02:00
|
|
|
|
});
|
|
|
|
|
|
2018-12-25 16:09:48 +01:00
|
|
|
|
notification.onclick = function () {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
delayedFunction(function () {
|
|
|
|
|
location.reload();
|
|
|
|
|
window.focus();
|
|
|
|
|
notification.close();
|
|
|
|
|
});
|
|
|
|
|
};
|
2014-09-18 10:46:34 +02:00
|
|
|
|
|
2016-08-06 13:18:46 +02:00
|
|
|
|
if (context.html5_notif_timeout !== 0) {
|
2018-12-25 16:09:48 +01:00
|
|
|
|
setTimeout(function () {
|
2015-02-16 00:18:28 +01:00
|
|
|
|
notification.close();
|
2016-08-06 13:18:46 +02:00
|
|
|
|
}, context.html5_notif_timeout * 1000);
|
2014-09-18 10:46:34 +02:00
|
|
|
|
}
|
2014-08-08 21:30:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init_notifs_html5() {
|
|
|
|
|
if (!notifs_html5_is_supported()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notifs_html5_permission = notifs_html5_ask_permission();
|
|
|
|
|
}
|
|
|
|
|
// </notifs html5>
|
|
|
|
|
|
2014-01-09 23:17:35 +01:00
|
|
|
|
function refreshUnreads() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('GET', './?c=javascript&a=nbUnreadsPerFeed', true);
|
|
|
|
|
req.responseType = 'json';
|
|
|
|
|
req.onload = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const json = xmlHttpRequestJson(this);
|
|
|
|
|
if (!json) {
|
|
|
|
|
return badAjax(false);
|
|
|
|
|
}
|
|
|
|
|
const isAll = document.querySelector('.category.all.active');
|
|
|
|
|
let new_articles = false;
|
2021-12-07 23:19:58 +01:00
|
|
|
|
let nbUnreadFeeds = 0;
|
2022-02-04 15:54:31 +01:00
|
|
|
|
const title = document.querySelector('.category.all .title');
|
|
|
|
|
const nb_unreads_before = title ? str2int(title.getAttribute('data-unread')) : 0;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
Object.keys(json.feeds).forEach(function (feed_id) {
|
|
|
|
|
const nbUnreads = json.feeds[feed_id];
|
2021-12-07 23:19:58 +01:00
|
|
|
|
nbUnreadFeeds += nbUnreads;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
feed_id = 'f_' + feed_id;
|
|
|
|
|
const elem = document.getElementById(feed_id);
|
|
|
|
|
const feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && // Update of current view?
|
2019-02-13 15:06:28 +01:00
|
|
|
|
(nbUnreads - feed_unreads > 0)) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const newArticle = document.getElementById('new-article');
|
|
|
|
|
newArticle.setAttribute('aria-hidden', 'false');
|
|
|
|
|
newArticle.style.display = 'block';
|
|
|
|
|
new_articles = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-09-29 20:47:17 +02:00
|
|
|
|
|
2021-12-07 23:19:58 +01:00
|
|
|
|
const noArticlesToShow_div = document.getElementById('noArticlesToShow');
|
|
|
|
|
if (nbUnreadFeeds > 0 && noArticlesToShow_div) {
|
|
|
|
|
noArticlesToShow_div.classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
let nbUnreadTags = 0;
|
2018-09-29 20:47:17 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
Object.keys(json.tags).forEach(function (tag_id) {
|
|
|
|
|
const nbUnreads = json.tags[tag_id];
|
|
|
|
|
nbUnreadTags += nbUnreads;
|
|
|
|
|
const tag = document.getElementById('t_' + tag_id);
|
|
|
|
|
if (tag) {
|
|
|
|
|
tag.setAttribute('data-unread', nbUnreads);
|
|
|
|
|
tag.querySelector('.item-title').setAttribute('data-unread', numberFormat(nbUnreads));
|
2019-02-13 15:06:28 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
});
|
2018-09-29 20:47:17 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const tags = document.querySelector('.category.tags');
|
|
|
|
|
if (tags) {
|
|
|
|
|
tags.setAttribute('data-unread', nbUnreadTags);
|
|
|
|
|
tags.querySelector('.title').setAttribute('data-unread', numberFormat(nbUnreadTags));
|
|
|
|
|
}
|
2014-08-09 11:50:13 +02:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const nb_unreads = title ? str2int(title.getAttribute('data-unread')) : 0;
|
|
|
|
|
|
|
|
|
|
if (nb_unreads > 0 && new_articles) {
|
|
|
|
|
faviconNbUnread(nb_unreads);
|
2022-02-04 15:54:31 +01:00
|
|
|
|
const nb_new = nb_unreads - nb_unreads_before;
|
|
|
|
|
notifs_html5_show(nb_unreads, nb_new);
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.send();
|
2014-01-09 23:17:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// <endless_mode>
|
|
|
|
|
let url_load_more = '';
|
|
|
|
|
let load_more = false;
|
|
|
|
|
let box_load_more = null;
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
|
|
|
|
function load_more_posts() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
if (load_more || !url_load_more || !box_load_more) {
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
load_more = true;
|
2018-12-25 05:11:38 +01:00
|
|
|
|
document.getElementById('load_more').classList.add('loading');
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
|
req.open('GET', url_load_more, true);
|
|
|
|
|
req.responseType = 'document';
|
|
|
|
|
req.onload = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const html = this.response;
|
2022-02-06 17:29:56 +01:00
|
|
|
|
const streamFooter = document.getElementById('stream-footer');
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const streamAdopted = document.adoptNode(html.getElementById('stream'));
|
|
|
|
|
streamAdopted.querySelectorAll('.flux, .day').forEach(function (div) {
|
2022-02-06 17:29:56 +01:00
|
|
|
|
box_load_more.insertBefore(div, streamFooter);
|
2021-10-21 11:44:03 +02:00
|
|
|
|
});
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
2022-02-06 17:29:56 +01:00
|
|
|
|
const streamFooterOld = streamFooter.querySelector('.stream-footer-inner');
|
|
|
|
|
const streamFooterNew = streamAdopted.querySelector('.stream-footer-inner');
|
|
|
|
|
streamFooter.replaceChild(streamFooterNew, streamFooterOld);
|
2019-02-13 15:06:28 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const bigMarkAsRead = document.getElementById('bigMarkAsRead');
|
2021-11-15 22:03:26 +01:00
|
|
|
|
const readAll = document.querySelector('#nav_menu_read_all .read_all');
|
|
|
|
|
if (readAll && bigMarkAsRead && bigMarkAsRead.formAction) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (context.display_order === 'ASC') {
|
2021-11-15 22:03:26 +01:00
|
|
|
|
readAll.formAction = bigMarkAsRead.formAction;
|
2021-10-21 11:44:03 +02:00
|
|
|
|
} else {
|
2021-11-15 22:03:26 +01:00
|
|
|
|
bigMarkAsRead.formAction = readAll.formAction;
|
2013-11-26 18:44:03 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
}
|
2013-11-08 20:32:35 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
document.querySelectorAll('[id^=day_]').forEach(function (div) {
|
|
|
|
|
const ids = document.querySelectorAll('[id="' + div.id + '"]');
|
|
|
|
|
for (let i = ids.length - 1; i > 0; i--) { // Keep only the first
|
|
|
|
|
ids[i].remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
init_load_more(box_load_more);
|
2018-12-25 15:34:25 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const div_load_more = document.getElementById('load_more');
|
|
|
|
|
if (bigMarkAsRead) {
|
|
|
|
|
bigMarkAsRead.removeAttribute('disabled');
|
|
|
|
|
}
|
|
|
|
|
if (div_load_more) {
|
|
|
|
|
div_load_more.classList.remove('loading');
|
|
|
|
|
}
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
load_more = false;
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
req.send();
|
2014-04-27 17:00:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const freshrssLoadMoreEvent = document.createEvent('Event');
|
2016-10-06 19:07:54 +02:00
|
|
|
|
freshrssLoadMoreEvent.initEvent('freshrss:load-more', true, true);
|
|
|
|
|
|
2013-11-17 11:23:23 +01:00
|
|
|
|
function init_load_more(box) {
|
2014-01-18 19:29:44 +01:00
|
|
|
|
box_load_more = box;
|
2016-10-06 19:07:54 +02:00
|
|
|
|
document.body.dispatchEvent(freshrssLoadMoreEvent);
|
|
|
|
|
|
2022-02-06 17:29:56 +01:00
|
|
|
|
const next_button = document.getElementById('load_more');
|
|
|
|
|
if (!next_button) {
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
// no more article to load
|
2018-12-25 05:11:38 +01:00
|
|
|
|
url_load_more = '';
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
return;
|
2013-10-13 17:55:03 +02:00
|
|
|
|
}
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2022-02-06 17:29:56 +01:00
|
|
|
|
url_load_more = next_button.getAttribute('formaction');
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2022-02-06 17:29:56 +01:00
|
|
|
|
next_button.onclick = function (e) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
load_more_posts();
|
|
|
|
|
return false;
|
|
|
|
|
};
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// </endless_mode>
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
|
2019-02-13 15:06:28 +01:00
|
|
|
|
function init_confirm_action() {
|
|
|
|
|
document.body.onclick = function (ev) {
|
2021-10-21 11:44:03 +02:00
|
|
|
|
const b = ev.target.closest('.confirm');
|
|
|
|
|
if (b) {
|
|
|
|
|
let str_confirmation = this.getAttribute('data-str-confirm');
|
|
|
|
|
if (!str_confirmation) {
|
|
|
|
|
str_confirmation = context.i18n.confirmation_default;
|
2014-01-12 03:10:31 +01:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
return confirm(str_confirmation);
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-02-13 15:06:28 +01:00
|
|
|
|
document.querySelectorAll('button.confirm').forEach(function (b) { b.disabled = false; });
|
2014-03-15 15:08:44 +01:00
|
|
|
|
}
|
2014-03-15 12:08:58 +01:00
|
|
|
|
|
2014-08-02 01:33:33 +02:00
|
|
|
|
function faviconNbUnread(n) {
|
|
|
|
|
if (typeof n === 'undefined') {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const t = document.querySelector('.category.all .title');
|
|
|
|
|
n = t ? str2int(t.getAttribute('data-unread')) : 0;
|
2014-08-02 01:33:33 +02:00
|
|
|
|
}
|
2021-10-21 11:44:03 +02:00
|
|
|
|
// http://remysharp.com/2010/08/24/dynamic-favicons/
|
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
|
const link = document.getElementById('favicon').cloneNode(true);
|
|
|
|
|
const ratio = window.devicePixelRatio;
|
2014-08-02 01:33:33 +02:00
|
|
|
|
if (canvas.getContext && link) {
|
2019-09-28 12:10:52 +02:00
|
|
|
|
canvas.height = canvas.width = 16 * ratio;
|
2018-12-25 05:11:38 +01:00
|
|
|
|
const img = document.createElement('img');
|
2014-08-02 01:33:33 +02:00
|
|
|
|
img.onload = function () {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
const ctx = canvas.getContext('2d');
|
2014-08-02 15:33:00 +02:00
|
|
|
|
ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
|
2014-08-02 01:33:33 +02:00
|
|
|
|
if (n > 0) {
|
2018-12-25 05:11:38 +01:00
|
|
|
|
let text = '';
|
2014-08-02 11:43:43 +02:00
|
|
|
|
if (n < 1000) {
|
2014-08-02 02:12:20 +02:00
|
|
|
|
text = n;
|
2014-08-02 11:43:43 +02:00
|
|
|
|
} else if (n < 100000) {
|
|
|
|
|
text = Math.floor(n / 1000) + 'k';
|
2014-08-02 02:12:20 +02:00
|
|
|
|
} else {
|
2014-08-03 20:20:54 +02:00
|
|
|
|
text = 'E' + Math.floor(Math.log10(n));
|
2014-08-02 02:12:20 +02:00
|
|
|
|
}
|
2019-09-28 12:10:52 +02:00
|
|
|
|
ctx.font = 'bold ' + 9 * ratio + 'px "Arial", sans-serif';
|
2014-08-07 21:33:38 +02:00
|
|
|
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
|
2019-09-28 12:10:52 +02:00
|
|
|
|
ctx.fillRect(0, 7 * ratio, ctx.measureText(text).width, 9 * ratio);
|
2014-08-02 01:33:33 +02:00
|
|
|
|
ctx.fillStyle = '#F00';
|
2014-08-07 21:33:38 +02:00
|
|
|
|
ctx.fillText(text, 0, canvas.height - 1);
|
2014-08-02 01:33:33 +02:00
|
|
|
|
}
|
|
|
|
|
link.href = canvas.toDataURL('image/png');
|
2021-12-31 13:14:15 +01:00
|
|
|
|
// Check if data URI has generated a real favicon and if not, fallback to standard icon
|
|
|
|
|
if (link.href.length > 180) {
|
|
|
|
|
document.querySelector('link[rel~=icon]').remove();
|
|
|
|
|
document.head.appendChild(link);
|
|
|
|
|
}
|
2014-08-02 01:33:33 +02:00
|
|
|
|
};
|
|
|
|
|
img.src = '../favicon.ico';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 12:17:21 +02:00
|
|
|
|
function removeFirstLoadSpinner() {
|
|
|
|
|
const first_load = document.getElementById('first_load');
|
|
|
|
|
if (first_load) {
|
|
|
|
|
first_load.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-06 13:18:46 +02:00
|
|
|
|
function init_normal() {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const stream = document.getElementById('stream');
|
|
|
|
|
if (!stream) {
|
2016-08-06 13:18:46 +02:00
|
|
|
|
if (window.console) {
|
|
|
|
|
console.log('FreshRSS waiting for content…');
|
|
|
|
|
}
|
2018-12-25 16:09:48 +01:00
|
|
|
|
setTimeout(init_normal, 100);
|
2016-08-06 13:18:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
init_column_categories();
|
2019-02-13 15:06:28 +01:00
|
|
|
|
init_stream(stream);
|
2016-08-06 13:18:46 +02:00
|
|
|
|
init_shortcuts();
|
|
|
|
|
init_actualize();
|
|
|
|
|
faviconNbUnread();
|
2019-04-06 09:24:22 +02:00
|
|
|
|
|
|
|
|
|
window.onbeforeunload = function (e) {
|
2020-10-19 11:38:27 +02:00
|
|
|
|
const sidebar = document.getElementById('sidebar');
|
2021-10-21 11:44:03 +02:00
|
|
|
|
if (sidebar) { // Save sidebar scroll position
|
2020-10-19 11:38:27 +02:00
|
|
|
|
sessionStorage.setItem('FreshRSS_sidebar_scrollTop', sidebar.scrollTop);
|
|
|
|
|
}
|
2019-04-06 09:24:22 +02:00
|
|
|
|
if (mark_read_queue && mark_read_queue.length > 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-08-06 13:18:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 00:30:11 +02:00
|
|
|
|
function init_beforeDOM() {
|
2020-03-23 22:29:26 +01:00
|
|
|
|
document.scrollingElement.scrollTop = 0;
|
2016-08-06 13:18:46 +02:00
|
|
|
|
if (['normal', 'reader', 'global'].indexOf(context.current_view) >= 0) {
|
|
|
|
|
init_normal();
|
2016-08-02 00:30:11 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init_afterDOM() {
|
2020-05-21 12:17:21 +02:00
|
|
|
|
removeFirstLoadSpinner();
|
2016-08-02 00:30:11 +02:00
|
|
|
|
init_notifications();
|
2020-02-13 18:22:35 +01:00
|
|
|
|
init_popup();
|
2018-10-14 13:59:26 +02:00
|
|
|
|
init_confirm_action();
|
2019-02-13 15:06:28 +01:00
|
|
|
|
const stream = document.getElementById('stream');
|
|
|
|
|
if (stream) {
|
|
|
|
|
init_load_more(stream);
|
2014-01-12 20:26:26 +01:00
|
|
|
|
init_posts();
|
|
|
|
|
init_nav_entries();
|
2014-08-08 21:30:23 +02:00
|
|
|
|
init_notifs_html5();
|
2019-10-01 18:12:48 +02:00
|
|
|
|
setTimeout(faviconNbUnread, 1000);
|
2018-12-25 16:09:48 +01:00
|
|
|
|
setInterval(refreshUnreads, 120000);
|
2014-01-12 20:26:26 +01:00
|
|
|
|
}
|
2014-01-27 22:35:27 +01:00
|
|
|
|
|
2013-11-03 23:58:54 +01:00
|
|
|
|
if (window.console) {
|
2019-02-13 15:06:28 +01:00
|
|
|
|
console.log('FreshRSS main init done.');
|
2013-11-03 23:58:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:44:03 +02:00
|
|
|
|
init_beforeDOM(); // Can be called before DOM is fully loaded
|
2016-08-02 00:30:11 +02:00
|
|
|
|
|
2013-11-03 23:58:54 +01:00
|
|
|
|
if (document.readyState && document.readyState !== 'loading') {
|
2016-08-02 00:30:11 +02:00
|
|
|
|
init_afterDOM();
|
2019-02-13 15:06:28 +01:00
|
|
|
|
} else {
|
2020-05-21 12:17:21 +02:00
|
|
|
|
if (window.console) {
|
|
|
|
|
console.log('FreshRSS waiting for DOMContentLoaded…');
|
|
|
|
|
}
|
|
|
|
|
document.addEventListener('DOMContentLoaded', init_afterDOM, false);
|
Grosse optimisation JavaScript
* Fusion de endless_mode.js dans main.js car endless_mode.js est
toujours chargé et assez petit.
* Suppression des changements de style en JavaScript lors du chargement
(genre boucle de .hide(), ou d'ajout de classe ".stick") et
implémentation en PHP + CSS à la place.
* Chargement JavaScript asynchrone (defer + async) pour de meilleurs
performances.
* Utilisation préférable des événements globaux plutôt que des
événements pour chaque élément avec jQuery.on(events, selector) pour un
chargement plus rapide et moins de mémoire utilisée.
* Optimisation manuelle du JavaScript (sélecteurs CSS plus performants,
méthodes jQuery plus appropriées, etc.).
* Désactivation de init_img() qui était coûteux, lancé à un moment où
les images ne sont de toute manière pas encore chargées, et qui
n'apporte rien car il y a déjà un img {max-width:100%} en CSS.
* JavaScript en mode strict.
* Enfin, passage du code JavaScript dans JSLint et du coup nombreuses
corrections (syntaxe, variables, méthodes dépréciées...).
* Devrait permettre de fermer
https://github.com/marienfressinaud/FreshRSS/issues/121
* Au passage, quelques simplifications CSS pour de meilleures
performances.
2013-11-03 19:22:59 +01:00
|
|
|
|
}
|
2019-10-20 22:10:24 +02:00
|
|
|
|
// @license-end
|