diff --git a/lib/javascripts/pagy.js b/lib/javascripts/pagy.js index b95065c01..718a05272 100644 --- a/lib/javascripts/pagy.js +++ b/lib/javascripts/pagy.js @@ -14,28 +14,28 @@ Pagy.addInputEventListeners = function(input, handler){ }; Pagy.compact = function(id, marker, page, trim){ - var pagyNav = document.getElementById(id), - input = pagyNav.getElementsByTagName('input')[0], - link = pagyNav.getElementsByTagName('a')[0], - linkP1 = pagyNav.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(); - } - } - }; + 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(); + } + } + }; Pagy.addInputEventListeners(input, go); }; Pagy.items = function(id, marker, from){ - var pagyNav = document.getElementById(id), - input = pagyNav.getElementsByTagName('input')[0], + var pagyEl = document.getElementById(id), + input = pagyEl.getElementsByTagName('input')[0], current = input.value, - link = pagyNav.getElementsByTagName('a')[0], + link = pagyEl.getElementsByTagName('a')[0], go = function(){ var items = input.value; if (current !== items) { @@ -49,18 +49,18 @@ Pagy.items = function(id, marker, from){ }; Pagy.responsive = function(id, tags, widths, series){ - var pagyNav = document.getElementById(id), - pagyParent = pagyNav.parentElement, + var pagyEl = document.getElementById(id), + pagyParent = pagyEl.parentElement, lastWidth = undefined, render = function(){ var parentWidth = parseInt(pagyParent.clientWidth), width = widths.find(function(w){return parentWidth > w}); if (width !== lastWidth) { - while (pagyNav.firstChild) { pagyNav.removeChild(pagyNav.firstChild) } + while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) } var html = tags['before']; series[width].forEach(function(item){html += tags[item]}); html += tags['after']; - pagyNav.insertAdjacentHTML('beforeend', html); + pagyEl.insertAdjacentHTML('beforeend', html); lastWidth = width; } }.bind(this);