lib/javascripts/pagy.js in pagy-5.2.3 vs lib/javascripts/pagy.js in pagy-5.3.0
- old
+ new
@@ -1,11 +1,13 @@
// See the Pagy documentation: https://ddnexus.github.io/pagy/extras#javascript
+// This code should be OK also with very old browsers
+
// Container of the whole pagy stuff
function Pagy(){}
-Pagy.version = '5.2.3'
+Pagy.version = '5.3.0'
// Used by the waitForMe function
Pagy.delay = 100
// Scan the target for data-pagy-json elements and apply their functions
@@ -21,14 +23,15 @@
}
}
// Power the pagy*_nav_js helpers
Pagy.nav =
- function(pagyEl, tags, sequels, trimParam) {
- var lastWidth,
- pageREg = new RegExp(/__pagy_page__/g),
- widths = []
+ function(pagyEl, tags, sequels, label_sequels, trimParam ) {
+ label_sequels = (label_sequels === null) ? sequels : label_sequels
+ var widths = [], lastWidth,
+ fill = function(string, item, label) { return string.replace(/__pagy_page__/g, item)
+ .replace(/__pagy_label__/g, label) }
for (var width in sequels) {
if (sequels.hasOwnProperty(width)) { widths.push(parseInt(width, 10)) }
}
widths.sort(function(a, b) { return b - a })
@@ -38,16 +41,18 @@
for (i = 0, len = widths.length; i < len; i++) {
if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
}
if (width !== lastWidth) {
var html = tags.before,
- series = sequels[width]
+ series = sequels[width],
+ labels = label_sequels[width]
for (i = 0, len = series.length; i < len; i++) {
- var item = series[i]
- if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(tags.link.replace(pageREg, item), trimParam) }
- else if (typeof(item) === 'number') { html += tags.link.replace(pageREg, item) }
+ var item = series[i],
+ label = labels[i]
+ if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(fill(tags.link, item, label), trimParam) }
+ else if (typeof(item) === 'number') { html += fill(tags.link, item, label) }
else if (item === 'gap') { html += tags.gap }
- else if (typeof(item) === 'string') { html += tags.active.replace(pageREg, item) }
+ else if (typeof(item) === 'string') { html += fill(tags.active, item, label) }
}
html += tags.after
this.insertAdjacentHTML('afterbegin', html)
lastWidth = width
}