Sha256: ba38e66f1319a4ce5ef0cf56f385eed24ad814fef1dbab9587c3f253fcb724e3

Contents?: true

Size: 1011 Bytes

Versions: 3

Compression:

Stored size: 1011 Bytes

Contents

// See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items

function PagyItems(id, marker, from){
  var pagyNav = document.getElementById('pagy-items-'+id),
      input   = pagyNav.getElementsByTagName('input')[0],
      current = input.value,
      link    = pagyNav.getElementsByTagName('a')[0];

  this.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();
    }
  };

  // select the content on click: easier for typing a number
  input.addEventListener('click', function(){ this.select() });
  // jump to page number from input when the input looses focus
  input.addEventListener('focusout', this.go);
  // … and when pressing enter inside the input
  input.addEventListener('keyup', function(e){ if (e.which === 13) this.go() }.bind(this));

}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pagy-0.9.2 lib/pagy/extras/javascripts/pagy-items.js
pagy-0.9.1 lib/pagy/extras/javascripts/pagy-items.js
pagy-0.9.0 lib/pagy/extras/javascripts/pagy-items.js