getPreviousFeed/getNextFeed: implement wrap around
This commit is contained in:
parent
eadaaebd58
commit
3e22368962
|
@ -388,6 +388,24 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
getNextUnread: function(feed, is_cat) {
|
getNextUnread: function(feed, is_cat) {
|
||||||
return this.getNextFeed(feed, is_cat, true);
|
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) {
|
getNextFeed: function (feed, is_cat, unread_only = false) {
|
||||||
let treeItem;
|
let treeItem;
|
||||||
|
|
||||||
|
@ -398,36 +416,40 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = this.model.store._arrayOfAllItems;
|
const items = this.model.store._arrayOfAllItems;
|
||||||
let item = false;
|
const start = items.indexOf(treeItem);
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
if (start != -1) {
|
||||||
if (items[i] == treeItem) {
|
let item = this._nextTreeItemFromIndex(start, unread_only);
|
||||||
|
|
||||||
for (let j = i+1; j < items.length; j++) {
|
// let's try again from the top
|
||||||
const id = String(items[j].id);
|
// 0 (instead of -1) to skip Special category
|
||||||
|
if (!item) {
|
||||||
|
item = this._nextTreeItemFromIndex(0, unread_only);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item)
|
||||||
|
return [this.model.store.getValue(item, 'bare_id'),
|
||||||
|
!this.model.store.getValue(item, 'id').match('FEED:')];
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
const box = this._itemNodesMap[id];
|
||||||
const unread = parseInt(items[j].unread);
|
|
||||||
|
|
||||||
if (box && (!unread_only || unread > 0)) {
|
if (box) {
|
||||||
const row = box[0].rowNode;
|
const row = box[0].rowNode;
|
||||||
const cat = box[0].rowNode.parentNode.parentNode;
|
const cat = box[0].rowNode.parentNode.parentNode;
|
||||||
|
|
||||||
if (Element.visible(cat) && Element.visible(row)) {
|
if (Element.visible(cat) && Element.visible(row)) {
|
||||||
item = items[j];
|
return items[i];
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) {
|
getPreviousFeed: function (feed, is_cat) {
|
||||||
let treeItem;
|
let treeItem;
|
||||||
|
@ -439,36 +461,22 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = this.model.store._arrayOfAllItems;
|
const items = this.model.store._arrayOfAllItems;
|
||||||
let item = false;
|
const start = items.indexOf(treeItem);
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
if (start != -1) {
|
||||||
if (items[i] == treeItem) {
|
let item = this._prevTreeItemFromIndex(start);
|
||||||
|
|
||||||
for (let j = i-1; j > 0; j--) {
|
// wrap from the bottom
|
||||||
const id = String(items[j].id);
|
if (!item) {
|
||||||
const box = this._itemNodesMap[id];
|
item = this._prevTreeItemFromIndex(items.length);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item) {
|
if (item)
|
||||||
return [this.model.store.getValue(item, 'bare_id'),
|
return [this.model.store.getValue(item, 'bare_id'),
|
||||||
!this.model.store.getValue(item, 'id').match('FEED:')];
|
!this.model.store.getValue(item, 'id').match('FEED:')];
|
||||||
} else {
|
|
||||||
return [false, false];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [false, false];
|
||||||
},
|
},
|
||||||
getFeedCategory: function(feed) {
|
getFeedCategory: function(feed) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue