aboutsummaryrefslogtreecommitdiff
path: root/p/scripts
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-08-02 00:52:31 +0200
committerGravatar GitHub <noreply@github.com> 2016-08-02 00:52:31 +0200
commit4a516aef583f4292293026ebc1d1a3984b75b4e8 (patch)
treeb7377129b7b2b8e3ff7ede2e6259fba326adc9ab /p/scripts
parentfde42d7af4cd6a1be433924eaddfa001fcd67cc6 (diff)
parent8ffb02e4d12b05bd142216dec75574f5a6bae64e (diff)
Merge pull request #1191 from Alkarex/JS-optimisation
Fix bug articles not marked as read +JS optimisation
Diffstat (limited to 'p/scripts')
-rw-r--r--p/scripts/main.js82
1 files changed, 47 insertions, 35 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index f1b82900e..01c8c9cf5 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -113,7 +113,7 @@ function incUnreadsFeed(article, feed_id, nb) {
return isCurrentView;
}
-var pending_feeds = [];
+var pending_entries = {};
function mark_read(active, only_not_read) {
if (active.length === 0 ||
(only_not_read === true && !active.hasClass("not_read"))) {
@@ -125,15 +125,10 @@ function mark_read(active, only_not_read) {
return false;
}
- var feed_url = active.find(".website>a").attr("href"),
- feed_id = feed_url.substr(feed_url.lastIndexOf('f_')),
- index_pending = pending_feeds.indexOf(feed_id);
-
- if (index_pending !== -1) {
+ if (pending_entries[active.attr('id')]) {
return false;
}
-
- pending_feeds.push(feed_id);
+ pending_entries[active.attr('id')] = true;
$.ajax({
type: 'POST',
@@ -151,13 +146,16 @@ function mark_read(active, only_not_read) {
}
$r.find('.icon').replaceWith(data.icon);
+ var feed_url = active.find(".website>a").attr("href"),
+ feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
+
incUnreadsFeed(active, feed_id, inc);
faviconNbUnread();
- pending_feeds.splice(index_pending, 1);
+ delete pending_entries[active.attr('id')];
}).fail(function (data) {
openNotification(i18n.notif_request_failed, 'bad');
- pending_feeds.splice(index_pending, 1);
+ delete pending_entries[active.attr('id')];
});
}
@@ -171,15 +169,10 @@ function mark_favorite(active) {
return false;
}
- var feed_url = active.find(".website>a").attr("href"),
- feed_id = feed_url.substr(feed_url.lastIndexOf('f_')),
- index_pending = pending_feeds.indexOf(feed_id);
-
- if (index_pending !== -1) {
+ if (pending_entries[active.attr('id')]) {
return false;
}
-
- pending_feeds.push(feed_id);
+ pending_entries[active.attr('id')] = true;
$.ajax({
type: 'POST',
@@ -212,10 +205,10 @@ function mark_favorite(active) {
}
}
- pending_feeds.splice(index_pending, 1);
+ delete pending_entries[active.attr('id')];
}).fail(function (data) {
openNotification(i18n.notif_request_failed, 'bad');
- pending_feeds.splice(index_pending, 1);
+ delete pending_entries[active.attr('id')];
});
}
@@ -905,7 +898,7 @@ function notifs_html5_show(nb) {
notification.onclick = function() {
window.location.reload();
- }
+ };
if (context['html5_notif_timeout'] !== 0) {
setTimeout(function() {
@@ -1298,27 +1291,46 @@ function parseJsonVars() {
window.icons = json.icons;
}
-function init_all() {
+function init_beforeDOM() {
if (!window.$) {
if (window.console) {
- console.log('FreshRSS waiting for JS…');
+ console.log('FreshRSS waiting for jQuery…');
}
- window.setTimeout(init_all, 50);
+ window.setTimeout(init_beforeDOM, 50);
return;
}
- parseJsonVars();
- init_notifications();
init_confirm_action();
+ if (['normal', 'reader', 'global'].indexOf(context['current_view']) >= 0) {
+ $stream = $('#stream');
+ if ($stream.length < 1) {
+ if (window.console) {
+ console.log('FreshRSS waiting for content…');
+ }
+ window.setTimeout(init_beforeDOM, 50);
+ return;
+ }
+ init_column_categories();
+ init_stream($stream);
+ init_shortcuts();
+ init_actualize();
+ faviconNbUnread();
+ }
+}
+
+function init_afterDOM() {
+ if (!window.$) {
+ if (window.console) {
+ console.log('FreshRSS waiting again for jQuery…');
+ }
+ window.setTimeout(init_afterDOM, 50);
+ return;
+ }
+ init_notifications();
$stream = $('#stream');
if ($stream.length > 0) {
- init_actualize();
- init_column_categories();
init_load_more($stream);
init_posts();
- init_stream($stream);
init_nav_entries();
- init_shortcuts();
- faviconNbUnread();
init_print_action();
init_notifs_html5();
window.setInterval(refreshUnreads, 120000);
@@ -1339,16 +1351,16 @@ function init_all() {
}
}
+parseJsonVars();
+init_beforeDOM(); //Can be called before DOM is fully loaded
+
if (document.readyState && document.readyState !== 'loading') {
- if (window.console) {
- console.log('FreshRSS immediate init…');
- }
- init_all();
+ init_afterDOM();
} else if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
if (window.console) {
console.log('FreshRSS waiting for DOMContentLoaded…');
}
- init_all();
+ init_afterDOM();
}, false);
}