X-Git-Url: http://jaekl.net/gitweb/?p=quanweb.git;a=blobdiff_plain;f=js%2FBooksModel.js;h=984519d137409329027f20ca894beeeb18409ab0;hp=0c0b915769e0cfcd29501ccceef7740a31ec9eec;hb=32c817b6cf7484487c1160cec8a4b9e770b8404a;hpb=ea10c37dd0cf10799d4e2c3e265f5e0e108a8023 diff --git a/js/BooksModel.js b/js/BooksModel.js index 0c0b915..984519d 100644 --- a/js/BooksModel.js +++ b/js/BooksModel.js @@ -24,6 +24,35 @@ var BooksModel = (function() { // ============== // Public methods + my.adjustPos = function(setting) { + + var value = parseInt(setting); + + var prev = { + first: my.first, + last: my.last, + }; + + var maxFirst = Math.max(0, my.count - my.pageSize); + + if (value < 0) { + my.first = 0; + } else if (value > maxFirst) { + my.first = maxFirst; + } else { + my.first = value; + } + + my.last = my.first + my.pageSize - 1; + if (my.last >= my.count) { + my.last = my.count - 1; + } + + if (prev.first !== my.first || prev.last !== my.last) { + my.refreshData(); + } + }; + my.listen = function(subscriber) { listeners.push(subscriber); };