resolved some issues with es6 classes, about to break input into discreet classes instead of sharing any handlers to prevent confusion

This commit is contained in:
Kevin Ross 2015-12-04 15:00:57 -06:00
parent 0bfeb61b69
commit 93f0402161
10 changed files with 25 additions and 24 deletions

View File

@ -20,8 +20,8 @@ const Autofill = (($) => {
*/
class Autofill {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
this._watchLoading()

View File

@ -84,12 +84,12 @@ const BootstrapMaterialDesign = (($) => {
*/
class BootstrapMaterialDesign {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
let $document = $(document)
for (let component in this.config.instantiation) {
for (let component of this.config.instantiation) {
// the component's config fragment is passed in directly, allowing users to override
let componentConfig = this.config[component]
@ -101,6 +101,7 @@ const BootstrapMaterialDesign = (($) => {
let selector = this._resolveSelector(componentConfig)
// instantiate component on selector elements with config
console.debug(`instantiating: ${component}`)
$(selector)[component](componentConfig)
// add to arrive if present and enabled

View File

@ -23,12 +23,12 @@ const Checkbox = (($) => {
*/
class Checkbox {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
this.$element.after(this.config.template)
this.$formGroup = Util.findFormGroup(this.$element)
this.$formGroup = Util.findFormGroup(this.$element, false)
this._bindEventListeners()
}

View File

@ -27,8 +27,8 @@ const FileInput = (($) => {
*/
class FileInput {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
this.$formGroup = Util.findFormGroup(this.$element)

View File

@ -41,8 +41,8 @@ const Input = (($) => {
*/
class Input {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
// Requires form-group standard markup (will add it if necessary)
@ -158,8 +158,8 @@ const Input = (($) => {
_findOrCreateFormGroup() {
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) {
this.$element.wrap(this.config.$formGroup.template)
if (fg === null || fg.length === 0) {
this.$element.wrap(this.config.formGroup.template)
fg = this.$element.closest(Selector.FORM_GROUP) // find node after attached (otherwise additional attachments don't work)
}
return fg

View File

@ -22,8 +22,8 @@ const Foo = (($) => {
*/
class Foo {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
}

View File

@ -23,8 +23,8 @@ const Radio = (($) => {
*/
class Radio {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
this.$element.after(this.config.template)

View File

@ -44,8 +44,8 @@ const Ripples = (($) => {
*/
class Ripples {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
// attach initial listener

View File

@ -23,8 +23,8 @@ const Togglebutton = (($) => {
*/
class Togglebutton {
constructor($element, config) {
this.$element = $element
constructor(element, config) {
this.$element = $(element)
this.config = $.extend({}, Default, config)
this.$element.after(this.config.template)

View File

@ -86,9 +86,9 @@ const Util = (($) => {
/**
Find expected form-group
*/
findFormGroup($element) {
findFormGroup($element, raiseError = true) {
let fg = $element.closest(Selector.FORM_GROUP) // note that form-group may be grandparent in the case of an input-group
if (fg.length === 0) {
if (fg.length === 0 && raiseError) {
$.error(`Failed to find form-group for ${$element}`)
}
return fg