API Docs for: 3.13.0
Show:

File: paginator/js/paginator-url.js

  1. /**
  2. Adds in URL options for paginator links.
  3.  
  4. @module paginator
  5. @submodule paginator-url
  6. @class Paginator.Url
  7. @since 3.10.0
  8. */
  9.  
  10. function PaginatorUrl () {}
  11.  
  12. PaginatorUrl.ATTRS = {
  13. /**
  14. URL to return formatted with the page number. URL uses `Y.Lang.sub` for page number stubstitutions.
  15.  
  16. For example, if the page number is `3`, setting the `pageUrl` to `"?pg={page}"`, will result in `?pg=3`
  17.  
  18. @attribute pageUrl
  19. @type String
  20. **/
  21. pageUrl: {}
  22. };
  23.  
  24. PaginatorUrl.prototype = {
  25. /**
  26. Returns a formated URL for the previous page.
  27. @method prevPageUrl
  28. @return {String | null} Formatted URL for the previous page, or `null` if there is no previous page.
  29. */
  30. prevPageUrl: function () {
  31. return (this.hasPrevPage() && this.formatPageUrl(this.get('page') - 1)) || null;
  32. },
  33.  
  34. /**
  35. Returns a formated URL for the next page.
  36. @method nextPageUrl
  37. @return {String | null} Formatted URL for the next page or `null` if there is no next page.
  38. */
  39. nextPageUrl: function () {
  40. return (this.hasNextPage() && this.formatPageUrl(this.get('page') + 1)) || null;
  41. },
  42.  
  43. /**
  44. Returns a formated URL for the provided page number.
  45. @method formatPageUrl
  46. @param {Number} [page] Page value to be used in the formatted URL. If empty, page will be the value of the `page` ATTRS.
  47. @return {String | null} Formatted URL for the page or `null` if there is not a `pageUrl` set.
  48. */
  49. formatPageUrl: function (page) {
  50. var pageUrl = this.get('pageUrl');
  51. if (pageUrl) {
  52. return Y.Lang.sub(pageUrl, {
  53. page: page || this.get('page')
  54. });
  55. }
  56. return null;
  57. }
  58. };
  59.  
  60. Y.namespace('Paginator').Url = PaginatorUrl;
  61.  
  62. Y.Base.mix(Y.Paginator, [PaginatorUrl]);
  63.