2015-12-06 00:07:37 +03:00
|
|
|
import Checkbox from './checkbox'
|
2015-12-01 21:47:00 +03:00
|
|
|
|
2015-12-05 23:00:40 +03:00
|
|
|
const Switch = (($) => {
|
2015-12-01 21:47:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Constants
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2015-12-05 23:00:40 +03:00
|
|
|
const NAME = 'switch'
|
2015-12-01 21:47:00 +03:00
|
|
|
const DATA_KEY = `mdb.${NAME}`
|
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
|
|
|
|
|
|
|
const Default = {
|
2015-12-05 23:00:40 +03:00
|
|
|
template: `<span class='switch-decorator'></span>`
|
2015-12-01 21:47:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Class Definition
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2015-12-06 00:07:37 +03:00
|
|
|
class Switch extends Checkbox {
|
2015-12-01 21:47:00 +03:00
|
|
|
|
2015-12-05 00:00:57 +03:00
|
|
|
constructor(element, config) {
|
2015-12-06 00:07:37 +03:00
|
|
|
super(element, $.extend({}, Default, config), 'checkbox', NAME)
|
|
|
|
// selector: '.switch > label > input[type=checkbox]'
|
2015-12-01 21:47:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dispose() {
|
2015-12-06 00:07:37 +03:00
|
|
|
super.dispose(DATA_KEY)
|
2015-12-01 21:47:00 +03:00
|
|
|
}
|
|
|
|
|
2015-12-06 00:07:37 +03:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// protected
|
|
|
|
|
2015-12-01 21:47:00 +03:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// private
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// static
|
|
|
|
static _jQueryInterface(config) {
|
|
|
|
return this.each(function () {
|
|
|
|
let $element = $(this)
|
|
|
|
let data = $element.data(DATA_KEY)
|
|
|
|
|
|
|
|
if (!data) {
|
2015-12-05 23:00:40 +03:00
|
|
|
data = new Switch(this, config)
|
2015-12-01 21:47:00 +03:00
|
|
|
$element.data(DATA_KEY, data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2015-12-05 23:00:40 +03:00
|
|
|
$.fn[NAME] = Switch._jQueryInterface
|
|
|
|
$.fn[NAME].Constructor = Switch
|
2015-12-01 21:47:00 +03:00
|
|
|
$.fn[NAME].noConflict = () => {
|
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
2015-12-05 23:00:40 +03:00
|
|
|
return Switch._jQueryInterface
|
2015-12-01 21:47:00 +03:00
|
|
|
}
|
|
|
|
|
2015-12-05 23:00:40 +03:00
|
|
|
return Switch
|
2015-12-01 21:47:00 +03:00
|
|
|
|
|
|
|
})(jQuery)
|
|
|
|
|
2015-12-05 23:00:40 +03:00
|
|
|
export default Switch
|