2015-12-01 21:47:00 +03:00
|
|
|
//import Util from './util'
|
|
|
|
|
2015-12-05 23:00:40 +03:00
|
|
|
// Switch decorator, to be called after Input
|
|
|
|
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-05 23:00:40 +03:00
|
|
|
class Switch {
|
2015-12-01 21:47:00 +03:00
|
|
|
|
2015-12-05 00:00:57 +03:00
|
|
|
constructor(element, config) {
|
|
|
|
this.$element = $(element)
|
2015-12-01 21:47:00 +03:00
|
|
|
this.config = $.extend({}, Default, config)
|
|
|
|
|
2015-12-04 04:09:01 +03:00
|
|
|
this.$element.after(this.config.template)
|
2015-12-01 21:47:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dispose() {
|
2015-12-04 04:09:01 +03:00
|
|
|
$.removeData(this.$element, DATA_KEY)
|
|
|
|
this.$element = null
|
2015-12-01 21:47:00 +03:00
|
|
|
this.config = null
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// 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
|