Should we have .next() and .previous() skip an item if it's filtered?
Currently they blindly this.index(this.index() + 1);
If so, something like this could work:
/**
* Convenience method to navigate to next item
*
* @param {Number} _index -- an optional index. Used to recursively find unflitered item
*/
next: function(_index) {
var currentIndex = _index || this.index();
var nextItem;
if (typeof currentIndex === 'number') {
nextItem = this.getItemByIndex(currentIndex + 1);
// valid index and item
if (nextItem) {
// proceed if not filtered. if filtered try the one after that.
if (!nextItem.filtered) {
this.index(currentIndex + 1);
} else {
this.next(currentIndex + 1);
}
}
}
},
/**
* Convenience method to navigate to previous item
*
* @param {Number} _index -- an optional index. Used to recursively find unflitered item
*/
previous: function(_index) {
var currentIndex = _index || this.index();
var previousItem;
if (typeof currentIndex === 'number') {
previousItem = this.getItemByIndex(currentIndex - 1);
// valid index and item
if (previousItem) {
// proceed if not filtered. if filtered try the one before that.
if (!previousItem.filtered) {
this.index(currentIndex - 1);
} else {
this.previous(currentIndex - 1);
}
}
}
}
Should we have .next() and .previous() skip an item if it's filtered?
Currently they blindly
this.index(this.index() + 1);
If so, something like this could work: