Skip to content

Commit

Permalink
better internal javascript naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Dec 1, 2018
1 parent 910facc commit 263c12d
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/javascripts/pagy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 263c12d

Please sign in to comment.