Browse Source

Rewrote jump-to extension to ES6.

zhixin 6 years ago
parent
commit
a164ea47d3
51 changed files with 105 additions and 122 deletions
  1. 4 20
      site/docs/extensions/page-jump-to.md
  2. 1 1
      src/bootstrap-table.js
  3. 11 8
      src/extensions/page-jump-to/bootstrap-table-page-jump-to.css
  4. 41 45
      src/extensions/page-jump-to/bootstrap-table-page-jump-to.js
  5. 1 1
      src/locale/bootstrap-table-af-ZA.js
  6. 1 1
      src/locale/bootstrap-table-ar-SA.js
  7. 1 1
      src/locale/bootstrap-table-ca-ES.js
  8. 1 1
      src/locale/bootstrap-table-cs-CZ.js
  9. 1 1
      src/locale/bootstrap-table-da-DK.js
  10. 1 1
      src/locale/bootstrap-table-de-DE.js
  11. 1 1
      src/locale/bootstrap-table-el-GR.js
  12. 1 1
      src/locale/bootstrap-table-en-US.js
  13. 1 1
      src/locale/bootstrap-table-es-AR.js
  14. 1 1
      src/locale/bootstrap-table-es-CL.js
  15. 1 1
      src/locale/bootstrap-table-es-CR.js
  16. 1 1
      src/locale/bootstrap-table-es-ES.js
  17. 1 1
      src/locale/bootstrap-table-es-MX.js
  18. 1 1
      src/locale/bootstrap-table-es-NI.js
  19. 1 1
      src/locale/bootstrap-table-es-SP.js
  20. 1 1
      src/locale/bootstrap-table-et-EE.js
  21. 1 1
      src/locale/bootstrap-table-eu-EU.js
  22. 1 1
      src/locale/bootstrap-table-fa-IR.js
  23. 1 1
      src/locale/bootstrap-table-fi-FI.js
  24. 1 1
      src/locale/bootstrap-table-fr-BE.js
  25. 1 1
      src/locale/bootstrap-table-fr-FR.js
  26. 1 1
      src/locale/bootstrap-table-he-IL.js
  27. 1 1
      src/locale/bootstrap-table-hr-HR.js
  28. 1 1
      src/locale/bootstrap-table-hu-HU.js
  29. 1 1
      src/locale/bootstrap-table-id-ID.js
  30. 1 1
      src/locale/bootstrap-table-it-IT.js
  31. 2 2
      src/locale/bootstrap-table-ja-JP.js
  32. 1 1
      src/locale/bootstrap-table-ka-GE.js
  33. 1 1
      src/locale/bootstrap-table-ko-KR.js
  34. 1 1
      src/locale/bootstrap-table-ms-MY.js
  35. 1 1
      src/locale/bootstrap-table-nb-NO.js
  36. 1 1
      src/locale/bootstrap-table-nl-NL.js
  37. 1 1
      src/locale/bootstrap-table-pl-PL.js
  38. 1 1
      src/locale/bootstrap-table-pt-BR.js
  39. 1 1
      src/locale/bootstrap-table-pt-PT.js
  40. 1 1
      src/locale/bootstrap-table-ro-RO.js
  41. 1 1
      src/locale/bootstrap-table-ru-RU.js
  42. 1 1
      src/locale/bootstrap-table-sk-SK.js
  43. 1 1
      src/locale/bootstrap-table-sv-SE.js
  44. 1 1
      src/locale/bootstrap-table-th-TH.js
  45. 1 1
      src/locale/bootstrap-table-tr-TR.js
  46. 1 1
      src/locale/bootstrap-table-uk-UA.js
  47. 1 1
      src/locale/bootstrap-table-ur-PK.js
  48. 1 1
      src/locale/bootstrap-table-uz-Latn-UZ.js
  49. 1 1
      src/locale/bootstrap-table-vi-VN.js
  50. 1 1
      src/locale/bootstrap-table-zh-CN.js
  51. 1 1
      src/locale/bootstrap-table-zh-TW.js

