summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-04-12 16:04:45 +0300
committerAndrew Dolgov <[email protected]>2021-04-12 16:04:45 +0300
commit3e2236896219804cdf4b9cfb79eb186f371feddc (patch)
tree51efd7ea6561ffde24193b17f9e1074bae909040 /js
parenteadaaebd588471b5df54123d29e115df3320177b (diff)
getPreviousFeed/getNextFeed: implement wrap around
Diffstat (limited to 'js')
-rwxr-xr-xjs/FeedTree.js102
1 files changed, 55 insertions, 47 deletions
diff --git a/js/FeedTree.js b/js/FeedTree.js
index 185135ec6..b81638c39 100755
--- a/js/FeedTree.js
+++ b/js/FeedTree.js
@@ -388,6 +388,24 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
getNextUnread: function(feed, is_cat) {
return this.getNextFeed(feed, is_cat, true);
},
+ _nextTreeItemFromIndex: function (start, unread_only) {
+ const items = this.model.store._arrayOfAllItems;
+
+ for (let i = start+1; i < items.length; i++) {
+ const id = String(items[i].id);
+ const box = this._itemNodesMap[id];
+ const unread = parseInt(items[i].unread);
+
+ if (box && (!unread_only || unread > 0)) {
+ const row = box[0].rowNode;
+ const cat = box[0].rowNode.parentNode.parentNode;
+
+ if (Element.visible(cat) && Element.visible(row)) {
+ return items[i];
+ }
+ }
+ }
+ },
getNextFeed: function (feed, is_cat, unread_only = false) {
let treeItem;
@@ -398,36 +416,40 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
}
const items = this.model.store._arrayOfAllItems;
- let item = false;
+ const start = items.indexOf(treeItem);
- for (let i = 0; i < items.length; i++) {
- if (items[i] == treeItem) {
+ if (start != -1) {
+ let item = this._nextTreeItemFromIndex(start, unread_only);
- for (let j = i+1; j < items.length; j++) {
- const id = String(items[j].id);
- const box = this._itemNodesMap[id];
- const unread = parseInt(items[j].unread);
+ // let's try again from the top
+ // 0 (instead of -1) to skip Special category
+ if (!item) {
+ item = this._nextTreeItemFromIndex(0, unread_only);
+ }
- if (box && (!unread_only || unread > 0)) {
- const row = box[0].rowNode;
- const cat = box[0].rowNode.parentNode.parentNode;
+ if (item)
+ return [this.model.store.getValue(item, 'bare_id'),
+ !this.model.store.getValue(item, 'id').match('FEED:')];
+ }
- if (Element.visible(cat) && Element.visible(row)) {
- item = items[j];
- break;
- }
- }
+ return [false, false];
+ },
+ _prevTreeItemFromIndex: function (start) {
+ const items = this.model.store._arrayOfAllItems;
+
+ for (let i = start-1; i > 0; i--) {
+ const id = String(items[i].id);
+ const box = this._itemNodesMap[id];
+
+ if (box) {
+ const row = box[0].rowNode;
+ const cat = box[0].rowNode.parentNode.parentNode;
+
+ if (Element.visible(cat) && Element.visible(row)) {
+ return items[i];
}
- break;
}
}
-
- if (item) {
- return [this.model.store.getValue(item, 'bare_id'),
- !this.model.store.getValue(item, 'id').match('FEED:')];
- } else {
- return [false, false];
- }
},
getPreviousFeed: function (feed, is_cat) {
let treeItem;
@@ -439,36 +461,22 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
}
const items = this.model.store._arrayOfAllItems;
- let item = false;
-
- for (let i = 0; i < items.length; i++) {
- if (items[i] == treeItem) {
+ const start = items.indexOf(treeItem);
- for (let j = i-1; j > 0; j--) {
- const id = String(items[j].id);
- const box = this._itemNodesMap[id];
+ if (start != -1) {
+ let item = this._prevTreeItemFromIndex(start);
- if (box) {
- const row = box[0].rowNode;
- const cat = box[0].rowNode.parentNode.parentNode;
-
- if (Element.visible(cat) && Element.visible(row)) {
- item = items[j];
- break;
- }
- }
- }
- break;
+ // wrap from the bottom
+ if (!item) {
+ item = this._prevTreeItemFromIndex(items.length);
}
- }
- if (item) {
- return [this.model.store.getValue(item, 'bare_id'),
- !this.model.store.getValue(item, 'id').match('FEED:')];
- } else {
- return [false, false];
+ if (item)
+ return [this.model.store.getValue(item, 'bare_id'),
+ !this.model.store.getValue(item, 'id').match('FEED:')];
}
+ return [false, false];
},
getFeedCategory: function(feed) {
try {