aspaginator.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/Plugin/aspaginator", ["exports", "jquery", "Plugin"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(exports, require("jquery"), require("Plugin"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(mod.exports, global.jQuery, global.Plugin);
  11. global.PluginAspaginator = mod.exports;
  12. }
  13. })(this, function (_exports, _jquery, _Plugin2) {
  14. "use strict";
  15. Object.defineProperty(_exports, "__esModule", {
  16. value: true
  17. });
  18. _exports.default = void 0;
  19. _jquery = babelHelpers.interopRequireDefault(_jquery);
  20. _Plugin2 = babelHelpers.interopRequireDefault(_Plugin2);
  21. var NAME = 'paginator';
  22. var Paginator =
  23. /*#__PURE__*/
  24. function (_Plugin) {
  25. babelHelpers.inherits(Paginator, _Plugin);
  26. function Paginator() {
  27. babelHelpers.classCallCheck(this, Paginator);
  28. return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Paginator).apply(this, arguments));
  29. }
  30. babelHelpers.createClass(Paginator, [{
  31. key: "getName",
  32. value: function getName() {
  33. return NAME;
  34. }
  35. }, {
  36. key: "render",
  37. value: function render() {
  38. if (!_jquery.default.fn.asPaginator) {
  39. return;
  40. }
  41. var $el = this.$el;
  42. var total = $el.data('total');
  43. $el.asPaginator(total, this.options);
  44. }
  45. }], [{
  46. key: "getDefaults",
  47. value: function getDefaults() {
  48. return {
  49. namespace: 'pagination',
  50. currentPage: 1,
  51. itemsPerPage: 10,
  52. disabledClass: 'disabled',
  53. activeClass: 'active',
  54. visibleNum: {
  55. 0: 3,
  56. 480: 5
  57. },
  58. tpl: function tpl() {
  59. return '{{prev}}{{lists}}{{next}}';
  60. },
  61. components: {
  62. prev: {
  63. tpl: function tpl() {
  64. return "<li class=\"".concat(this.namespace, "-prev page-item\"><a class=\"page-link\" href=\"javascript:void(0)\" aria-label=\"Prev\"><span class=\"icon wb-chevron-left-mini\"></span></a></li>");
  65. }
  66. },
  67. next: {
  68. tpl: function tpl() {
  69. return "<li class=\"".concat(this.namespace, "-next page-item\"><a class=\"page-link\" href=\"javascript:void(0)\" aria-label=\"Next\"><span class=\"icon wb-chevron-right-mini\"></span></a></li>");
  70. }
  71. },
  72. lists: {
  73. tpl: function tpl() {
  74. var lists = '';
  75. var remainder = this.currentPage >= this.visible ? this.currentPage % this.visible : this.currentPage;
  76. remainder = remainder === 0 ? this.visible : remainder;
  77. for (var k = 1; k < remainder; k++) {
  78. lists += "<li class=\"".concat(this.namespace, "-items page-item\" data-value=\"").concat(this.currentPage - remainder + k, "\"><a class=\"page-link\" href=\"javascript:void(0)\">").concat(this.currentPage - remainder + k, "</a></li>");
  79. }
  80. lists += "<li class=\"".concat(this.namespace, "-items page-item ").concat(this.classes.active, "\" data-value=\"").concat(this.currentPage, "\"><a class=\"page-link\" href=\"javascript:void(0)\">").concat(this.currentPage, "</a></li>");
  81. for (var i = this.currentPage + 1, limit = i + this.visible - remainder - 1 > this.totalPages ? this.totalPages : i + this.visible - remainder - 1; i <= limit; i++) {
  82. lists += "<li class=\"".concat(this.namespace, "-items page-item\" data-value=\"").concat(i, "\"><a class=\"page-link\" href=\"javascript:void(0)\">").concat(i, "</a></li>");
  83. }
  84. return lists;
  85. }
  86. }
  87. }
  88. };
  89. }
  90. }]);
  91. return Paginator;
  92. }(_Plugin2.default);
  93. _Plugin2.default.register(NAME, Paginator);
  94. var _default = Paginator;
  95. _exports.default = _default;
  96. });