// ==============
// 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);
};
}
fetch(url, {method:'GET', cache:'default'})
- .then(response => response.json())
- .then((jsonValue) => {
- console.log('JSON response for info: ', jsonValue);
+ .then(function(response) {return response.json();})
+ .then(function(jsonValue) {
my.cache = jsonValue;
notifyAll(); // inform all subscribers that the model has been updated
})
- .catch(err => {
+ .catch(function(err) {
var msg = 'Error fetching book details via URL: ' + url + ': ' + err;
console.log(msg, err.stack);
report(msg);