corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 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 if (this.options.minWidth < 100 && this.options.resizable) {
102 console.log("The minWidth when the resizable extension is active should be greater or equal than 100");
103 this.options.minWidth = 100;
104 }
105  
106 var that = this,
107 old = {
108 width: $(window).width(),
109 height: $(window).height()
110 };
111  
112 $(window).on('resize orientationchange',debounce(function (evt) {
113 // reset view if height has only changed by at least the threshold.
114 var height = $(this).height(),
115 width = $(this).width();
116  
117 if (Math.abs(old.height - height) > that.options.heightThreshold || old.width != width) {
118 changeView(that, width, height);
119 old = {
120 width: width,
121 height: height
122 };
123 }
124 },200));
125  
126 if (this.options.checkOnInit) {
127 var height = $(window).height(),
128 width = $(window).width();
129 changeView(this, width, height);
130 old = {
131 width: width,
132 height: height
133 };
134 }
135 };
136 }(jQuery);