diff --git a/Gruntfile.js b/Gruntfile.js index 70def36a..dc3e7e38 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -100,12 +100,14 @@ module.exports = function (grunt) { modules: 'ignore' }, files: { + 'dist/js/babel/baseInput.js': 'js/src/baseInput.js', + 'dist/js/babel/baseToggle.js': 'js/src/baseToggle.js', 'dist/js/babel/util.js': 'js/src/util.js', 'dist/js/babel/ripples.js': 'js/src/ripples.js', 'dist/js/babel/autofill.js': 'js/src/autofill.js', - 'dist/js/babel/input.js': 'js/src/textInput.js', + 'dist/js/babel/textInput.js': 'js/src/textInput.js', 'dist/js/babel/checkbox.js': 'js/src/checkbox.js', - 'dist/js/babel/togglebutton.js': 'js/src/switch.js', + 'dist/js/babel/switch.js': 'js/src/switch.js', 'dist/js/babel/radio.js': 'js/src/radio.js', 'dist/js/babel/fileInput.js': 'js/src/fileInput.js', 'dist/js/babel/bootstrapMaterialDesign.js': 'js/src/bootstrapMaterialDesign.js', @@ -121,12 +123,14 @@ module.exports = function (grunt) { 'docs/assets/js/dist/application.js': 'docs/assets/js/src/application.js', // generate core so we have local debugging + 'docs/dist/js/babel/baseInput.js': 'js/src/baseInput.js', + 'docs/dist/js/babel/baseToggle.js': 'js/src/baseToggle.js', 'docs/dist/js/babel/util.js': 'js/src/util.js', 'docs/dist/js/babel/ripples.js': 'js/src/ripples.js', 'docs/dist/js/babel/autofill.js': 'js/src/autofill.js', - 'docs/dist/js/babel/input.js': 'js/src/textInput.js', + 'docs/dist/js/babel/textInput.js': 'js/src/textInput.js', 'docs/dist/js/babel/checkbox.js': 'js/src/checkbox.js', - 'docs/dist/js/babel/togglebutton.js': 'js/src/switch.js', + 'docs/dist/js/babel/switch.js': 'js/src/switch.js', 'docs/dist/js/babel/radio.js': 'js/src/radio.js', 'docs/dist/js/babel/fileInput.js': 'js/src/fileInput.js', 'docs/dist/js/babel/bootstrapMaterialDesign.js': 'js/src/bootstrapMaterialDesign.js', @@ -145,12 +149,14 @@ module.exports = function (grunt) { modules: 'umd' }, files: { + 'dist/js/umd/baseInput.js': 'js/src/baseInput.js', + 'dist/js/umd/baseToggle.js': 'js/src/baseToggle.js', 'dist/js/umd/util.js': 'js/src/util.js', 'dist/js/umd/ripples.js': 'js/src/ripples.js', 'dist/js/umd/autofill.js': 'js/src/autofill.js', - 'dist/js/umd/input.js': 'js/src/textInput.js', + 'dist/js/umd/textInput.js': 'js/src/textInput.js', 'dist/js/umd/checkbox.js': 'js/src/checkbox.js', - 'dist/js/umd/togglebutton.js': 'js/src/switch.js', + 'dist/js/umd/switch.js': 'js/src/switch.js', 'dist/js/umd/radio.js': 'js/src/radio.js', 'dist/js/umd/fileInput.js': 'js/src/fileInput.js', 'dist/js/umd/bootstrapMaterialDesign.js': 'js/src/bootstrapMaterialDesign.js', @@ -205,6 +211,8 @@ module.exports = function (grunt) { }, bootstrap: { src: [ + 'dist/js/babel/baseInput.js', + 'dist/js/babel/baseToggle.js', 'dist/js/babel/util.js', 'dist/js/babel/ripples.js', 'dist/js/babel/autofill.js', diff --git a/grunt/configBridge.json b/grunt/configBridge.json index 2f0bdd94..105e4ebf 100644 --- a/grunt/configBridge.json +++ b/grunt/configBridge.json @@ -10,14 +10,15 @@ "coreJs": [ "../dist/js/babel/baseInput.js", + "../dist/js/babel/baseToggle.js", "../dist/js/babel/autofill.js", "../dist/js/babel/bootstrapMaterialDesign.js", "../dist/js/babel/checkbox.js", "../dist/js/babel/fileInput.js", - "../dist/js/babel/input.js", + "../dist/js/babel/textInput.js", "../dist/js/babel/radio.js", "../dist/js/babel/ripples.js", - "../dist/js/babel/togglebutton.js", + "../dist/js/babel/switch.js", "../dist/js/babel/util.js" ] } diff --git a/js/src/baseInput.js b/js/src/baseInput.js index c8d61294..7d639c90 100644 --- a/js/src/baseInput.js +++ b/js/src/baseInput.js @@ -36,12 +36,12 @@ const BaseInput = (($) => { // Enforce no overlap between components to prevent side effects this._rejectInvalidComponentMatches() - // Enforce required classes for a consistent rendering - this._rejectWithoutRequiredClasses() - // Enforce expected structure (if any) this.rejectWithoutRequiredStructure() + // Enforce required classes for a consistent rendering + this._rejectWithoutRequiredClasses() + if(this.config.formGroup.autoCreate) { // Will create form-group if necessary this.autoCreateFormGroup() @@ -76,12 +76,12 @@ const BaseInput = (($) => { // implement } - addFormGroupFocus(formGroup) { - formGroup.addClass(ClassName.IS_FOCUSED) + addFormGroupFocus() { + this.$formGroup.addClass(ClassName.IS_FOCUSED) } - removeFormGroupFocus(formGroup) { - formGroup.removeClass(ClassName.IS_FOCUSED) + removeFormGroupFocus() { + this.$formGroup.removeClass(ClassName.IS_FOCUSED) } addHasError() { diff --git a/js/src/baseToggle.js b/js/src/baseToggle.js new file mode 100644 index 00000000..47c2cafe --- /dev/null +++ b/js/src/baseToggle.js @@ -0,0 +1,88 @@ +import BaseInput from './baseInput' +//import TextInput from './textInput' +//import FileInput from './fileInput' +//import Radio from './radio' +//import Switch from './switch' +import Util from './util' + +const BaseToggle = (($) => { + + /** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ + const Default = { + formGroup: { + autoCreate: true + } + } + + const Selector = { + LABEL: 'label' + } + + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ + class BaseToggle extends BaseInput { + + constructor(element, config, inputType, outerClass) { + super(element, Default, config) + this.$element.after(this.config.template) + // '.checkbox|switch|radio > label > input[type=checkbox|radio]' + // '.${this.outerClass} > label > input[type=${this.inputType}]' + this.inputType = inputType + this.outerClass = outerClass + } + + dispose() { + super.dispose(DATA_KEY) + } + + // ------------------------------------------------------------------------ + // protected + + // Demarcation element (e.g. first child of a form-group) + outerElement() { + // '.checkbox|switch|radio > label > input[type=checkbox|radio]' + // '.${this.outerClass} > label > input[type=${this.inputType}]' + return this.$element.parent().parent() + } + + rejectWithoutRequiredStructure() { + // '.checkbox|switch|radio > label > input[type=checkbox|radio]' + // '.${this.outerClass} > label > input[type=${this.inputType}]' + Util.assert(this.$element.parent().prop('tagName') === 'label', `${component} parent element should be