mirror of
https://github.com/mdbootstrap/mdb-ui-kit.git
synced 2025-02-09 08:10:39 +03:00
migrated checkbox to es6
This commit is contained in:
parent
3c3bf7eb49
commit
d1fe1a06dd
|
@ -103,7 +103,7 @@ module.exports = function (grunt) {
|
||||||
'js/dist/util.js' : 'js/src/util.js',
|
'js/dist/util.js' : 'js/src/util.js',
|
||||||
'js/dist/ripples.js' : 'js/src/ripples.js',
|
'js/dist/ripples.js' : 'js/src/ripples.js',
|
||||||
'js/dist/autofill.js' : 'js/src/autofill.js',
|
'js/dist/autofill.js' : 'js/src/autofill.js',
|
||||||
//'js/dist/button.js' : 'js/src/button.js',
|
'js/dist/checkbox.js' : 'js/src/checkbox.js',
|
||||||
//'js/dist/carousel.js' : 'js/src/carousel.js',
|
//'js/dist/carousel.js' : 'js/src/carousel.js',
|
||||||
//'js/dist/collapse.js' : 'js/src/collapse.js',
|
//'js/dist/collapse.js' : 'js/src/collapse.js',
|
||||||
//'js/dist/dropdown.js' : 'js/src/dropdown.js',
|
//'js/dist/dropdown.js' : 'js/src/dropdown.js',
|
||||||
|
@ -130,7 +130,7 @@ module.exports = function (grunt) {
|
||||||
'dist/js/umd/util.js' : 'js/src/util.js',
|
'dist/js/umd/util.js' : 'js/src/util.js',
|
||||||
'dist/js/umd/ripples.js' : 'js/src/ripples.js',
|
'dist/js/umd/ripples.js' : 'js/src/ripples.js',
|
||||||
'dist/js/umd/autofill.js' : 'js/src/autofill.js',
|
'dist/js/umd/autofill.js' : 'js/src/autofill.js',
|
||||||
//'dist/js/umd/alert.js' : 'js/src/alert.js',
|
'dist/js/umd/checkbox.js' : 'js/src/checkbox.js',
|
||||||
//'dist/js/umd/button.js' : 'js/src/button.js',
|
//'dist/js/umd/button.js' : 'js/src/button.js',
|
||||||
//'dist/js/umd/carousel.js' : 'js/src/carousel.js',
|
//'dist/js/umd/carousel.js' : 'js/src/carousel.js',
|
||||||
//'dist/js/umd/collapse.js' : 'js/src/collapse.js',
|
//'dist/js/umd/collapse.js' : 'js/src/collapse.js',
|
||||||
|
@ -193,7 +193,7 @@ module.exports = function (grunt) {
|
||||||
'js/src/util.js',
|
'js/src/util.js',
|
||||||
'js/src/ripples.js',
|
'js/src/ripples.js',
|
||||||
'js/src/autofill.js',
|
'js/src/autofill.js',
|
||||||
//'js/src/button.js',
|
'js/src/checkbox.js',
|
||||||
//'js/src/carousel.js',
|
//'js/src/carousel.js',
|
||||||
//'js/src/collapse.js',
|
//'js/src/collapse.js',
|
||||||
//'js/src/dropdown.js',
|
//'js/src/dropdown.js',
|
||||||
|
|
73
js/src/checkbox.js
Normal file
73
js/src/checkbox.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
//import Util from './util'
|
||||||
|
|
||||||
|
const Checkbox = (($) => {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
* Constants
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
const NAME = 'checkbox'
|
||||||
|
const DATA_KEY = `mdb.${NAME}`
|
||||||
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
|
|
||||||
|
const Default = {
|
||||||
|
template: `<span class='checkbox-material'><span class='check'></span></span>`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
* Class Definition
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
class Checkbox {
|
||||||
|
|
||||||
|
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 Checkbox(this, config)
|
||||||
|
$element.data(DATA_KEY, data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
* jQuery
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
$.fn[NAME] = Checkbox._jQueryInterface
|
||||||
|
$.fn[NAME].Constructor = Checkbox
|
||||||
|
$.fn[NAME].noConflict = () => {
|
||||||
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
||||||
|
return Checkbox._jQueryInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
return Checkbox
|
||||||
|
|
||||||
|
})(jQuery)
|
||||||
|
|
||||||
|
export default Checkbox
|
|
@ -11,7 +11,9 @@ const Foo = (($) => {
|
||||||
const DATA_KEY = `mdb.${NAME}`
|
const DATA_KEY = `mdb.${NAME}`
|
||||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
|
|
||||||
const Default = {}
|
const Default = {
|
||||||
|
template: ``
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
|
|
|
@ -52,15 +52,14 @@
|
||||||
"togglebuttonElements": ".togglebutton > label > input[type=checkbox]",
|
"togglebuttonElements": ".togglebutton > label > input[type=checkbox]",
|
||||||
"radioElements": ".radio > label > input[type=radio]"
|
"radioElements": ".radio > label > input[type=radio]"
|
||||||
},
|
},
|
||||||
"checkbox": function(selector) {
|
//"checkbox": function(selector) {
|
||||||
// Add fake-checkbox to material checkboxes
|
// // Add fake-checkbox to material checkboxes
|
||||||
$((selector) ? selector : this.options.checkboxElements)
|
// $((selector) ? selector : this.options.checkboxElements)
|
||||||
.filter(":notmdproc")
|
// .filter(":notmdproc")
|
||||||
.data("mdproc", true)
|
// .data("mdproc", true)
|
||||||
.after("<span class='checkbox-material'><span class='check'></span></span>");
|
// .after("<span class='checkbox-material'><span class='check'></span></span>");
|
||||||
},
|
//},
|
||||||
"togglebutton": function(selector) {
|
"togglebutton": function(selector) {
|
||||||
// Add fake-checkbox to material checkboxes
|
|
||||||
$((selector) ? selector : this.options.togglebuttonElements)
|
$((selector) ? selector : this.options.togglebuttonElements)
|
||||||
.filter(":notmdproc")
|
.filter(":notmdproc")
|
||||||
.data("mdproc", true)
|
.data("mdproc", true)
|
||||||
|
@ -243,6 +242,7 @@
|
||||||
}
|
}
|
||||||
if (this.options.checkbox) {
|
if (this.options.checkbox) {
|
||||||
this.checkbox();
|
this.checkbox();
|
||||||
|
$(this.options.checkboxElements).checkbox()
|
||||||
}
|
}
|
||||||
if (this.options.togglebutton) {
|
if (this.options.togglebutton) {
|
||||||
this.togglebutton();
|
this.togglebutton();
|
||||||
|
@ -269,7 +269,7 @@
|
||||||
}
|
}
|
||||||
if (this.options.checkbox) {
|
if (this.options.checkbox) {
|
||||||
$document.arrive(this.options.checkboxElements, function() {
|
$document.arrive(this.options.checkboxElements, function() {
|
||||||
$.material.checkbox($(this));
|
$(this).checkbox();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.options.radio) {
|
if (this.options.radio) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user