Browse Source

Rewrote i18n-enhance to ES6.

zhixin 6 years ago
parent
commit
c025b761aa
1 changed files with 25 additions and 26 deletions
  1. 25 26
      src/extensions/i18n-enhance/bootstrap-table-i18n-enhance.js

+ 25 - 26
src/extensions/i18n-enhance/bootstrap-table-i18n-enhance.js

@@ -1,35 +1,34 @@
 /**
  * @author: Jewway
- * @version: v1.0.0
+ * @update zhixin wen <wenzhixin2010@gmail.com>
  */
 
-!function ($) {
-  'use strict'
+($ => {
 
-  var BootstrapTable = $.fn.bootstrapTable.Constructor
+  $.fn.bootstrapTable.methods.push('changeTitle')
+  $.fn.bootstrapTable.methods.push('changeLocale')
 
-  BootstrapTable.prototype.changeTitle = function (locale) {
-    $.each(this.options.columns, function (idx, columnList) {
-      $.each(columnList, function (idx, column) {
-        if (column.field) {
-          column.title = locale[column.field]
-        }
+  $.BootstrapTable = class extends $.BootstrapTable {
+
+    changeTitle (locale) {
+      $.each(this.options.columns, (idx, columnList) => {
+        $.each(columnList, (idx, column) => {
+          if (column.field) {
+            column.title = locale[column.field]
+          }
+        })
       })
-    })
-    this.initHeader()
-    this.initBody()
-    this.initToolbar()
-  }
+      this.initHeader()
+      this.initBody()
+      this.initToolbar()
+    }
 
-  BootstrapTable.prototype.changeLocale = function (localeId) {
-    this.options.locale = localeId
-    this.initLocale()
-    this.initPagination()
-    this.initBody()
-    this.initToolbar()
+    changeLocale (localeId) {
+      this.options.locale = localeId
+      this.initLocale()
+      this.initPagination()
+      this.initBody()
+      this.initToolbar()
+    }
   }
-
-  $.fn.bootstrapTable.methods.push('changeTitle')
-  $.fn.bootstrapTable.methods.push('changeLocale')
-
-}(jQuery)
+})(jQuery)