This commit is contained in:
Kevin Ross 2015-12-05 15:19:06 -06:00
parent c5282e7097
commit 6f0e41a486
6 changed files with 23 additions and 26 deletions

View File

@ -1,5 +1,3 @@
import Util from './util'
const BaseInput = (($) => {
const Default = {
@ -42,7 +40,7 @@ const BaseInput = (($) => {
// Enforce required classes for a consistent rendering
this._rejectWithoutRequiredClasses()
if(this.config.formGroup.autoCreate) {
if (this.config.formGroup.autoCreate) {
// Will create form-group if necessary
this.autoCreateFormGroup()
}
@ -64,7 +62,7 @@ const BaseInput = (($) => {
// ------------------------------------------------------------------------
// protected
rejectWithoutRequiredStructure(){
rejectWithoutRequiredStructure() {
// implement
}
@ -114,7 +112,7 @@ const BaseInput = (($) => {
// Demarcation element (e.g. first child of a form-group)
// Subclasses such as file inputs may have different structures
outerElement(){
outerElement() {
return this.$element
}
@ -122,7 +120,7 @@ const BaseInput = (($) => {
findFormGroup(raiseError = true) {
let fg = this.$element.closest(Selector.FORM_GROUP) // note that form-group may be grandparent in the case of an input-group
if (fg.length === 0 && raiseError) {
$.error(`Failed to find form-group for ${$element}`)
$.error(`Failed to find form-group for ${this.$element}`)
}
return fg
}
@ -138,15 +136,15 @@ const BaseInput = (($) => {
// ------------------------------------------------------------------------
// private
_rejectInvalidComponentMatches(){
for(let otherComponent in this.config.invalidComponentMatches){
otherComponent.rejectMatch(this.constructor.name, $element)
_rejectInvalidComponentMatches() {
for (let otherComponent in this.config.invalidComponentMatches) {
otherComponent.rejectMatch(this.constructor.name, this.$element)
}
}
_rejectWithoutRequiredClasses(){
for(let requiredClass in this.config.requiredClasses){
if(!$element.hasClass(requiredClass)){
_rejectWithoutRequiredClasses() {
for (let requiredClass in this.config.requiredClasses) {
if (!this.$element.hasClass(requiredClass)) {
$.error(`${this.constructor.name} elements require class: ${requiredClass}`)
}
}

View File

@ -38,10 +38,6 @@ const BaseToggle = (($) => {
this.outerClass = outerClass
}
dispose() {
super.dispose(DATA_KEY)
}
// ------------------------------------------------------------------------
// protected
@ -55,8 +51,8 @@ const BaseToggle = (($) => {
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 <label>.`)
Util.assert(this.outerElement().hasClass(this.outerClass), `${component} grandparent element should have class .${this.outerClass}.`)
Util.assert(this.$element.parent().prop('tagName') === 'label', `${this.constructor.name}'s ${this.$element} parent element should be <label>.`)
Util.assert(this.outerElement().hasClass(this.outerClass), `${this.constructor.name}'s ${this.$element} grandparent element should have class .${this.outerClass}.`)
}
// ------------------------------------------------------------------------

View File

@ -101,13 +101,13 @@ const BootstrapMaterialDesign = (($) => {
let selector = this._resolveSelector(componentConfig)
// instantiate component on selector elements with config
console.debug(`instantiating: ${component}`)
// console.debug(`instantiating: ${component}`)
$(selector)[component](componentConfig)
// add to arrive if present and enabled
if (document.arrive && this.config.arrive) {
$document.arrive(selector, (element) => { // eslint-disable-line no-loop-func
$($element)[component](componentConfig)
$(element)[component](componentConfig)
})
}
}

View File

@ -2,7 +2,6 @@ import BaseToggle from './baseToggle'
import TextInput from './textInput'
import FileInput from './fileInput'
import Radio from './radio'
import Switch from './switch'
import Util from './util'
const Checkbox = (($) => {
@ -21,10 +20,6 @@ const Checkbox = (($) => {
invalidComponentMatches: [FileInput, Radio, TextInput]
}
const Selector = {
LABEL: 'label'
}
/**
* ------------------------------------------------------------------------
* Class Definition
@ -36,6 +31,10 @@ const Checkbox = (($) => {
super(element, $.extend({}, Default, config), inputType, outerClass)
}
dispose() {
super.dispose(DATA_KEY)
}
static matches($element) {
// '.checkbox > label > input[type=checkbox]'
if ($element.attr('type') === 'checkbox') {

View File

@ -25,7 +25,7 @@ const FileInput = (($) => {
}
const ClassName = {
IS_FILEINPUT: 'is-fileinput',
IS_FILEINPUT: 'is-fileinput'
}
const Selector = {

View File

@ -33,6 +33,10 @@ const Radio = (($) => {
super(element, $.extend({}, Default, config), NAME, NAME)
}
dispose() {
super.dispose(DATA_KEY)
}
static matches($element) {
// '.radio > label > input[type=radio]'
if ($element.attr('type') === 'radio') {