bootstrap-table-page-jump-to.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define([], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory();
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory();
  11. global.bootstrapTablePageJumpTo = mod.exports;
  12. }
  13. })(this, function () {
  14. 'use strict';
  15. /**
  16. * @author Jay <jwang@dizsoft.com>
  17. */
  18. (function ($) {
  19. 'use strict';
  20. var sprintf = $.fn.bootstrapTable.utils.sprintf;
  21. $.extend($.fn.bootstrapTable.defaults, {
  22. showJumpto: false,
  23. exportOptions: {}
  24. });
  25. $.extend($.fn.bootstrapTable.locales, {
  26. formatJumpto: function formatJumpto() {
  27. return 'GO';
  28. }
  29. });
  30. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
  31. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  32. _initPagination = BootstrapTable.prototype.initPagination;
  33. BootstrapTable.prototype.initPagination = function () {
  34. _initPagination.apply(this, Array.prototype.slice.apply(arguments));
  35. if (this.options.showJumpto) {
  36. var that = this,
  37. $pageGroup = this.$pagination.find('ul.pagination'),
  38. $jumpto = $pageGroup.find('li.jumpto');
  39. if (!$jumpto.length) {
  40. $jumpto = $(['<li class="jumpto">', '<input type="text" class="form-control">', '<button class="btn' + sprintf(' btn-%s', this.options.buttonsClass) + sprintf(' btn-%s', this.options.iconSize) + '" title="' + this.options.formatJumpto() + '" ' + ' type="button">' + this.options.formatJumpto(), '</button>', '</li>'].join('')).appendTo($pageGroup);
  41. $jumpto.find('button').click(function () {
  42. that.selectPage(parseInt($jumpto.find('input').val()));
  43. });
  44. }
  45. }
  46. };
  47. })(jQuery);
  48. });