bootstrap-table-mobile.js
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* 基于bootstrap-table-mobile修改
* 修正部分iPhone手机不显示卡片视图
* Copyright (c) 2019 ruoyi
*/
!function ($) {
'use strict';
var resetView = function (that) {
if (that.options.height || that.options.showFooter) {
setTimeout(that.resetView(), 1);
}
};
// 判断是否 iphone
var isIPhone = function () {
var browserName = navigator.userAgent.toLowerCase();
return /(iPhone|iPad|iPod|iOS)/i.test(browserName);
};
var changeView = function (that, width, height) {
if (that.options.minHeight) {
if (checkValuesLessEqual(width, that.options.minWidth) && checkValuesLessEqual(height, that.options.minHeight)) {
conditionCardView(that);
} else if (checkValuesGreater(width, that.options.minWidth) && checkValuesGreater(height, that.options.minHeight)) {
conditionFullView(that);
}
} else {
if (checkValuesLessEqual(width, that.options.minWidth) || isIPhone()) {
conditionCardView(that);
} else if (checkValuesGreater(width, that.options.minWidth)) {
conditionFullView(that);
}
}
resetView(that);
};
var checkValuesLessEqual = function (currentValue, targetValue) {
return currentValue <= targetValue;
};
var checkValuesGreater = function (currentValue, targetValue) {
return currentValue > targetValue;
};
var conditionCardView = function (that) {
changeTableView(that, false);
};
var conditionFullView = function (that) {
changeTableView(that, true);
};
var changeTableView = function (that, cardViewState) {
that.options.cardView = cardViewState;
that.toggleView();
};
$.extend($.fn.bootstrapTable.defaults, {
mobileResponsive: false,
minWidth: 562,
minHeight: undefined,
checkOnInit: true,
toggled: false
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_init = BootstrapTable.prototype.init;
BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.mobileResponsive) {
return;
}
if (!this.options.minWidth) {
return;
}
var that = this;
$(window).resize(function () {
changeView(that, $(this).width(), $(this).height())
});
if (this.options.checkOnInit) {
changeView(this, $(window).width(), $(window).height());
}
};
}(jQuery);