浏览代码

Fixed icons (#5329)

* Set the icons in the initConstants function to prevent issues with
extentions

* Fixed customizing icons for the multiple sort extension

* Fixed issue that the button is always shown, also if the
showMultiSortButton is set to false
Dustin Utecht 5 年之前
父节点
当前提交
e60b8ea4fc
共有 2 个文件被更改,包括 47 次插入51 次删除
  1. 4 4
      src/bootstrap-table.js
  2. 43 47
      src/extensions/multiple-sort/bootstrap-table-multiple-sort.js

+ 4 - 4
src/bootstrap-table.js

@@ -50,6 +50,10 @@ class BootstrapTable {
     if (typeof this.buttons !== 'object') {
     if (typeof this.buttons !== 'object') {
       this.buttons = {}
       this.buttons = {}
     }
     }
+
+    if (typeof opts.icons === 'string') {
+      opts.icons = Utils.calculateObjectValue(null, opts.icons)
+    }
   }
   }
 
 
   initLocale () {
   initLocale () {
@@ -563,10 +567,6 @@ class BootstrapTable {
       `${this.constants.classes.pull}-${opts.buttonsAlign}`
       `${this.constants.classes.pull}-${opts.buttonsAlign}`
     ].join(' ')}">`]
     ].join(' ')}">`]
 
 