+ 4 - 20
site/docs/extensions/page-jump-to.md

@@ -9,34 +9,18 @@ toc: true
 ## Usage
 
 {% highlight html %}
-<link rel="stylesheet" href="extensions/page-jumpto/bootstrap-table-jumpto.css"></style>
-<script src="extensions/page-jumpto/bootstrap-table-jumpto.js"></script>
+<link rel="stylesheet" href="extensions/page-jump-to/bootstrap-table-jump-to.css"></style>
+<script src="extensions/page-jump-to/bootstrap-table-jump-to.js"></script>
 {% endhighlight %}
 
 ## Options
 
-### showJumpto
+### showJumpTo
 
 - **type:** `Boolean`
 
 - **Detail:**
 
-   Set true to enable show 'jump to page'. can be defined via `data-show-jumpto` HTML attributes.
+   Set true to enable show 'jump to page'. Can be defined via `data-show-jump-to` HTML attributes.
 
 - **Default:** `false`
-* button style: can be styled via bootstrap-table buttonsClass attributes.
-
-`{% highlight html %}
-<table id="my_table_id"
-  data-url="data/url.json"
-  data-id-field="id"
-  data-show-jumpto="true">
-  <thead>
-    <tr>
-      <th class="col-md-1" data-field="id" data-sortable="true" data-align="center">#</th>
-      <th class="col-md-4" data-field="name" data-editable="true">Name</th>
-      <th class="col-md-7" data-field="description" data-editable="true" data-editable-emptytext="Custom empty text.">Description</th>
-    </tr>
-  </thead>
-</table>
-{% endhighlight %}`

+ 1 - 1
src/bootstrap-table.js

