mirror of
https://github.com/mdbootstrap/mdb-ui-kit.git
synced 2025-03-11 07:15:48 +03:00
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
|
//import Util from './util'
|
||
|
|
||
|
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 {
|
||
|
|
||
|
constructor(element, config) {
|
||
|
this.element = element
|
||
|
this.config = $.extend({}, Default, config)
|
||
|
|
||
|
this.element.after(this.config.template)
|
||
|
}
|
||
|
|
||
|
dispose() {
|
||
|
$.removeData(this.element, DATA_KEY)
|
||
|
this.element = null
|
||
|
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
|