Version 3.18.1
Show:

File: paginator/js/paginator.js

  1. /**
  2. The Paginator utility allows you to display an item or a group of items
  3. depending on the number of items you wish to display at one time.
  4. Paginator's primary functionality is contained in `paginator-core` and is mixed
  5. into `paginator` to allow `paginator` to have extra functionality added to it
  6. while leaving the core functionality untouched. This allows `paginator-core` to
  7. remain available for use later on or used in isolation if it is the only piece
  8. you need.
  9. Due to the vast number of interfaces a paginator could possibly consist of,
  10. `Paginator` does not contain any ready to use UIs. However, `Paginator` is
  11. ready to be used in any Based-based, module such as a Widget, by extending your
  12. desired class and mixing in `Paginator`. This is displayed in the following
  13. example:
  14. <pre><code>
  15. YUI().use('paginator-url', 'widget', function (Y){
  16. var MyPaginator = Y.Base.create('my-paginator', Y.Widget, [Y.Paginator], {
  17. renderUI: function () {
  18. var numbers = '',
  19. i, numberOfPages = this.get('totalPages');
  20. for (i = 1; i <= numberOfPages; i++) {
  21. // use paginator-url's formatUrl method
  22. numbers += '&lt;a href="' + this.formatUrl(i) + '">' + i + '&lt;/a>';
  23. }
  24. this.get('boundingBox').append(numbers);
  25. },
  26. bindUI: function () {
  27. this.get('boundingBox').delegate('click', function (e) {
  28. // let's not go to the page, just update internally
  29. e.preventDefault();
  30. this.set('page', parseInt(e.currentTarget.getContent(), 10));
  31. }, 'a', this);
  32. this.after('pageChange', function (e) {
  33. // mark the link selected when it's the page being displayed
  34. var bb = this.get('boundingBox'),
  35. activeClass = 'selected';
  36. bb.all('a').removeClass(activeClass).item(e.newVal).addClass(activeClass);
  37. });
  38. }
  39. });
  40. var myPg = new MyPaginator({
  41. totalItems: 100,
  42. pageUrl: '?pg={page}'
  43. });
  44. myPg.render();
  45. });
  46. </code></pre>
  47. @module paginator
  48. @main paginator
  49. @class Paginator
  50. @constructor
  51. @since 3.11.0
  52. */
  53. Y.Paginator = Y.mix(
  54. Y.Base.create('paginator', Y.Base, [Y.Paginator.Core]),
  55. Y.Paginator
  56. );