fix: 修复 bootstrap-toggle 默认值问题

This commit is contained in:
Argo Zhang 2019-08-17 18:56:18 +08:00
parent 902afdfcdd
commit 833df4778e
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
2 changed files with 13 additions and 6 deletions

View File

@ -29,8 +29,7 @@
size: 'normal',
style: '',
width: null,
height: null,
defaultVal: ''
height: null
}
Toggle.prototype.defaults = function() {
@ -42,14 +41,11 @@
size: this.$element.attr('data-size') || Toggle.DEFAULTS.size,
style: this.$element.attr('data-style') || Toggle.DEFAULTS.style,
width: this.$element.attr('data-width') || Toggle.DEFAULTS.width,
height: this.$element.attr('data-height') || Toggle.DEFAULTS.height,
defaultVal: this.$element.attr('data-default-val') || Toggle.DEFAULTS.defaultVal,
height: this.$element.attr('data-height') || Toggle.DEFAULTS.height
}
}
Toggle.prototype.render = function () {
if(this.options.defaultVal === '') this.$element.prop('checked', true);
this._onstyle = 'btn-' + this.options.onstyle
this._offstyle = 'btn-' + this.options.offstyle
var size = this.options.size === 'large' ? 'btn-lg'

View File

@ -500,6 +500,17 @@
});
}
// extend bootstrap-toggle
if($.fn.bootstrapToggle) {
var toggle = $.fn.bootstrapToggle.Constructor;
var oldFunc = toggle.prototype.render;
toggle.prototype.render = function() {
var defaultVal = this.$element.attr('data-default-val') || '';
if(defaultVal === '') this.$element.prop('checked', true);
oldFunc.call(this);
}
}
if (window.NProgress) {
$(document).ajaxStart(function () {
return NProgress.start();