-    if (typeof opts.icons === 'string') {
-      opts.icons = Utils.calculateObjectValue(null, opts.icons)
-    }
-
     if (typeof opts.buttonsOrder === 'string') {
     if (typeof opts.buttonsOrder === 'string') {
       opts.buttonsOrder = opts.buttonsOrder.replace(/\[|\]| |'/g, '').toLowerCase().split(',')
       opts.buttonsOrder = opts.buttonsOrder.replace(/\[|\]| |'/g, '').toLowerCase().split(',')
     }
     }

+ 43 - 47
src/extensions/multiple-sort/bootstrap-table-multiple-sort.js

@@ -7,13 +7,42 @@
 
 
 let isSingleSort = false
 let isSingleSort = false
 const Utils = $.fn.bootstrapTable.utils
 const Utils = $.fn.bootstrapTable.utils
+
+$.extend($.fn.bootstrapTable.defaults.icons, {
+  plus: {
+    bootstrap3: 'glyphicon-plus',
+    bootstrap4: 'fa-plus',
+    bootstrap5: 'fa-plus',
+    semantic: 'fa-plus',
+    materialize: 'plus',
+    foundation: 'fa-plus',
+    bulma: 'fa-plus',
+    'bootstrap-table': 'icon-plus'
+  }[$.fn.bootstrapTable.theme] || 'fa-clock',
+  minus: {
+    bootstrap3: 'glyphicon-minus',
+    bootstrap4: 'fa-minus',
+    bootstrap5: 'fa-minus',
+    semantic: 'fa-minus',
+    materialize: 'minus',
+    foundation: 'fa-minus',
+    bulma: 'fa-minus',
+    'bootstrap-table': 'icon-minus'
+  }[$.fn.bootstrapTable.theme] || 'fa-clock',
+  sort: {
+    bootstrap3: 'glyphicon-sort',
+    bootstrap4: 'fa-sort',
+    bootstrap5: 'fa-sort',
+    semantic: 'fa-sort',
+    materialize: 'sort',
+    foundation: 'fa-sort',
+    bulma: 'fa-sort',
+    'bootstrap-table': 'icon-sort-amount-asc'
+  }[$.fn.bootstrapTable.theme] || 'fa-clock'
+})
+
 const theme = {
 const theme = {
   bootstrap3: {
   bootstrap3: {
-    icons: {
-      plus: 'glyphicon-plus',
-      minus: 'glyphicon-minus',
-      sort: 'glyphicon-sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="modal fade" id="%s" tabindex="-1" role="dialog" aria-labelledby="%sLabel" aria-hidden="true">
         <div class="modal fade" id="%s" tabindex="-1" role="dialog" aria-labelledby="%sLabel" aria-hidden="true">
@@ -60,11 +89,6 @@ const theme = {
     }
     }
   },
   },
   bootstrap4: {
   bootstrap4: {
-    icons: {
-      plus: 'fa-plus',
-      minus: 'fa-minus',
-      sort: 'fa-sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="modal fade" id="%s" tabindex="-1" role="dialog" aria-labelledby="%sLabel" aria-hidden="true">
         <div class="modal fade" id="%s" tabindex="-1" role="dialog" aria-labelledby="%sLabel" aria-hidden="true">
@@ -113,11 +137,6 @@ const theme = {
     }
     }
   },
   },
   bootstrap5: {
   bootstrap5: {
-    icons: {
-      plus: 'fa-plus',
-      minus: 'fa-minus',
-      sort: 'fa-sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="modal fade" id="%s" tabindex="-1" role="dialog" aria-labelledby="%sLabel" aria-hidden="true">
         <div class="modal fade" id="%s" tabindex="-1" role="dialog" aria-labelledby="%sLabel" aria-hidden="true">
@@ -166,11 +185,6 @@ const theme = {
     }
     }
   },
   },
   semantic: {
   semantic: {
-    icons: {
-      plus: 'fa-plus',
-      minus: 'fa-minus',
-      sort: 'fa-sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="ui modal tiny" id="%s" aria-labelledby="%sLabel" aria-hidden="true">
         <div class="ui modal tiny" id="%s" aria-labelledby="%sLabel" aria-hidden="true">
@@ -213,11 +227,6 @@ const theme = {
     }
     }
   },
   },
   materialize: {
   materialize: {
-    icons: {
-      plus: 'plus',
-      minus: 'minus',
-      sort: 'sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div id="%s" class="modal" aria-labelledby="%sLabel" aria-hidden="true">
         <div id="%s" class="modal" aria-labelledby="%sLabel" aria-hidden="true">
@@ -257,11 +266,6 @@ const theme = {
     }
     }
   },
   },
   foundation: {
   foundation: {
-    icons: {
-      plus: 'fa-plus',
-      minus: 'fa-minus',
-      sort: 'fa-sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="reveal" id="%s" data-reveal aria-labelledby="%sLabel" aria-hidden="true">
         <div class="reveal" id="%s" data-reveal aria-labelledby="%sLabel" aria-hidden="true">
@@ -304,11 +308,6 @@ const theme = {
     }
     }
   },
   },
   bulma: {
   bulma: {
-    icons: {
-      plus: 'fa-plus',
-      minus: 'fa-minus',
-      sort: 'fa-sort'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="modal" id="%s" aria-labelledby="%sLabel" aria-hidden="true">
         <div class="modal" id="%s" aria-labelledby="%sLabel" aria-hidden="true">
@@ -349,11 +348,6 @@ const theme = {
     }
     }
   },
   },
   'bootstrap-table': {
   'bootstrap-table': {
-    icons: {
-      plus: 'icon-plus',
-      minus: 'icon-minus',
-      sort: 'icon-sort-amount-asc'
-    },
     html: {
     html: {
       multipleSortModal: `
       multipleSortModal: `
         <div class="modal" id="%s" aria-labelledby="%sLabel" aria-hidden="true">
         <div class="modal" id="%s" aria-labelledby="%sLabel" aria-hidden="true">
@@ -407,9 +401,9 @@ const showSortModal = that => {
       theme.html.multipleSortModal,
       theme.html.multipleSortModal,
       _selector, _selector, _selector,
       _selector, _selector, _selector,
       that.options.formatMultipleSort(),
       that.options.formatMultipleSort(),
-      Utils.sprintf(that.constants.html.icon, o.iconsPrefix, theme.icons.plus),
+      Utils.sprintf(that.constants.html.icon, o.iconsPrefix, o.icons.plus),
       that.options.formatAddLevel(),
       that.options.formatAddLevel(),
-      Utils.sprintf(that.constants.html.icon, o.iconsPrefix, theme.icons.minus),
+      Utils.sprintf(that.constants.html.icon, o.iconsPrefix, o.icons.minus),
       that.options.formatDeleteLevel(),
       that.options.formatDeleteLevel(),
       that.options.formatColumn(),
       that.options.formatColumn(),
       that.options.formatOrder(),
       that.options.formatOrder(),
@@ -592,11 +586,13 @@ BootstrapTable.prototype.initToolbar = function (...args) {
     that.onMultipleSort()
     that.onMultipleSort()
   }
   }
 
 
-  this.buttons = Object.assign(this.buttons, {
-    multipleSort: {
-      html: Utils.sprintf(theme.html.multipleSortButton, that.sortModalSelector, this.options.formatMultipleSort(), Utils.sprintf(that.constants.html.icon, o.iconsPrefix, theme.icons.sort))
-    }
-  })
+  if (this.options.showMultiSortButton) {
+    this.buttons = Object.assign(this.buttons, {
+      multipleSort: {
+        html: Utils.sprintf(theme.html.multipleSortButton, that.sortModalSelector, this.options.formatMultipleSort(), Utils.sprintf(that.constants.html.icon, o.iconsPrefix, o.icons.sort))
+      }
+    })
+  }
 
 
   _initToolbar.apply(this, Array.prototype.slice.apply(args))
   _initToolbar.apply(this, Array.prototype.slice.apply(args))