Skip to content

Commit

Permalink
Format the auto-refresh code
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzhixin committed Dec 17, 2017
1 parent ef6ac2c commit 8cbdbad
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.btn.enabled {
background-color: #5bc0de;
background-color: #5bc0de;
}
124 changes: 62 additions & 62 deletions src/extensions/auto-refresh/bootstrap-table-auto-refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,79 @@

(function ($) {

'use strict';
'use strict';

$.extend($.fn.bootstrapTable.defaults, {
autoRefresh: false,
autoRefreshInterval: 60,
autoRefreshSilent: true,
autoRefreshStatus: true,
autoRefreshFunction: null
});
$.extend($.fn.bootstrapTable.defaults, {
autoRefresh: false,
autoRefreshInterval: 60,
autoRefreshSilent: true,
autoRefreshStatus: true,
autoRefreshFunction: null
});

$.extend($.fn.bootstrapTable.defaults.icons, {
autoRefresh: 'glyphicon-time icon-time'
});
$.extend($.fn.bootstrapTable.defaults.icons, {
autoRefresh: 'glyphicon-time icon-time'
});

$.extend($.fn.bootstrapTable.locales, {
formatAutoRefresh: function() {
return 'Auto Refresh';
}
});
$.extend($.fn.bootstrapTable.locales, {
formatAutoRefresh: function() {
return 'Auto Refresh';
}
});

$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);

var BootstrapTable = $.fn.bootstrapTable.Constructor;
var _init = BootstrapTable.prototype.init;
var _initToolbar = BootstrapTable.prototype.initToolbar;
var sprintf = $.fn.bootstrapTable.utils.sprintf;
var BootstrapTable = $.fn.bootstrapTable.Constructor;
var _init = BootstrapTable.prototype.init;
var _initToolbar = BootstrapTable.prototype.initToolbar;
var sprintf = $.fn.bootstrapTable.utils.sprintf;

BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));
BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));

if (this.options.autoRefresh && this.options.autoRefreshStatus) {
var that = this;
this.options.autoRefreshFunction = setInterval(function () {
that.refresh({silent: that.options.autoRefreshSilent});
}, this.options.autoRefreshInterval*1000);
}
};
if (this.options.autoRefresh && this.options.autoRefreshStatus) {
var that = this;
this.options.autoRefreshFunction = setInterval(function () {
that.refresh({silent: that.options.autoRefreshSilent});
}, this.options.autoRefreshInterval*1000);
}
};

BootstrapTable.prototype.initToolbar = function() {
_initToolbar.apply(this, Array.prototype.slice.apply(arguments));
BootstrapTable.prototype.initToolbar = function() {
_initToolbar.apply(this, Array.prototype.slice.apply(arguments));

if (this.options.autoRefresh) {
var $btnGroup = this.$toolbar.find('>.btn-group');
var $btnAutoRefresh = $btnGroup.find('.auto-refresh');
if (this.options.autoRefresh) {
var $btnGroup = this.$toolbar.find('>.btn-group');
var $btnAutoRefresh = $btnGroup.find('.auto-refresh');

if (!$btnAutoRefresh.length) {
$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);
if (!$btnAutoRefresh.length) {
$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);

$btnAutoRefresh.on('click', $.proxy(this.toggleAutoRefresh, this));
}
}
};
$btnAutoRefresh.on('click', $.proxy(this.toggleAutoRefresh, this));
}
}
};

BootstrapTable.prototype.toggleAutoRefresh = function() {
if (this.options.autoRefresh) {
if (this.options.autoRefreshStatus) {
clearInterval(this.options.autoRefreshFunction);
this.$toolbar.find('>.btn-group').find('.auto-refresh').removeClass('enabled');
} else {
var that = this;
this.options.autoRefreshFunction = setInterval(function () {
that.refresh({silent: that.options.autoRefreshSilent});
}, this.options.autoRefreshInterval*1000);
this.$toolbar.find('>.btn-group').find('.auto-refresh').addClass('enabled');
}
this.options.autoRefreshStatus = !this.options.autoRefreshStatus;
}
};
BootstrapTable.prototype.toggleAutoRefresh = function() {
if (this.options.autoRefresh) {
if (this.options.autoRefreshStatus) {
clearInterval(this.options.autoRefreshFunction);
this.$toolbar.find('>.btn-group').find('.auto-refresh').removeClass('enabled');
} else {
var that = this;
this.options.autoRefreshFunction = setInterval(function () {
that.refresh({silent: that.options.autoRefreshSilent});
}, this.options.autoRefreshInterval*1000);
this.$toolbar.find('>.btn-group').find('.auto-refresh').addClass('enabled');
}
this.options.autoRefreshStatus = !this.options.autoRefreshStatus;
}
};

})(jQuery);

0 comments on commit 8cbdbad

Please sign in to comment.