1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define([], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory();
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory();
|
11 | global.bootstrapTableMobile = mod.exports;
|
12 | }
|
13 | })(this, function () {
|
14 | 'use strict';
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | !function ($) {
|
23 |
|
24 | 'use strict';
|
25 |
|
26 | var showHideColumns = function showHideColumns(that, checked) {
|
27 | if (that.options.columnsHidden.length > 0) {
|
28 | $.each(that.columns, function (i, column) {
|
29 | if (that.options.columnsHidden.indexOf(column.field) !== -1) {
|
30 | if (column.visible !== checked) {
|
31 | that.toggleColumn(that.fieldsColumnsIndex[column.field], checked, true);
|
32 | }
|
33 | }
|
34 | });
|
35 | }
|
36 | };
|
37 |
|
38 | var resetView = function resetView(that) {
|
39 | if (that.options.height || that.options.showFooter) {
|
40 | setTimeout(function () {
|
41 | that.resetView.call(that);
|
42 | }, 1);
|
43 | }
|
44 | };
|
45 |
|
46 | var changeView = function changeView(that, width, height) {
|
47 | if (that.options.minHeight) {
|
48 | if (width <= that.options.minWidth && height <= that.options.minHeight) {
|
49 | conditionCardView(that);
|
50 | } else if (width > that.options.minWidth && height > that.options.minHeight) {
|
51 | conditionFullView(that);
|
52 | }
|
53 | } else {
|
54 | if (width <= that.options.minWidth) {
|
55 | conditionCardView(that);
|
56 | } else if (width > that.options.minWidth) {
|
57 | conditionFullView(that);
|
58 | }
|
59 | }
|
60 |
|
61 | resetView(that);
|
62 | };
|
63 |
|
64 | var conditionCardView = function conditionCardView(that) {
|
65 | changeTableView(that, false);
|
66 | showHideColumns(that, false);
|
67 | };
|
68 |
|
69 | var conditionFullView = function conditionFullView(that) {
|
70 | changeTableView(that, true);
|
71 | showHideColumns(that, true);
|
72 | };
|
73 |
|
74 | var changeTableView = function changeTableView(that, cardViewState) {
|
75 | that.options.cardView = cardViewState;
|
76 | that.toggleView();
|
77 | };
|
78 |
|
79 | var debounce = function debounce(func, wait) {
|
80 | var timeout;
|
81 | return function () {
|
82 | var context = this,
|
83 | args = arguments;
|
84 | var later = function later() {
|
85 | timeout = null;
|
86 | func.apply(context, args);
|
87 | };
|
88 | clearTimeout(timeout);
|
89 | timeout = setTimeout(later, wait);
|
90 | };
|
91 | };
|
92 |
|
93 | $.extend($.fn.bootstrapTable.defaults, {
|
94 | mobileResponsive: false,
|
95 | minWidth: 562,
|
96 | minHeight: undefined,
|
97 | heightThreshold: 100,
|
98 | checkOnInit: true,
|
99 | columnsHidden: []
|
100 | });
|
101 |
|
102 | var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
103 | _init = BootstrapTable.prototype.init;
|
104 |
|
105 | BootstrapTable.prototype.init = function () {
|
106 | _init.apply(this, Array.prototype.slice.apply(arguments));
|
107 |
|
108 | if (!this.options.mobileResponsive) {
|
109 | return;
|
110 | }
|
111 |
|
112 | if (!this.options.minWidth) {
|
113 | return;
|
114 | }
|
115 |
|
116 | if (this.options.minWidth < 100 && this.options.resizable) {
|
117 | console.log("The minWidth when the resizable extension is active should be greater or equal than 100");
|
118 | this.options.minWidth = 100;
|
119 | }
|
120 |
|
121 | var that = this,
|
122 | old = {
|
123 | width: $(window).width(),
|
124 | height: $(window).height()
|
125 | };
|
126 |
|
127 | $(window).on('resize orientationchange', debounce(function (evt) {
|
128 |
|
129 | var height = $(this).height(),
|
130 | width = $(this).width();
|
131 |
|
132 | if (Math.abs(old.height - height) > that.options.heightThreshold || old.width != width) {
|
133 | changeView(that, width, height);
|
134 | old = {
|
135 | width: width,
|
136 | height: height
|
137 | };
|
138 | }
|
139 | }, 200));
|
140 |
|
141 | if (this.options.checkOnInit) {
|
142 | var height = $(window).height(),
|
143 | width = $(window).width();
|
144 | changeView(this, width, height);
|
145 | old = {
|
146 | width: width,
|
147 | height: height
|
148 | };
|
149 | }
|
150 | };
|
151 | }(jQuery);
|
152 | }); |
\ | No newline at end of file |