@@ -728,7 +728,7 @@
         ? '<div class="fixed-table-pagination"></div>' : ''
 
       this.$container = $(`
-        <div class="bootstrap-table">
+        <div class="bootstrap-table ${this.constants.theme}">
         <div class="fixed-table-toolbar"></div>
         ${topPagination}
         <div class="fixed-table-container">

+ 11 - 8
src/extensions/page-jump-to/bootstrap-table-page-jump-to.css

@@ -1,8 +1,11 @@
-.jumpto input {
-    height: 31px;
-    width: 50px;
-    margin-left: 5px;
-    margin-right: 5px;
-    text-align: center;
-    display: inline-block;
-}
+.bootstrap-table.bootstrap3 .fixed-table-pagination > .pagination ul.pagination,
+.bootstrap-table.bootstrap3 .fixed-table-pagination > .pagination .page-jump-to {
+  display: inline;
+}
+
+.bootstrap-table .fixed-table-pagination > .pagination .page-jump-to input {
+  width: 70px;
+  margin-left: 5px;
+  text-align: center;
+  float: left;
+}

+ 41 - 45
src/extensions/page-jump-to/bootstrap-table-page-jump-to.js

@@ -1,50 +1,46 @@
 /**
  * @author Jay <jwang@dizsoft.com>
+ * @update zhixin wen <wenzhixin2010@gmail.com>
  */
 
-(function ($) {
-    'use strict';
-    var sprintf = $.fn.bootstrapTable.utils.sprintf;
-
-    $.extend($.fn.bootstrapTable.defaults, {
-        showJumpto: false,
-        exportOptions: {}
-    });
-
-    $.extend($.fn.bootstrapTable.locales, {
-        formatJumpto: function () {
-            return 'GO';
-        }
-    });
-    $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
-
-    var BootstrapTable = $.fn.bootstrapTable.Constructor,
-        _initPagination = BootstrapTable.prototype.initPagination;
-
-    BootstrapTable.prototype.initPagination = function () {
-        _initPagination.apply(this, Array.prototype.slice.apply(arguments));
-
-        if (this.options.showJumpto) {
-            var that = this,
-                $pageGroup = this.$pagination.find('ul.pagination'),
-                $jumpto = $pageGroup.find('li.jumpto');
-
-            if (!$jumpto.length) {
-                $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);
-
-                $jumpto.find('button').click(function () {
-                    that.selectPage(parseInt($jumpto.find('input').val()));
-                });
-            }
+($ => {
+  const Utils = $.fn.bootstrapTable.utils
+
+  $.extend($.fn.bootstrapTable.defaults, {
+    showJumpTo: false
+  })
+
+  $.extend($.fn.bootstrapTable.locales, {
+    formatJumpTo () {
+      return 'GO'
+    }
+  })
+  $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales)
+
+  $.BootstrapTable = class extends $.BootstrapTable {
+    initPagination (...args) {
+      super.initPagination(...args)
+
+      if (this.options.showJumpTo) {
+        const that = this
+        const $pageGroup = this.$pagination.find('> .pagination')
+        let $jumpTo = $pageGroup.find('.page-jump-to')
+
+        if (!$jumpTo.length) {
+          $jumpTo = $(`
+            <div class="page-jump-to ${this.constants.classes.inputGroup}">
+            <input type="number" class="${this.constants.classes.input}${Utils.sprintf(' input-%s', this.options.iconSize)}" value="${this.options.pageNumber}">
+            <button class="${this.constants.buttonsClass}"  type="button">
+            ${this.options.formatJumpTo()}
+            </button>
+            </div>
+          `).appendTo($pageGroup)
+
+          $jumpTo.find('button').click(() => {
+            this.selectPage(+$jumpTo.find('input').val())
+          })
         }
-    };
-})(jQuery);
+      }
+    }
+  }
+})(jQuery)

+ 1 - 1
src/locale/bootstrap-table-af-ZA.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ar-SA.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ca-ES.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-cs-CZ.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-da-DK.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Ryd filtre'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-de-DE.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Lösche Filter'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-el-GR.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-en-US.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-es-AR.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-es-CL.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-es-CR.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-es-ES.js

@@ -53,7 +53,7 @@
     formatClearFilters: function () {
       return 'Borrar los filtros'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch: function () {

+ 1 - 1
src/locale/bootstrap-table-es-MX.js

@@ -55,7 +55,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-es-NI.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-es-SP.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-et-EE.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-eu-EU.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-fa-IR.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-fi-FI.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Poista suodattimet'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-fr-BE.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-fr-FR.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Vider les filtres'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-he-IL.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-hr-HR.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-hu-HU.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-id-ID.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Bersihkan filter'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-it-IT.js

@@ -55,7 +55,7 @@
     formatClearFilters () {
       return 'Pulisci filtri'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 2 - 2
src/locale/bootstrap-table-ja-JP.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {
@@ -65,4 +65,4 @@
   }
 
   $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['ja-JP'])
-})(jQuery)
+})(jQuery)

+ 1 - 1
src/locale/bootstrap-table-ka-GE.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ko-KR.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ms-MY.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-nb-NO.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-nl-NL.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Verwijder filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-pl-PL.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-pt-BR.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-pt-PT.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ro-RO.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ru-RU.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Очистить фильтры'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-sk-SK.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Odstráň filtre'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-sv-SE.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-th-TH.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-tr-TR.js

@@ -54,7 +54,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-uk-UA.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Очистити фільтри'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-ur-PK.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-uz-Latn-UZ.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Filtrlarni tozalash'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-vi-VN.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return 'Clear filters'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return 'GO'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-zh-CN.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return '清空过滤'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return '跳转'
     },
     formatAdvancedSearch () {

+ 1 - 1
src/locale/bootstrap-table-zh-TW.js

@@ -53,7 +53,7 @@
     formatClearFilters () {
       return '清空過濾'
     },
-    formatJumpto () {
+    formatJumpTo () {
       return '跳轉'
     },
     formatAdvancedSearch () {