pageStack.js
725 Bytes
define(function() {
var stack = [];
return {
pop: function(pageid) {
if (!pageid) return stack.pop();
var pageids = this.getAllPrevPageIds();
stack.splice(pageids.lastIndexOf(pageid) + 1, stack.length);
},
push: function() {
return stack.push.apply(stack, arguments);
},
getPrevPage: function() {
return stack[stack.length - 2];
},
getAllPrevPages: function () {
return stack.slice(0, stack.length - 1);
},
getAllPrevPageIds: function() {
return this.getAllPrevPages().map(function (page) {
return page.id
});
}
};
});