浏览代码

Delete repeated code and added more functionalities to resizable extension

Dennis Hernández 10 年之前
父节点
当前提交
fb6f3572a7
共有 2 个文件被更改,包括 47 次插入18 次删除
  1. 3 6
      src/bootstrap-table.js
  2. 44 12
      src/extensions/resizable/bootstrap-table-resizable.js

+ 3 - 6
src/bootstrap-table.js

@@ -809,11 +809,7 @@
         if (this.options.showToggle) {
         if (this.options.showToggle) {
             this.$toolbar.find('button[name="toggle"]')
             this.$toolbar.find('button[name="toggle"]')
                 .off('click').on('click', function () {
                 .off('click').on('click', function () {
-                    that.options.cardView = !that.options.cardView;
-                    that.initHeader();
-                    // Fixed remove toolbar when click cardView button.
-                    //that.initToolbar();
-                    that.initBody();
+                    that.toggleView();
                 });
                 });
         }
         }
 
 
@@ -2127,7 +2123,8 @@
     BootstrapTable.prototype.toggleView = function () {
     BootstrapTable.prototype.toggleView = function () {
         this.options.cardView = !this.options.cardView;
         this.options.cardView = !this.options.cardView;
         this.initHeader();
         this.initHeader();
-        this.initToolbar();
+        // Fixed remove toolbar when click cardView button.
+        //that.initToolbar();
         this.initBody();
         this.initBody();
     };
     };
 
 

+ 44 - 12
src/extensions/resizable/bootstrap-table-resizable.js

@@ -7,6 +7,25 @@
 (function ($) {
 (function ($) {
     'use strict';
     'use strict';
 
 
+    var initResizable = function (el) {
+        var that = el;
+
+        //Deletes the plugin to re-create it
+        $(el.$el).colResizable({disable: true});
+
+        //Creates the plugin
+        $(el.$el).colResizable({
+            liveDrag: that.options.liveDrag,
+            fixed: that.options.fixed,
+            headerOnly: that.options.headerOnly,
+            minWidth: that.options.minWidth,
+            hoverCursor: that.options.hoverCursor,
+            dragCursor: that.options.dragCursor,
+            onResize: that.options.onResizableResize,
+            onDrag: that.options.onResizableDrag
+        });
+    };
+
     $.extend($.fn.bootstrapTable.defaults, {
     $.extend($.fn.bootstrapTable.defaults, {
         resizable: false,
         resizable: false,
         liveDrag: false,
         liveDrag: false,
@@ -24,23 +43,36 @@
     });
     });
 
 
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
-        _init = BootstrapTable.prototype.init;
+        _init = BootstrapTable.prototype.init,
+        _toggleColumn = BootstrapTable.prototype.toggleColumn,
+        _toggleView = BootstrapTable.prototype.toggleView;
 
 
     BootstrapTable.prototype.init = function () {
     BootstrapTable.prototype.init = function () {
-        var that = this;
         _init.apply(this, Array.prototype.slice.apply(arguments));
         _init.apply(this, Array.prototype.slice.apply(arguments));
 
 
         if (this.options.resizable) {
         if (this.options.resizable) {
-            $(this.$el).colResizable({
-                liveDrag: that.options.liveDrag,
-                fixed: that.options.fixed,
-                headerOnly: that.options.headerOnly,
-                minWidth: that.options.minWidth,
-                hoverCursor: that.options.hoverCursor,
-                dragCursor: that.options.dragCursor,
-                onResize: that.options.onResizableResize,
-                onDrag: that.options.onResizableDrag
-            });
+            initResizable(this);
+        }
+    };
+
+    BootstrapTable.prototype.toggleColumn = function () {
+        _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
+
+        if (this.options.resizable) {
+            initResizable(this);
+        }
+    };
+
+    BootstrapTable.prototype.toggleView = function () {
+        _toggleView.apply(this, Array.prototype.slice.apply(arguments));
+
+        if (this.options.resizable) {
+            if (this.options.cardView) {
+                //Deletes the plugin
+                $(this.$el).colResizable({disable: true});
+                return;
+            }
+            initResizable(this);
         }
         }
     };
     };
 })(jQuery);
 })(jQuery);