Blame view

src/main/resources/static/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js 2.61 KB
tangying authored
1
/**
2
3
4
 * 基于bootstrap-table-mobile修改
 * 修正部分iPhone手机不显示卡片视图
 * Copyright (c) 2019 ruoyi
tangying authored
5
6
 */
!function ($) {
7
    
tangying authored
8
    'use strict';
9
    
tangying authored
10
11
    var resetView = function (that) {
        if (that.options.height || that.options.showFooter) {
12
            setTimeout(that.resetView(), 1);
tangying authored
13
14
        }
    };
15
16
17
18
19
20
    
    // 判断是否 iphone
    var isIPhone = function () {
	    var browserName = navigator.userAgent.toLowerCase();
	    return /(iPhone|iPad|iPod|iOS)/i.test(browserName);
	};
tangying authored
21
22
23

    var changeView = function (that, width, height) {
        if (that.options.minHeight) {
24
            if (checkValuesLessEqual(width, that.options.minWidth) && checkValuesLessEqual(height, that.options.minHeight)) {
tangying authored
25
                conditionCardView(that);
26
            } else if (checkValuesGreater(width, that.options.minWidth) && checkValuesGreater(height, that.options.minHeight)) {
tangying authored
27
28
29
                conditionFullView(that);
            }
        } else {
30
            if (checkValuesLessEqual(width, that.options.minWidth) || isIPhone()) {
tangying authored
31
                conditionCardView(that);
32
            } else if (checkValuesGreater(width, that.options.minWidth)) {
tangying authored
33
34
35
36
37
38
39
                conditionFullView(that);
            }
        }

        resetView(that);
    };
40
41
42
43
44
45
46
47
    var checkValuesLessEqual = function (currentValue, targetValue) {
        return currentValue <= targetValue;
    };

    var checkValuesGreater = function (currentValue, targetValue) {
        return currentValue > targetValue;
    };
tangying authored
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    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,
66
        toggled: false
tangying authored
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    });

    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;
        }
83
84
85
86
        var that = this;
        $(window).resize(function () {
            changeView(that, $(this).width(), $(this).height())
        });
tangying authored
87
88

        if (this.options.checkOnInit) {
89
            changeView(this, $(window).width(), $(window).height());
tangying authored
90
91
92
        }
    };
}(jQuery);