2015-12-01 21:47:00 +03:00
|
|
|
//import Util from './util'
|
|
|
|
|
2015-12-02 03:28:36 +03:00
|
|
|
// Togglebutton decorator, to be called after Input
|
2015-12-01 21:47:00 +03:00
|
|
|
const Togglebutton = (($) => {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Constants
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
const NAME = 'togglebutton'
|
|
|
|
const DATA_KEY = `mdb.${NAME}`
|
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
|
|
|
|
|
|
|
const Default = {
|
|
|
|
template: `<span class='toggle'></span>`
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Class Definition
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
class Togglebutton {
|
|
|
|
|
2015-12-04 04:09:01 +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) {
|
|
|
|
data = new Togglebutton(this, config)
|
|
|
|
$element.data(DATA_KEY, data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
$.fn[NAME] = Togglebutton._jQueryInterface
|
|
|
|
$.fn[NAME].Constructor = Togglebutton
|
|
|
|
$.fn[NAME].noConflict = () => {
|
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
|
|
return Togglebutton._jQueryInterface
|
|
|
|
}
|
|
|
|
|
|
|
|
return Togglebutton
|
|
|
|
|
|
|
|
})(jQuery)
|
|
|
|
|
|
|
|
export default Togglebutton
|