Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
776 lars 1
/**
2
 * @author: Dennis Hernández
3
 * @webSite: http://djhvscf.github.io/Blog
4
 * @version: v1.1.0
5
 */
6
 
7
!function ($) {
8
 
9
    'use strict';
10
 
11
    var showHideColumns = function (that, checked) {
12
        if (that.options.columnsHidden.length > 0 ) {
13
            $.each(that.columns, function (i, column) {
14
                if (that.options.columnsHidden.indexOf(column.field) !== -1) {
15
                    if (column.visible !== checked) {
16
                        that.toggleColumn($.fn.bootstrapTable.utils.getFieldIndex(that.columns, column.field), checked, true);
17
                    }
18
                }
19
            });
20
        }
21
    };
22
 
23
    var resetView = function (that) {
24
        if (that.options.height || that.options.showFooter) {
25
            setTimeout(function(){
26
                that.resetView.call(that);
27
            }, 1);
28
        }
29
    };
30
 
31
    var changeView = function (that, width, height) {
32
        if (that.options.minHeight) {
33
            if ((width <= that.options.minWidth) && (height <= that.options.minHeight)) {
34
                conditionCardView(that);
35
            } else if ((width > that.options.minWidth) && (height > that.options.minHeight)) {
36
                conditionFullView(that);
37
            }
38
        } else {
39
            if (width <= that.options.minWidth) {
40
                conditionCardView(that);
41
            } else if (width > that.options.minWidth) {
42
                conditionFullView(that);
43
            }
44
        }
45
 
46
        resetView(that);
47
    };
48
 
49
    var conditionCardView = function (that) {
50
        changeTableView(that, false);
51
        showHideColumns(that, false);
52
    };
53
 
54
    var conditionFullView = function (that) {
55
        changeTableView(that, true);
56
        showHideColumns(that, true);
57
    };
58
 
59
    var changeTableView = function (that, cardViewState) {
60
        that.options.cardView = cardViewState;
61
        that.toggleView();
62
    };
63
 
64
    var debounce = function(func,wait) {
65
        var timeout;
66
        return function() {
67
            var context = this,
68
                args = arguments;
69
            var later = function() {
70
                timeout = null;
71
                func.apply(context,args);
72
            };
73
            clearTimeout(timeout);
74
            timeout = setTimeout(later, wait);
75
        };
76
    };
77
 
78
    $.extend($.fn.bootstrapTable.defaults, {
79
        mobileResponsive: false,
80
        minWidth: 562,
81
        minHeight: undefined,
82
        heightThreshold: 100, // just slightly larger than mobile chrome's auto-hiding toolbar
83
        checkOnInit: true,
84
        columnsHidden: []
85
    });
86
 
87
    var BootstrapTable = $.fn.bootstrapTable.Constructor,
88
        _init = BootstrapTable.prototype.init;
89
 
90
    BootstrapTable.prototype.init = function () {
91
        _init.apply(this, Array.prototype.slice.apply(arguments));
92
 
93
        if (!this.options.mobileResponsive) {
94
            return;
95
        }
96
 
97
        if (!this.options.minWidth) {
98
            return;
99
        }
100
 
101
        var that = this,
102
            old = {
103
                width: $(window).width(),
104
                height: $(window).height()
105
            };
106
 
107
        $(window).on('resize orientationchange',debounce(function (evt) {
108
            // reset view if height has only changed by at least the threshold.
109
            var height = $(this).height(),
110
                width = $(this).width();
111
 
112
            if (Math.abs(old.height - height) > that.options.heightThreshold || old.width != width) {
113
                changeView(that, width, height);
114
                old = {
115
                    width: width,
116
                    height: height
117
                };
118
            }
119
        },200));
120
 
121
        if (this.options.checkOnInit) {
122
            var height = $(window).height(),
123
                width = $(window).width();
124
            changeView(this, width, height);
125
            old = {
126
                width: width,
127
                height: height
128
            };
129
        }
130
    };
131
}(jQuery);