Browse Source

Improve the mobile extension

Dennis Hernández 10 years ago
parent
commit
a4faec7284
2 changed files with 34 additions and 13 deletions
  1. 2 2
      src/extensions/mobile/README.md
  2. 32 11
      src/extensions/mobile/bootstrap-table-mobile.js

+ 2 - 2
src/extensions/mobile/README.md

@@ -20,7 +20,7 @@ Use Plugin: [bootstrap-table-mobile](https://github.com/wenzhixin/bootstrap-tabl
 
 * type: Boolean
 * description: Set true to check the window size on init.
-* default: `false`
+* default: `true`
 
 ### minWidth
 
@@ -32,4 +32,4 @@ Use Plugin: [bootstrap-table-mobile](https://github.com/wenzhixin/bootstrap-tabl
 
 * type: Integer
 * description: Set the minimum height when the table will change the view.
-* default: `562`
+* default: `undefined`

+ 32 - 11
src/extensions/mobile/bootstrap-table-mobile.js

@@ -1,7 +1,7 @@
 /**
  * @author: Dennis Hernández
  * @webSite: http://djhvscf.github.io/Blog
- * @version: v1.0.0
+ * @version: v1.1.0
  */
 
 !function ($) {
@@ -17,26 +17,43 @@
     };
 
     var changeView = function (el, width, height) {
-        if (width <= el.options.minWidth && height <= el.options.minHeight) {
-            if (!toggled) {
-                el.toggleView();
-                toggled = true;
+        if (el.options.minHeight) {
+            if (checkValuesLessEqual(width, el.options.minWidth) && checkValuesLessEqual(height, el.options.minHeight)) {
+                checkToggledStatus(false, true, el);
+            } else if (checkValuesGreater(width, el.options.minWidth) && checkValuesGreater(height, el.options.minHeight)) {
+                checkToggledStatus(true, false, el);
             }
-        } else if (width > el.options.minWidth && height > el.options.minHeight) {
-            if (toggled) {
-                el.toggleView()
-                toggled = false;
+        } else {
+            if (checkValuesLessEqual(width, el.options.minWidth)) {
+                checkToggledStatus(false, true, el);
+            } else if (checkValuesGreater(width, el.options.minWidth)) {
+                checkToggledStatus(true, false, el);
             }
         }
 
         resetView(el);
     };
 
+    var checkValuesLessEqual = function (currentValue, targetValue) {
+        return currentValue <= targetValue;
+    };
+
+    var checkValuesGreater = function (currentValue, targetValue) {
+        return currentValue > targetValue;
+    };
+
+    var checkToggledStatus = function (targetToggledStatus, newToggledStatus, el) {
+        if (toggled === targetToggledStatus) {
+            el.toggleView();
+            toggled = newToggledStatus;
+        }
+    };
+
     $.extend($.fn.bootstrapTable.defaults, {
         mobileResponsive: false,
         minWidth: 562,
-        minHeight: 562,
-        checkOnInit: false
+        minHeight: undefined,
+        checkOnInit: true
     });
 
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
@@ -49,6 +66,10 @@
             return;
         }
 
+        if (!this.options.minWidth) {
+            return;
+        }
+
         var that = this;
         $(window).resize(function () {
             changeView(that, $(this).width(), $(this).height())