corrade-nucleus-nucleons – Blame information for rev 24
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | /** |
2 | * @author: Dennis Hernández |
||
3 | * @webSite: http://djhvscf.github.io/Blog |
||
4 | * @version: v1.2.2 |
||
5 | * |
||
6 | * @update zhixin wen <wenzhixin2010@gmail.com> |
||
7 | */ |
||
8 | |||
9 | (function ($) { |
||
10 | 'use strict'; |
||
11 | |||
12 | var cookieIds = { |
||
13 | sortOrder: 'bs.table.sortOrder', |
||
14 | sortName: 'bs.table.sortName', |
||
15 | pageNumber: 'bs.table.pageNumber', |
||
16 | pageList: 'bs.table.pageList', |
||
17 | columns: 'bs.table.columns', |
||
18 | searchText: 'bs.table.searchText', |
||
19 | filterControl: 'bs.table.filterControl' |
||
20 | }; |
||
21 | |||
22 | var getCurrentHeader = function (that) { |
||
23 | var header = that.$header; |
||
24 | if (that.options.height) { |
||
25 | header = that.$tableHeader; |
||
26 | } |
||
27 | |||
28 | return header; |
||
29 | }; |
||
30 | |||
31 | var getCurrentSearchControls = function (that) { |
||
32 | var searchControls = 'select, input'; |
||
33 | if (that.options.height) { |
||
34 | searchControls = 'table select, table input'; |
||
35 | } |
||
36 | |||
37 | return searchControls; |
||
38 | }; |
||
39 | |||
40 | var cookieEnabled = function () { |
||
41 | return !!(navigator.cookieEnabled); |
||
42 | }; |
||
43 | |||
44 | var inArrayCookiesEnabled = function (cookieName, cookiesEnabled) { |
||
45 | var index = -1; |
||
46 | |||
47 | for (var i = 0; i < cookiesEnabled.length; i++) { |
||
48 | if (cookieName.toLowerCase() === cookiesEnabled[i].toLowerCase()) { |
||
49 | index = i; |
||
50 | break; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | return index; |
||
55 | }; |
||
56 | |||
57 | var setCookie = function (that, cookieName, cookieValue) { |
||
58 | if ((!that.options.cookie) || (!cookieEnabled()) || (that.options.cookieIdTable === '')) { |
||
59 | return; |
||
60 | } |
||
61 | |||
62 | if (inArrayCookiesEnabled(cookieName, that.options.cookiesEnabled) === -1) { |
||
63 | return; |
||
64 | } |
||
65 | |||
66 | cookieName = that.options.cookieIdTable + '.' + cookieName; |
||
67 | |||
68 | switch(that.options.cookieStorage) { |
||
69 | case 'cookieStorage': |
||
70 | document.cookie = [ |
||
71 | cookieName, '=', cookieValue, |
||
72 | '; expires=' + that.options.cookieExpire, |
||
73 | that.options.cookiePath ? '; path=' + that.options.cookiePath : '', |
||
74 | that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', |
||
75 | that.options.cookieSecure ? '; secure' : '' |
||
76 | ].join(''); |
||
77 | break; |
||
78 | case 'localStorage': |
||
79 | localStorage.setItem(cookieName, cookieValue); |
||
80 | break; |
||
81 | case 'sessionStorage': |
||
82 | sessionStorage.setItem(cookieName, cookieValue); |
||
83 | break; |
||
84 | default: |
||
85 | return false; |
||
86 | } |
||
87 | |||
88 | return true; |
||
89 | }; |
||
90 | |||
91 | var getCookie = function (that, tableName, cookieName) { |
||
92 | if (!cookieName) { |
||
93 | return null; |
||
94 | } |
||
95 | |||
96 | if (inArrayCookiesEnabled(cookieName, that.options.cookiesEnabled) === -1) { |
||
97 | return null; |
||
98 | } |
||
99 | |||
100 | cookieName = tableName + '.' + cookieName; |
||
101 | |||
102 | switch(that.options.cookieStorage) { |
||
103 | case 'cookieStorage': |
||
104 | return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null; |
||
105 | case 'localStorage': |
||
106 | return localStorage.getItem(cookieName); |
||
107 | case 'sessionStorage': |
||
108 | return sessionStorage.getItem(cookieName); |
||
109 | default: |
||
110 | return null; |
||
111 | } |
||
112 | }; |
||
113 | |||
114 | var deleteCookie = function (that, tableName, cookieName) { |
||
115 | cookieName = tableName + '.' + cookieName; |
||
116 | |||
117 | switch(that.options.cookieStorage) { |
||
118 | case 'cookieStorage': |
||
119 | document.cookie = [ |
||
120 | encodeURIComponent(cookieName), '=', |
||
121 | '; expires=Thu, 01 Jan 1970 00:00:00 GMT', |
||
122 | that.options.cookiePath ? '; path=' + that.options.cookiePath : '', |
||
123 | that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', |
||
124 | ].join(''); |
||
125 | break; |
||
126 | case 'localStorage': |
||
127 | localStorage.removeItem(cookieName); |
||
128 | break; |
||
129 | case 'sessionStorage': |
||
130 | sessionStorage.removeItem(cookieName); |
||
131 | break; |
||
132 | |||
133 | } |
||
134 | return true; |
||
135 | }; |
||
136 | |||
137 | var calculateExpiration = function(cookieExpire) { |
||
138 | var time = cookieExpire.replace(/[0-9]*/, ''); //s,mi,h,d,m,y |
||
139 | cookieExpire = cookieExpire.replace(/[A-Za-z]{1,2}}/, ''); //number |
||
140 | |||
141 | switch (time.toLowerCase()) { |
||
142 | case 's': |
||
143 | cookieExpire = +cookieExpire; |
||
144 | break; |
||
145 | case 'mi': |
||
146 | cookieExpire = cookieExpire * 60; |
||
147 | break; |
||
148 | case 'h': |
||
149 | cookieExpire = cookieExpire * 60 * 60; |
||
150 | break; |
||
151 | case 'd': |
||
152 | cookieExpire = cookieExpire * 24 * 60 * 60; |
||
153 | break; |
||
154 | case 'm': |
||
155 | cookieExpire = cookieExpire * 30 * 24 * 60 * 60; |
||
156 | break; |
||
157 | case 'y': |
||
158 | cookieExpire = cookieExpire * 365 * 24 * 60 * 60; |
||
159 | break; |
||
160 | default: |
||
161 | cookieExpire = undefined; |
||
162 | break; |
||
163 | } |
||
164 | |||
165 | return cookieExpire === undefined ? '' : '; max-age=' + cookieExpire; |
||
166 | }; |
||
167 | |||
168 | var initCookieFilters = function (bootstrapTable) { |
||
169 | setTimeout(function () { |
||
170 | var parsedCookieFilters = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl)); |
||
171 | |||
172 | if (!bootstrapTable.options.filterControlValuesLoaded && parsedCookieFilters) { |
||
173 | bootstrapTable.options.filterControlValuesLoaded = true; |
||
174 | |||
175 | var cachedFilters = {}, |
||
176 | header = getCurrentHeader(bootstrapTable), |
||
177 | searchControls = getCurrentSearchControls(bootstrapTable), |
||
178 | |||
179 | applyCookieFilters = function (element, filteredCookies) { |
||
180 | $(filteredCookies).each(function (i, cookie) { |
||
181 | $(element).val(cookie.text); |
||
182 | cachedFilters[cookie.field] = cookie.text; |
||
183 | }); |
||
184 | }; |
||
185 | |||
186 | header.find(searchControls).each(function () { |
||
187 | var field = $(this).closest('[data-field]').data('field'), |
||
188 | filteredCookies = $.grep(parsedCookieFilters, function (cookie) { |
||
189 | return cookie.field === field; |
||
190 | }); |
||
191 | |||
192 | applyCookieFilters(this, filteredCookies); |
||
193 | }); |
||
194 | |||
195 | bootstrapTable.initColumnSearch(cachedFilters); |
||
196 | } |
||
197 | }, 250); |
||
198 | }; |
||
199 | |||
200 | $.extend($.fn.bootstrapTable.defaults, { |
||
201 | cookie: false, |
||
202 | cookieExpire: '2h', |
||
203 | cookiePath: null, |
||
204 | cookieDomain: null, |
||
205 | cookieSecure: null, |
||
206 | cookieIdTable: '', |
||
207 | cookiesEnabled: [ |
||
208 | 'bs.table.sortOrder', 'bs.table.sortName', |
||
209 | 'bs.table.pageNumber', 'bs.table.pageList', |
||
210 | 'bs.table.columns', 'bs.table.searchText', |
||
211 | 'bs.table.filterControl' |
||
212 | ], |
||
213 | cookieStorage: 'cookieStorage', //localStorage, sessionStorage |
||
214 | //internal variable |
||
215 | filterControls: [], |
||
216 | filterControlValuesLoaded: false |
||
217 | }); |
||
218 | |||
219 | $.fn.bootstrapTable.methods.push('getCookies'); |
||
220 | $.fn.bootstrapTable.methods.push('deleteCookie'); |
||
221 | |||
222 | $.extend($.fn.bootstrapTable.utils, { |
||
223 | setCookie: setCookie, |
||
224 | getCookie: getCookie |
||
225 | }); |
||
226 | |||
227 | var BootstrapTable = $.fn.bootstrapTable.Constructor, |
||
228 | _init = BootstrapTable.prototype.init, |
||
229 | _initTable = BootstrapTable.prototype.initTable, |
||
230 | _initServer = BootstrapTable.prototype.initServer, |
||
231 | _onSort = BootstrapTable.prototype.onSort, |
||
232 | _onPageNumber = BootstrapTable.prototype.onPageNumber, |
||
233 | _onPageListChange = BootstrapTable.prototype.onPageListChange, |
||
234 | _onPageFirst = BootstrapTable.prototype.onPageFirst, |
||
235 | _onPagePre = BootstrapTable.prototype.onPagePre, |
||
236 | _onPageNext = BootstrapTable.prototype.onPageNext, |
||
237 | _onPageLast = BootstrapTable.prototype.onPageLast, |
||
238 | _toggleColumn = BootstrapTable.prototype.toggleColumn, |
||
239 | _selectPage = BootstrapTable.prototype.selectPage, |
||
240 | _onSearch = BootstrapTable.prototype.onSearch; |
||
241 | |||
242 | BootstrapTable.prototype.init = function () { |
||
243 | var timeoutId = 0; |
||
244 | this.options.filterControls = []; |
||
245 | this.options.filterControlValuesLoaded = false; |
||
246 | |||
247 | this.options.cookiesEnabled = typeof this.options.cookiesEnabled === 'string' ? |
||
248 | this.options.cookiesEnabled.replace('[', '').replace(']', '') |
||
249 | .replace(/ /g, '').toLowerCase().split(',') : |
||
250 | this.options.cookiesEnabled; |
||
251 | |||
252 | if (this.options.filterControl) { |
||
253 | var that = this; |
||
254 | this.$el.on('column-search.bs.table', function (e, field, text) { |
||
255 | var isNewField = true; |
||
256 | |||
257 | for (var i = 0; i < that.options.filterControls.length; i++) { |
||
258 | if (that.options.filterControls[i].field === field) { |
||
259 | that.options.filterControls[i].text = text; |
||
260 | isNewField = false; |
||
261 | break; |
||
262 | } |
||
263 | } |
||
264 | if (isNewField) { |
||
265 | that.options.filterControls.push({ |
||
266 | field: field, |
||
267 | text: text |
||
268 | }); |
||
269 | } |
||
270 | |||
271 | setCookie(that, cookieIds.filterControl, JSON.stringify(that.options.filterControls)); |
||
272 | }).on('post-body.bs.table', initCookieFilters(that)); |
||
273 | } |
||
274 | _init.apply(this, Array.prototype.slice.apply(arguments)); |
||
275 | }; |
||
276 | |||
277 | BootstrapTable.prototype.initServer = function () { |
||
278 | var bootstrapTable = this, |
||
279 | selectsWithoutDefaults = [], |
||
280 | |||
281 | columnHasSelectControl = function (column) { |
||
282 | return column.filterControl && column.filterControl === 'select'; |
||
283 | }, |
||
284 | |||
285 | columnHasDefaultSelectValues = function (column) { |
||
286 | return column.filterData && column.filterData !== 'column'; |
||
287 | }, |
||
288 | |||
289 | cookiesPresent = function() { |
||
290 | var cookie = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl)); |
||
291 | return bootstrapTable.options.cookie && cookie; |
||
292 | }; |
||
293 | |||
294 | selectsWithoutDefaults = $.grep(bootstrapTable.columns, function(column) { |
||
295 | return columnHasSelectControl(column) && !columnHasDefaultSelectValues(column); |
||
296 | }); |
||
297 | |||
298 | // reset variable to original initServer function, so that future calls to initServer |
||
299 | // use the original function from this point on. |
||
300 | BootstrapTable.prototype.initServer = _initServer; |
||
301 | |||
302 | // early return if we don't need to populate any select values with cookie values |
||
303 | if (this.options.filterControl && cookiesPresent() && selectsWithoutDefaults.length === 0) { |
||
304 | return; |
||
305 | } |
||
306 | |||
307 | // call BootstrapTable.prototype.initServer |
||
308 | _initServer.apply(this, Array.prototype.slice.apply(arguments)); |
||
309 | }; |
||
310 | |||
311 | |||
312 | BootstrapTable.prototype.initTable = function () { |
||
313 | _initTable.apply(this, Array.prototype.slice.apply(arguments)); |
||
314 | this.initCookie(); |
||
315 | }; |
||
316 | |||
317 | BootstrapTable.prototype.initCookie = function () { |
||
318 | if (!this.options.cookie) { |
||
319 | return; |
||
320 | } |
||
321 | |||
322 | if ((this.options.cookieIdTable === '') || (this.options.cookieExpire === '') || (!cookieEnabled())) { |
||
323 | throw new Error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies"); |
||
324 | } |
||
325 | |||
326 | var sortOrderCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortOrder), |
||
327 | sortOrderNameCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortName), |
||
328 | pageNumberCookie = getCookie(this, this.options.cookieIdTable, cookieIds.pageNumber), |
||
329 | pageListCookie = getCookie(this, this.options.cookieIdTable, cookieIds.pageList), |
||
330 | columnsCookie = JSON.parse(getCookie(this, this.options.cookieIdTable, cookieIds.columns)), |
||
331 | searchTextCookie = getCookie(this, this.options.cookieIdTable, cookieIds.searchText); |
||
332 | |||
333 | //sortOrder |
||
334 | this.options.sortOrder = sortOrderCookie ? sortOrderCookie : this.options.sortOrder; |
||
335 | //sortName |
||
336 | this.options.sortName = sortOrderNameCookie ? sortOrderNameCookie : this.options.sortName; |
||
337 | //pageNumber |
||
338 | this.options.pageNumber = pageNumberCookie ? +pageNumberCookie : this.options.pageNumber; |
||
339 | //pageSize |
||
340 | this.options.pageSize = pageListCookie ? pageListCookie === this.options.formatAllRows() ? pageListCookie : +pageListCookie : this.options.pageSize; |
||
341 | //searchText |
||
342 | this.options.searchText = searchTextCookie ? searchTextCookie : ''; |
||
343 | |||
344 | if (columnsCookie) { |
||
345 | $.each(this.columns, function (i, column) { |
||
346 | column.visible = $.inArray(column.field, columnsCookie) !== -1; |
||
347 | }); |
||
348 | } |
||
349 | }; |
||
350 | |||
351 | BootstrapTable.prototype.onSort = function () { |
||
352 | _onSort.apply(this, Array.prototype.slice.apply(arguments)); |
||
353 | setCookie(this, cookieIds.sortOrder, this.options.sortOrder); |
||
354 | setCookie(this, cookieIds.sortName, this.options.sortName); |
||
355 | }; |
||
356 | |||
357 | BootstrapTable.prototype.onPageNumber = function () { |
||
358 | _onPageNumber.apply(this, Array.prototype.slice.apply(arguments)); |
||
359 | setCookie(this, cookieIds.pageNumber, this.options.pageNumber); |
||
360 | }; |
||
361 | |||
362 | BootstrapTable.prototype.onPageListChange = function () { |
||
363 | _onPageListChange.apply(this, Array.prototype.slice.apply(arguments)); |
||
364 | setCookie(this, cookieIds.pageList, this.options.pageSize); |
||
365 | }; |
||
366 | |||
367 | BootstrapTable.prototype.onPageFirst = function () { |
||
368 | _onPageFirst.apply(this, Array.prototype.slice.apply(arguments)); |
||
369 | setCookie(this, cookieIds.pageNumber, this.options.pageNumber); |
||
370 | }; |
||
371 | |||
372 | BootstrapTable.prototype.onPagePre = function () { |
||
373 | _onPagePre.apply(this, Array.prototype.slice.apply(arguments)); |
||
374 | setCookie(this, cookieIds.pageNumber, this.options.pageNumber); |
||
375 | }; |
||
376 | |||
377 | BootstrapTable.prototype.onPageNext = function () { |
||
378 | _onPageNext.apply(this, Array.prototype.slice.apply(arguments)); |
||
379 | setCookie(this, cookieIds.pageNumber, this.options.pageNumber); |
||
380 | }; |
||
381 | |||
382 | BootstrapTable.prototype.onPageLast = function () { |
||
383 | _onPageLast.apply(this, Array.prototype.slice.apply(arguments)); |
||
384 | setCookie(this, cookieIds.pageNumber, this.options.pageNumber); |
||
385 | }; |
||
386 | |||
387 | BootstrapTable.prototype.toggleColumn = function () { |
||
388 | _toggleColumn.apply(this, Array.prototype.slice.apply(arguments)); |
||
389 | |||
390 | var visibleColumns = []; |
||
391 | |||
392 | $.each(this.columns, function (i, column) { |
||
393 | if (column.visible) { |
||
394 | visibleColumns.push(column.field); |
||
395 | } |
||
396 | }); |
||
397 | |||
398 | setCookie(this, cookieIds.columns, JSON.stringify(visibleColumns)); |
||
399 | }; |
||
400 | |||
401 | BootstrapTable.prototype.selectPage = function (page) { |
||
402 | _selectPage.apply(this, Array.prototype.slice.apply(arguments)); |
||
403 | setCookie(this, cookieIds.pageNumber, page); |
||
404 | }; |
||
405 | |||
406 | BootstrapTable.prototype.onSearch = function () { |
||
407 | var target = Array.prototype.slice.apply(arguments); |
||
408 | _onSearch.apply(this, target); |
||
409 | |||
410 | if ($(target[0].currentTarget).parent().hasClass('search')) { |
||
411 | setCookie(this, cookieIds.searchText, this.searchText); |
||
412 | } |
||
413 | }; |
||
414 | |||
415 | BootstrapTable.prototype.getCookies = function () { |
||
416 | var bootstrapTable = this; |
||
417 | var cookies = {}; |
||
418 | $.each(cookieIds, function(key, value) { |
||
419 | cookies[key] = getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, value); |
||
420 | if (key === 'columns') { |
||
421 | cookies[key] = JSON.parse(cookies[key]); |
||
422 | } |
||
423 | }); |
||
424 | return cookies; |
||
425 | }; |
||
426 | |||
427 | BootstrapTable.prototype.deleteCookie = function (cookieName) { |
||
428 | if ((cookieName === '') || (!cookieEnabled())) { |
||
429 | return; |
||
430 | } |
||
431 | |||
432 | deleteCookie(this, this.options.cookieIdTable, cookieIds[cookieName]); |
||
433 | }; |
||
434 | })(jQuery); |