2016-01-26 21:12:48 +03:00
|
|
|
import Util from './util'
|
|
|
|
|
|
|
|
const Base = (($) => {
|
|
|
|
|
|
|
|
const ClassName = {
|
2016-03-28 19:13:18 +03:00
|
|
|
BMD_FORM_GROUP: 'bmd-form-group',
|
2016-01-26 21:12:48 +03:00
|
|
|
IS_FILLED: 'is-filled',
|
|
|
|
IS_FOCUSED: 'is-focused'
|
|
|
|
}
|
|
|
|
|
|
|
|
const Selector = {
|
2016-03-28 19:13:18 +03:00
|
|
|
BMD_FORM_GROUP: `.${ClassName.BMD_FORM_GROUP}`
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Default = {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Class Definition
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
class Base {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param element
|
|
|
|
* @param config
|
|
|
|
* @param properties - anything that needs to be set as this[key] = value. Works around the need to call `super` before using `this`
|
|
|
|
*/
|
|
|
|
constructor($element, config, properties = {}) {
|
|
|
|
this.$element = $element
|
|
|
|
this.config = $.extend(true, {}, Default, config)
|
|
|
|
|
|
|
|
// set properties for use in the constructor initialization
|
|
|
|
for (let key in properties) {
|
|
|
|
this[key] = properties[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose(dataKey) {
|
2016-04-27 01:46:10 +03:00
|
|
|
this.$element.data(dataKey, null)
|
2016-01-26 21:12:48 +03:00
|
|
|
this.$element = null
|
|
|
|
this.config = null
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// protected
|
|
|
|
|
|
|
|
addFormGroupFocus() {
|
|
|
|
if (!this.$element.prop('disabled')) {
|
2016-03-28 23:18:19 +03:00
|
|
|
this.$bmdFormGroup.addClass(ClassName.IS_FOCUSED)
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeFormGroupFocus() {
|
2016-03-28 23:18:19 +03:00
|
|
|
this.$bmdFormGroup.removeClass(ClassName.IS_FOCUSED)
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
removeIsFilled() {
|
2016-03-28 23:18:19 +03:00
|
|
|
this.$bmdFormGroup.removeClass(ClassName.IS_FILLED)
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
addIsFilled() {
|
2016-03-28 23:18:19 +03:00
|
|
|
this.$bmdFormGroup.addClass(ClassName.IS_FILLED)
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
2016-03-21 17:56:51 +03:00
|
|
|
// Find bmd-form-group
|
2016-01-26 21:12:48 +03:00
|
|
|
findMdbFormGroup(raiseError = true) {
|
2016-03-28 19:13:18 +03:00
|
|
|
let mfg = this.$element.closest(Selector.BMD_FORM_GROUP)
|
2016-01-26 21:12:48 +03:00
|
|
|
if (mfg.length === 0 && raiseError) {
|
2016-03-28 19:13:18 +03:00
|
|
|
$.error(`Failed to find ${Selector.BMD_FORM_GROUP} for ${Util.describe(this.$element)}`)
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
return mfg
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// private
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// static
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Base
|
|
|
|
|
|
|
|
})(jQuery)
|
|
|
|
|
|
|
|
export default Base
|