summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/AppBase.js4
-rw-r--r--js/Article.js10
-rwxr-xr-xjs/FeedTree.js211
-rw-r--r--js/Feeds.js16
-rwxr-xr-xjs/Headlines.js32
-rwxr-xr-xjs/common.js8
-rw-r--r--js/tt-rss.js12
-rw-r--r--js/utility.js44
8 files changed, 137 insertions, 200 deletions
diff --git a/js/AppBase.js b/js/AppBase.js
index 8a710d685..86cc44e8a 100644
--- a/js/AppBase.js
+++ b/js/AppBase.js
@@ -20,7 +20,7 @@ define(["dojo/_base/declare"], function (declare) {
console.log("night mode changed to", is_night);
if (link) {
- const css_override = is_night ? "themes/night.css" : "css/default.css";
+ const css_override = is_night ? "themes/night.css" : "themes/light.css";
link.setAttribute("href", css_override + "?" + Date.now());
}
},
@@ -367,7 +367,7 @@ define(["dojo/_base/declare"], function (declare) {
if (params.hasOwnProperty(k)) {
switch (k) {
case "label_base_index":
- _label_base_index = parseInt(params[k]);
+ LABEL_BASE_INDEX = parseInt(params[k]);
break;
case "cdm_auto_catchup":
if (params[k] == 1) {
diff --git a/js/Article.js b/js/Article.js
index 08b565695..50447c2a1 100644
--- a/js/Article.js
+++ b/js/Article.js
@@ -156,14 +156,14 @@ define(["dojo/_base/declare"], function (declare) {
comments_msg = hl.num_comments + " " + ngettext("comment", "comments", hl.num_comments)
}
- comments = `<a href="${hl.comments}">(${comments_msg})</a>`;
+ comments = `<a href="${escapeHtml(hl.comments)}">(${comments_msg})</a>`;
}
return comments;
},
formatOriginallyFrom: function(hl) {
return hl.orig_feed ? `<span>
- ${__('Originally from:')} <a target="_blank" rel="noopener noreferrer" href="${hl.orig_feed[1]}">${hl.orig_feed[0]}</a>
+ ${__('Originally from:')} <a target="_blank" rel="noopener noreferrer" href="${escapeHtml(hl.orig_feed[1])}">${hl.orig_feed[0]}</a>
</span>` : "";
},
unpack: function(row) {
@@ -194,10 +194,12 @@ define(["dojo/_base/declare"], function (declare) {
const comments = this.formatComments(hl);
const originally_from = this.formatOriginallyFrom(hl);
- const article = `<div class="post post-${hl.id}">
+ const article = `<div class="post post-${hl.id}" data-article-id="${hl.id}">
<div class="header">
<div class="row">
- <div class="title"><a target="_blank" rel="noopener noreferrer" title="${hl.title}" href="${hl.link}">${hl.title}</a></div>
+ <div class="title"><a target="_blank" rel="noopener noreferrer"
+ title="${escapeHtml(hl.title)}"
+ href="${escapeHtml(hl.link)}">${hl.title}</a></div>
<div class="date">${hl.updated_long}</div>
</div>
<div class="row">
diff --git a/js/FeedTree.js b/js/FeedTree.js
index 1dcbae3f9..85892b3d9 100755
--- a/js/FeedTree.js
+++ b/js/FeedTree.js
@@ -16,17 +16,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
if (iconName) {
if (iconName.indexOf("/") == -1) {
- iconNode = dojo.doc.createElement("i");
- iconNode.className = "material-icons icon icon-" + iconName;
- iconNode.innerHTML = iconName;
+ iconNode = dojo.create("i", { className: "material-icons icon icon-" + iconName, innerHTML: iconName });
} else {
- iconNode = dojo.doc.createElement('img');
+ iconNode = dojo.create('img', { className: 'icon' });
if (args.item.icon && args.item.icon[0]) {
iconNode.src = args.item.icon[0];
} else {
iconNode.src = 'images/blank_icon.gif';
}
- iconNode.className = 'icon';
}
}
@@ -36,13 +33,12 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
const id = args.item.id[0];
const bare_id = parseInt(id.substr(id.indexOf(':')+1));
- if (bare_id < _label_base_index) {
- const label = dojo.doc.createElement('i');
+ if (bare_id < LABEL_BASE_INDEX) {
+ const label = dojo.create('i', { className: "material-icons icon icon-label", innerHTML: "label" });
+
//const fg_color = args.item.fg_color[0];
const bg_color = args.item.bg_color[0];
- label.className = "material-icons icon icon-label";
- label.innerHTML = "label";
label.setStyle({
color: bg_color,
});
@@ -73,12 +69,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + this.getParent().row_id +
"&csrf_token=" + App.getInitParam("csrf_token"));
}}));
-
- /* menu.addChild(new dijit.MenuItem({
- label: __("Update feed"),
- onClick: function() {
- heduleFeedUpdate(this.getParent().row_id, false);
- }})); */
}
menu.bindDomNode(tnode.domNode);
@@ -106,11 +96,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
if (id.match("CAT:")) {
- loading = dojo.doc.createElement('img');
- loading.className = 'loadingNode';
- loading.src = 'images/blank_icon.gif';
- domConstruct.place(loading, tnode.labelNode, 'after');
- tnode.loadingNode = loading;
+ tnode.loadingNode = dojo.create('img', { className: 'loadingNode', src: 'images/blank_icon.gif'});
+ domConstruct.place(tnode.loadingNode, tnode.labelNode, 'after');
}
if (id.match("CAT:") && bare_id == -1) {
@@ -127,28 +114,19 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
tnode._menu = menu;
}
- ctr = dojo.doc.createElement('span');
- ctr.className = 'counterNode';
- ctr.innerHTML = args.item.unread > 0 ? args.item.unread : args.item.auxcounter;
-
- //args.item.unread > 0 ? ctr.addClassName("unread") : ctr.removeClassName("unread");
-
- args.item.unread > 0 || args.item.auxcounter > 0 ? Element.show(ctr) : Element.hide(ctr);
+ tnode.markedCounterNode = dojo.create('span', { className: 'counterNode marked', innerHTML: args.item.markedcounter });
+ domConstruct.place(tnode.markedCounterNode, tnode.rowNode, 'first');
- args.item.unread <= 0 && args.item.auxcounter > 0 ? ctr.addClassName("aux") : ctr.removeClassName("aux");
+ tnode.auxCounterNode = dojo.create('span', { className: 'counterNode aux', innerHTML: args.item.auxcounter });
+ domConstruct.place(tnode.auxCounterNode, tnode.rowNode, 'first');
- domConstruct.place(ctr, tnode.rowNode, 'first');
- tnode.counterNode = ctr;
+ tnode.unreadCounterNode = dojo.create('span', { className: 'counterNode unread', innerHTML: args.item.unread });
+ domConstruct.place(tnode.unreadCounterNode, tnode.rowNode, 'first');
- //tnode.labelNode.innerHTML = args.label;
return tnode;
},
postCreate: function() {
this.connect(this.model, "onChange", "updateCounter");
- this.connect(this, "_expandNode", function() {
- this.hideRead(App.getInitParam("hide_read_feeds"), App.getInitParam("hide_read_shows_special"));
- });
-
this.inherited(arguments);
},
updateCounter: function (item) {
@@ -156,26 +134,15 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
//console.log("updateCounter: " + item.id[0] + " " + item.unread + " " + tree);
- let node = tree._itemNodesMap[item.id];
-
- if (node) {
- node = node[0];
+ let treeNode = tree._itemNodesMap[item.id];
- if (node.counterNode) {
- ctr = node.counterNode;
- ctr.innerHTML = item.unread > 0 ? item.unread : item.auxcounter;
- item.unread > 0 || item.auxcounter > 0 ?
- item.unread > 0 ?
- Effect.Appear(ctr, {duration : 0.3,
- queue: { position: 'end', scope: 'CAPPEAR-' + item.id, limit: 1 }}) :
- Element.show(ctr) :
- Element.hide(ctr);
-
- item.unread <= 0 && item.auxcounter > 0 ? ctr.addClassName("aux") : ctr.removeClassName("aux");
+ if (treeNode) {
+ treeNode = treeNode[0];
- }
+ treeNode.unreadCounterNode.innerHTML = item.unread;
+ treeNode.auxCounterNode.innerHTML = item.auxcounter;
+ treeNode.markedCounterNode.innerHTML = item.markedcounter;
}
-
},
getTooltip: function (item) {
return [item.updated, item.error].filter(x => x && x != "").join(" - ");
@@ -187,11 +154,18 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
return (item.unread <= 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread";
},
getRowClass: function (item, opened) {
- let rc = (!item.error || item.error == '') ? "dijitTreeRow" :
- "dijitTreeRow Error";
+ let rc = "dijitTreeRow";
+
+ const is_cat = String(item.id).indexOf('CAT:') != -1;
+ if (!is_cat && item.error != '') rc += " Error";
if (item.unread > 0) rc += " Unread";
+ if (item.auxcounter > 0) rc += " Has_Aux";
+ if (item.markedcounter > 0) rc += " Has_Marked";
if (item.updates_disabled > 0) rc += " UpdatesDisabled";
+ if (item.bare_id >= LABEL_BASE_INDEX && item.bare_id < 0 && !is_cat || item.bare_id == 0 && !is_cat) rc += " Special";
+ if (item.bare_id == -1 && is_cat) rc += " AlwaysVisible";
+ if (item.bare_id < LABEL_BASE_INDEX) rc += " Label";
return rc;
},
@@ -205,14 +179,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
name = name.replace(/&lt;/g, "<");
name = name.replace(/&gt;/g, ">");
- /* var label;
-
- if (item.unread > 0) {
- label = name + " (" + item.unread + ")";
- } else {
- label = name;
- } */
-
return name;
},
expandParentNodes: function(feed, is_cat, list) {
@@ -268,6 +234,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
selectFeed: function(feed, is_cat) {
this.findNodeParentsAndExpandThem(feed, is_cat, false, false);
+ let treeNode;
+
if (is_cat)
treeNode = this._itemNodesMap['CAT:' + feed];
else
@@ -299,6 +267,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
},
setFeedIcon: function(feed, is_cat, src) {
+ let treeNode;
+
if (is_cat)
treeNode = this._itemNodesMap['CAT:' + feed];
else
@@ -306,15 +276,15 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
if (treeNode) {
treeNode = treeNode[0];
- const icon = dojo.doc.createElement('img');
- icon.src = src;
- icon.className = 'icon';
+ const icon = dojo.create('img', { src: src, className: 'icon' });
domConstruct.place(icon, treeNode.iconNode, 'only');
return true;
}
return false;
},
setFeedExpandoIcon: function(feed, is_cat, src) {
+ let treeNode;
+
if (is_cat)
treeNode = this._itemNodesMap['CAT:' + feed];
else
@@ -326,9 +296,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
treeNode.loadingNode.src = src;
return true;
} else {
- const icon = dojo.doc.createElement('img');
- icon.src = src;
- icon.className = 'loadingExpando';
+ const icon = dojo.create('img', { src: src, className: 'loadingExpando' });
domConstruct.place(icon, treeNode.expandoNode, 'only');
return true;
}
@@ -339,77 +307,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
hasCats: function() {
return this.model.hasCats();
},
- hideReadCat: function (cat, hide, show_special) {
- if (this.hasCats()) {
- const tree = this;
-
- if (cat && cat.items) {
- let cat_unread = tree.hideReadFeeds(cat.items, hide, show_special);
-
- const id = String(cat.id);
- const node = tree._itemNodesMap[id];
- const bare_id = parseInt(id.substr(id.indexOf(":")+1));
-
- if (node) {
- const check_unread = tree.model.getFeedUnread(bare_id, true);
-
- if (hide && cat_unread <= 0 && check_unread <= 0 && (id != "CAT:-1" || !show_special)) {
- Effect.Fade(node[0].rowNode, {duration : 0.3,
- queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
- } else {
- Element.show(node[0].rowNode);
- ++cat_unread;
- }
- }
- }
- }
- },
- hideRead: function (hide, show_special) {
- if (this.hasCats()) {
-
- const tree = this;
- const cats = this.model.store._arrayOfTopLevelItems;
-
- cats.each(function(cat) {
- tree.hideReadCat(cat, hide, show_special);
- });
-
- } else {
- this.hideReadFeeds(this.model.store._arrayOfTopLevelItems, hide,
- show_special);
- }
- },
- hideReadFeeds: function (items, hide, show_special) {
- const tree = this;
- let cat_unread = 0;
-
- items.each(function(feed) {
- const id = String(feed.id);
-
- // it's a subcategory
- if (feed.items) {
- tree.hideReadCat(feed, hide, show_special);
- } else { // it's a feed
- const bare_id = parseInt(feed.bare_id);
-
- const unread = feed.unread[0];
- const has_error = feed.error[0] != '';
- const node = tree._itemNodesMap[id];
-
- if (node) {
- if (hide && unread <= 0 && !has_error && (bare_id > 0 || bare_id < _label_base_index || !show_special)) {
- Effect.Fade(node[0].rowNode, {duration : 0.3,
- queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
- } else {
- Element.show(node[0].rowNode);
- ++cat_unread;
- }
- }
- }
- });
-
- return cat_unread;
- },
collapseCat: function(id) {
if (!this.model.hasCats()) return;
@@ -426,39 +323,9 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
},
- getVisibleUnreadFeeds: function() {
- const items = this.model.store._arrayOfAllItems;
- const rv = [];
-
- for (let i = 0; i < items.length; i++) {
- const id = String(items[i].id);
- const box = this._itemNodesMap[id];
-
- if (box) {
- const row = box[0].rowNode;
- let cat = false;
-
- try {
- cat = box[0].rowNode.parentNode.parentNode;
- } catch (e) { }
-
- if (row) {
- if (Element.visible(row) && (!cat || Element.visible(cat))) {
- const feed_id = String(items[i].bare_id);
- const is_cat = !id.match('FEED:');
- const unread = this.model.getFeedUnread(feed_id, is_cat);
-
- if (unread > 0)
- rv.push([feed_id, is_cat]);
-
- }
- }
- }
- }
-
- return rv;
- },
getNextFeed: function (feed, is_cat) {
+ let treeItem;
+
if (is_cat) {
treeItem = this.model.store._itemsByIdentity['CAT:' + feed];
} else {
@@ -497,6 +364,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
},
getPreviousFeed: function (feed, is_cat) {
+ let treeItem;
+
if (is_cat) {
treeItem = this.model.store._itemsByIdentity['CAT:' + feed];
} else {
diff --git a/js/Feeds.js b/js/Feeds.js
index 42ab6fe7e..7fa376984 100644
--- a/js/Feeds.js
+++ b/js/Feeds.js
@@ -58,7 +58,6 @@ define(["dojo/_base/declare"], function (declare) {
const error = elems[l].error;
const has_img = elems[l].has_img;
const updated = elems[l].updated;
- const auxctr = parseInt(elems[l].auxcounter);
if (id == "global-unread") {
App.global_unread = ctr;
@@ -76,7 +75,8 @@ define(["dojo/_base/declare"], function (declare) {
}*/
this.setUnread(id, (kind == "cat"), ctr);
- this.setValue(id, (kind == "cat"), 'auxcounter', auxctr);
+ this.setValue(id, (kind == "cat"), 'auxcounter', parseInt(elems[l].auxcounter));
+ this.setValue(id, (kind == "cat"), 'markedcounter', parseInt(elems[l].markedcounter));
if (kind != "cat") {
this.setValue(id, false, 'error', error);
@@ -221,6 +221,9 @@ define(["dojo/_base/declare"], function (declare) {
if (App.getInitParam("is_default_pw")) {
console.warn("user password is at default value");
+ if (dijit.byId("defaultPasswordDlg"))
+ dijit.byId("defaultPasswordDlg").destroyRecursive();
+
const dialog = new dijit.Dialog({
title: __("Your password is at default value"),
href: "backend.php?op=dlg&method=defaultpasswordwarning",
@@ -285,11 +288,14 @@ define(["dojo/_base/declare"], function (declare) {
App.setInitParam("hide_read_feeds", hide);
});
},
- hideOrShowFeeds: function(hide) {
- const tree = dijit.byId("feedTree");
+ hideOrShowFeeds: function (hide) {
+ /*const tree = dijit.byId("feedTree");
if (tree)
- return tree.hideRead(hide, App.getInitParam("hide_read_shows_special"));
+ return tree.hideRead(hide, App.getInitParam("hide_read_shows_special"));*/
+
+ $$("body")[0].setAttribute("hide-read-feeds", !!hide);
+ $$("body")[0].setAttribute("hide-read-shows-special", !!App.getInitParam("hide_read_shows_special"));
},
open: function(params) {
const feed = params.feed;
diff --git a/js/Headlines.js b/js/Headlines.js
index 5b7aac0b0..540c400d3 100755
--- a/js/Headlines.js
+++ b/js/Headlines.js
@@ -444,9 +444,15 @@ define(["dojo/_base/declare"], function (declare) {
const comments = Article.formatComments(hl);
const originally_from = Article.formatOriginallyFrom(hl);
- row = `<div class="cdm ${row_class} ${Article.getScoreClass(hl.score)}" id="RROW-${hl.id}" data-article-id="${hl.id}" data-orig-feed-id="${hl.feed_id}"
- data-content="${escapeHtml(hl.content)}" data-score="${hl.score}" data-article-title="${hl.title}"
- onmouseover="Article.mouseIn(${hl.id})" onmouseout="Article.mouseOut(${hl.id})">
+ row = `<div class="cdm ${row_class} ${Article.getScoreClass(hl.score)}"
+ id="RROW-${hl.id}"
+ data-article-id="${hl.id}"
+ data-orig-feed-id="${hl.feed_id}"
+ data-content="${escapeHtml(hl.content)}"
+ data-score="${hl.score}"
+ data-article-title="${escapeHtml(hl.title)}"
+ onmouseover="Article.mouseIn(${hl.id})"
+ onmouseout="Article.mouseOut(${hl.id})">
<div class="header">
<div class="left">
@@ -456,7 +462,7 @@ define(["dojo/_base/declare"], function (declare) {
</div>
<span onclick="return Headlines.click(event, ${hl.id});" data-article-id="${hl.id}" class="titleWrap hlMenuAttach">
- <a class="title" title="${hl.title}" target="_blank" rel="noopener noreferrer" href="${hl.link}">
+ <a class="title" title="${escapeHtml(hl.title)}" target="_blank" rel="noopener noreferrer" href="${escapeHtml(hl.link)}">
${hl.title}</a>
<span class="author">${hl.author}</span>
${hl.labels}
@@ -473,7 +479,7 @@ define(["dojo/_base/declare"], function (declare) {
<div class="right">
<i class="material-icons icon-score" title="${hl.score}" onclick="Article.setScore(${hl.id}, this)">${Article.getScorePic(hl.score)}</i>
- <span style="cursor : pointer" title="${hl.feed_title}" onclick="Feeds.open({feed:${hl.feed_id}})">
+ <span style="cursor : pointer" title="${escapeHtml(hl.feed_title)}" onclick="Feeds.open({feed:${hl.feed_id}})">
${hl.feed_icon}</span>
</div>
@@ -508,8 +514,14 @@ define(["dojo/_base/declare"], function (declare) {
} else {
- row = `<div class="hl ${row_class} ${Article.getScoreClass(hl.score)}" data-orig-feed-id="${hl.feed_id}" data-article-id="${hl.id}" id="RROW-${hl.id}"
- data-score="${hl.score}" onmouseover="Article.mouseIn(${hl.id})" onmouseout="Article.mouseOut(${hl.id})">
+ row = `<div class="hl ${row_class} ${Article.getScoreClass(hl.score)}"
+ id="RROW-${hl.id}"
+ data-orig-feed-id="${hl.feed_id}"
+ data-article-id="${hl.id}"
+ data-score="${hl.score}"
+ data-article-title="${escapeHtml(hl.title)}"
+ onmouseover="Article.mouseIn(${hl.id})"
+ onmouseout="Article.mouseOut(${hl.id})">
<div class="left">
<input dojoType="dijit.form.CheckBox" type="checkbox" onclick="Headlines.onRowChecked(this)" class='rchk'>
<i class="marked-pic marked-${hl.id} material-icons" onclick="Headlines.toggleMark(${hl.id})">star</i>
@@ -517,7 +529,7 @@ define(["dojo/_base/declare"], function (declare) {
</div>
<div onclick="return Headlines.click(event, ${hl.id})" class="title">
<span data-article-id="${hl.id}" class="hl-content hlMenuAttach">
- <a class="title" href="${hl.link}">${hl.title} <span class="preview">${hl.content_preview}</span></a>
+ <a class="title" href="${escapeHtml(hl.link)}">${hl.title} <span class="preview">${hl.content_preview}</span></a>
<span class="author">${hl.author}</span>
${hl.labels}
</span>
@@ -530,7 +542,7 @@ define(["dojo/_base/declare"], function (declare) {
</div>
<div class="right">
<i class="material-icons icon-score" title="${hl.score}" onclick="Article.setScore(${hl.id}, this)">${Article.getScorePic(hl.score)}</i>
- <span onclick="Feeds.open({feed:${hl.feed_id}})" style="cursor : pointer" title="${hl.feed_title}">${hl.feed_icon}</span>
+ <span onclick="Feeds.open({feed:${hl.feed_id}})" style="cursor : pointer" title="${escapeHtml(hl.feed_title)}">${hl.feed_icon}</span>
</div>
</div>
`;
@@ -895,7 +907,7 @@ define(["dojo/_base/declare"], function (declare) {
if (!noscroll) {
Article.scroll(-ctr.offsetHeight / 2, event);
} else {
- if (row && row.offsetTop < ctr.scrollTop) {
+ if (row && Math.round(row.offsetTop) < Math.round(ctr.scrollTop)) {
Article.cdmScrollToId(Article.getActive(), noscroll, event);
} else if (prev_id) {
Article.setActive(prev_id);
diff --git a/js/common.js b/js/common.js
index e93087eb4..69b528a1c 100755
--- a/js/common.js
+++ b/js/common.js
@@ -1,7 +1,7 @@
'use strict'
/* global dijit, __ */
-let _label_base_index = -1024;
+let LABEL_BASE_INDEX = -1024; /* not const because it's assigned at least once (by backend) */
let loading_progress = 0;
/* error reporting shim */
@@ -252,12 +252,12 @@ function displayIfChecked(checkbox, elemId) {
// noinspection JSUnusedGlobalSymbols
function label_to_feed_id(label) {
- return _label_base_index - 1 - Math.abs(label);
+ return LABEL_BASE_INDEX - 1 - Math.abs(label);
}
// noinspection JSUnusedGlobalSymbols
function feed_to_label_id(feed) {
- return _label_base_index - 1 + Math.abs(feed);
+ return LABEL_BASE_INDEX - 1 + Math.abs(feed);
}
// http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
@@ -313,4 +313,4 @@ function escapeHtml(text) {
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
-} \ No newline at end of file
+}
diff --git a/js/tt-rss.js b/js/tt-rss.js
index 84e42bf85..d45dd5748 100644
--- a/js/tt-rss.js
+++ b/js/tt-rss.js
@@ -197,6 +197,10 @@ require(["dojo/_base/kernel",
document.title = tmp;
},
onViewModeChanged: function() {
+ const view_mode = document.forms["toolbar-main"].view_mode.value;
+
+ $$("body")[0].setAttribute("view-mode", view_mode);
+
return Feeds.reloadCurrent('');
},
isCombinedMode: function() {
@@ -472,12 +476,12 @@ require(["dojo/_base/kernel",
this.hotkey_actions["collapse_sidebar"] = function () {
Feeds.toggle();
};
- this.hotkey_actions["toggle_embed_original"] = function () {
- if (typeof embedOriginalArticle != "undefined") {
+ this.hotkey_actions["toggle_full_text"] = function () {
+ if (typeof Plugins.Af_Readability != "undefined") {
if (Article.getActive())
- embedOriginalArticle(Article.getActive());
+ Plugins.Af_Readability.embed(Article.getActive());
} else {
- alert(__("Please enable embed_original plugin first."));
+ alert(__("Please enable af_readability first."));
}
};
this.hotkey_actions["toggle_widescreen"] = function () {
diff --git a/js/utility.js b/js/utility.js
new file mode 100644
index 000000000..2380f9823
--- /dev/null
+++ b/js/utility.js
@@ -0,0 +1,44 @@
+/* TODO: this should probably be something like night_mode.js since it does nothing specific to utility scripts */2
+
+Event.observe(window, "load", function() {
+ const UtilityJS = {
+ apply_night_mode: function (is_night, link) {
+ console.log("night mode changed to", is_night);
+
+ if (link) {
+ const css_override = is_night ? "themes/night.css" : "themes/light.css";
+
+ link.setAttribute("href", css_override + "?" + Date.now());
+ }
+ },
+ setup_night_mode: function() {
+ const mql = window.matchMedia('(prefers-color-scheme: dark)');
+
+ const link = new Element("link", {
+ rel: "stylesheet",
+ id: "theme_auto_css"
+ });
+
+ link.onload = function() {
+ document.querySelector("body").removeClassName("css_loading");
+
+ if (typeof UtilityApp != "undefined")
+ UtilityApp.init();
+ };
+
+ try {
+ mql.addEventListener("change", () => {
+ UtilityJS.apply_night_mode(mql.matches, link);
+ });
+ } catch (e) {
+ console.warn("exception while trying to set MQL event listener");
+ }
+
+ document.querySelector("head").appendChild(link);
+
+ UtilityJS.apply_night_mode(mql.matches, link);
+ }
+ };
+
+ UtilityJS.setup_night_mode();
+});