lib/javascripts/pagy.js in pagy-3.0.0 vs lib/javascripts/pagy.js in pagy-3.1.0
- old
+ new
@@ -9,16 +9,16 @@
var args = JSON.parse(jsonTags[i].innerHTML);
Pagy[args.shift()].apply(null, args);
}
};
-Pagy.nav = function(id, marker, tags, sequels){
+Pagy.nav = function(id, tags, sequels){
var pagyEl = document.getElementById(id),
container = pagyEl.parentElement,
lastWidth = undefined,
timeoutId = 0,
- marker_re = new RegExp(marker, 'g'),
+ markRE = new RegExp('--pagy.page--', 'g'),
widths = [];
for (var width in sequels) { widths.push(parseInt(width)) } // fine with sequels structure
widths.sort(function(a, b){return b-a});
var render = function(){
@@ -31,13 +31,13 @@
while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) }
var html = tags.before,
series = sequels[width];
for (i = 0, len = series.length; i < len; i++) {
var item = series[i];
- if (typeof(item) === 'number') { html += tags.link.replace(marker_re, item) }
+ if (typeof(item) === 'number') { html += tags.link.replace(markRE, item) }
else if (item === 'gap') { html += tags.gap }
- else if (typeof(item) === 'string') { html += tags.active.replace(marker_re, item) }
+ else if (typeof(item) === 'string') { html += tags.active.replace(markRE, item) }
}
html += tags.after;
pagyEl.insertAdjacentHTML('beforeend', html);
lastWidth = width;
}
@@ -52,40 +52,40 @@
Pagy.windowListeners[id] = rendering;
}
render();
};
-Pagy.combo_nav = function(id, marker, page, trim){
+Pagy.combo_nav = function(id, page, links){
var pagyEl = document.getElementById(id),
input = pagyEl.getElementsByTagName('input')[0],
- link = pagyEl.getElementsByTagName('a')[0],
- linkP1 = pagyEl.getElementsByTagName('a')[1],
go = function(){
if (page !== input.value) {
- if (trim === true && input.value === '1') { linkP1.click() }
- else {
- var href = link.getAttribute('href').replace(marker, input.value);
- link.setAttribute('href', href);
- link.click();
+ if (links.hasOwnProperty('trimmed') && input.value === '1') {
+ pagyEl.insertAdjacentHTML('afterbegin', links.trimmed);
+ } else {
+ pagyEl.insertAdjacentHTML('afterbegin', links.standard.replace('--pagy.page--', input.value));
}
+ pagyEl.getElementsByTagName('a')[0].click();
}
};
Pagy.addInputEventListeners(input, go);
};
-Pagy.items_selector = function(id, marker, from){
+Pagy.items_selector = function(id, from, links){
var pagyEl = document.getElementById(id),
input = pagyEl.getElementsByTagName('input')[0],
current = input.value,
- link = pagyEl.getElementsByTagName('a')[0],
go = function(){
var items = input.value;
if (current !== items) {
var page = Math.max(Math.ceil(from / items),1);
- var href = link.getAttribute('href').replace(marker+'-page-', page).replace(marker+'-items-', items);
- link.setAttribute('href', href);
- link.click();
+ if (links.hasOwnProperty('trimmed') && page === 1) {
+ pagyEl.insertAdjacentHTML('afterbegin', links.trimmed.replace('--pagy.items--', items));
+ } else {
+ pagyEl.insertAdjacentHTML('afterbegin', links.standard.replace('--pagy.page--', page).replace('--pagy.items--', items));
+ }
+ pagyEl.getElementsByTagName('a')[0].click();
}
};
Pagy.addInputEventListeners(input, go);
};
@@ -97,6 +97,5 @@
// go when the input looses focus
input.addEventListener('focusout', handler);
// … and when pressing enter inside the input
input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
};
-