1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define([], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory();
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory();
|
11 | global.bootstrapTableAutoRefresh = mod.exports;
|
12 | }
|
13 | })(this, function () {
|
14 | 'use strict';
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | (function ($) {
|
23 |
|
24 | 'use strict';
|
25 |
|
26 | $.extend($.fn.bootstrapTable.defaults, {
|
27 | autoRefresh: false,
|
28 | autoRefreshInterval: 60,
|
29 | autoRefreshSilent: true,
|
30 | autoRefreshStatus: true,
|
31 | autoRefreshFunction: null
|
32 | });
|
33 |
|
34 | $.extend($.fn.bootstrapTable.defaults.icons, {
|
35 | autoRefresh: $.fn.bootstrapTable.utils.bootstrapVersion === 4 ? 'fa-clock' : 'glyphicon-time icon-time'
|
36 | });
|
37 |
|
38 | $.extend($.fn.bootstrapTable.locales, {
|
39 | formatAutoRefresh: function formatAutoRefresh() {
|
40 | return 'Auto Refresh';
|
41 | }
|
42 | });
|
43 |
|
44 | $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
|
45 |
|
46 | var BootstrapTable = $.fn.bootstrapTable.Constructor;
|
47 | var _init = BootstrapTable.prototype.init;
|
48 | var _initToolbar = BootstrapTable.prototype.initToolbar;
|
49 | var sprintf = $.fn.bootstrapTable.utils.sprintf;
|
50 |
|
51 | BootstrapTable.prototype.init = function () {
|
52 | _init.apply(this, Array.prototype.slice.apply(arguments));
|
53 |
|
54 | if (this.options.autoRefresh && this.options.autoRefreshStatus) {
|
55 | var that = this;
|
56 | this.options.autoRefreshFunction = setInterval(function () {
|
57 | that.refresh({ silent: that.options.autoRefreshSilent });
|
58 | }, this.options.autoRefreshInterval * 1000);
|
59 | }
|
60 | };
|
61 |
|
62 | BootstrapTable.prototype.initToolbar = function () {
|
63 | _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
|
64 |
|
65 | if (this.options.autoRefresh) {
|
66 | var $btnGroup = this.$toolbar.find('>.btn-group');
|
67 | var $btnAutoRefresh = $btnGroup.find('.auto-refresh');
|
68 |
|
69 | if (!$btnAutoRefresh.length) {
|
70 | $btnAutoRefresh = $([sprintf('<button class="btn btn-default auto-refresh %s" ', this.options.autoRefreshStatus ? 'enabled' : ''), 'type="button" ', sprintf('title="%s">', this.options.formatAutoRefresh()), sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.autoRefresh), '</button>'].join('')).appendTo($btnGroup);
|
71 |
|
72 | $btnAutoRefresh.on('click', $.proxy(this.toggleAutoRefresh, this));
|
73 | }
|
74 | }
|
75 | };
|
76 |
|
77 | BootstrapTable.prototype.toggleAutoRefresh = function () {
|
78 | if (this.options.autoRefresh) {
|
79 | if (this.options.autoRefreshStatus) {
|
80 | clearInterval(this.options.autoRefreshFunction);
|
81 | this.$toolbar.find('>.btn-group').find('.auto-refresh').removeClass('enabled');
|
82 | } else {
|
83 | var that = this;
|
84 | this.options.autoRefreshFunction = setInterval(function () {
|
85 | that.refresh({ silent: that.options.autoRefreshSilent });
|
86 | }, this.options.autoRefreshInterval * 1000);
|
87 | this.$toolbar.find('>.btn-group').find('.auto-refresh').addClass('enabled');
|
88 | }
|
89 | this.options.autoRefreshStatus = !this.options.autoRefreshStatus;
|
90 | }
|
91 | };
|
92 | })(jQuery);
|
93 | }); |
\ | No newline at end of file |