2017-08-11 17:59:31 +03:00
|
|
|
import Util from "./util";
|
2016-01-26 21:12:48 +03:00
|
|
|
|
2017-08-11 17:59:31 +03:00
|
|
|
const Base = ($ => {
|
2016-01-26 21:12:48 +03:00
|
|
|
const ClassName = {
|
2017-08-11 17:59:31 +03:00
|
|
|
BMD_FORM_GROUP: "bmd-form-group",
|
|
|
|
IS_FILLED: "is-filled",
|
|
|
|
IS_FOCUSED: "is-focused"
|
|
|
|
};
|
2016-01-26 21:12:48 +03:00
|
|
|
|
|
|
|
const Selector = {
|
2016-03-28 19:13:18 +03:00
|
|
|
BMD_FORM_GROUP: `.${ClassName.BMD_FORM_GROUP}`
|
2017-08-11 17:59:31 +03:00
|
|
|
};
|
2016-01-26 21:12:48 +03:00
|
|
|
|
2017-08-11 17:59:31 +03:00
|
|
|
const Default = {};
|
2016-01-26 21:12:48 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* 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 = {}) {
|
2017-08-11 17:59:31 +03:00
|
|
|
this.$element = $element;
|
|
|
|
this.config = $.extend(true, {}, Default, config);
|
2016-01-26 21:12:48 +03:00
|
|
|
|
|
|
|
// set properties for use in the constructor initialization
|
|
|
|
for (let key in properties) {
|
2017-08-11 17:59:31 +03:00
|
|
|
this[key] = properties[key];
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose(dataKey) {
|
2017-08-11 17:59:31 +03:00
|
|
|
this.$element.data(dataKey, null);
|
|
|
|
this.$element = null;
|
|
|
|
this.config = null;
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// protected
|
|
|
|
|
|
|
|
addFormGroupFocus() {
|
2017-08-11 17:59:31 +03:00
|
|
|
if (!this.$element.prop("disabled")) {
|
|
|
|
this.$bmdFormGroup.addClass(ClassName.IS_FOCUSED);
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeFormGroupFocus() {
|
2017-08-11 17:59:31 +03:00
|
|
|
this.$bmdFormGroup.removeClass(ClassName.IS_FOCUSED);
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
removeIsFilled() {
|
2017-08-11 17:59:31 +03:00
|
|
|
this.$bmdFormGroup.removeClass(ClassName.IS_FILLED);
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
addIsFilled() {
|
2017-08-11 17:59:31 +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) {
|
2017-08-11 17:59:31 +03:00
|
|
|
let mfg = this.$element.closest(Selector.BMD_FORM_GROUP);
|
2016-01-26 21:12:48 +03:00
|
|
|
if (mfg.length === 0 && raiseError) {
|
2017-08-11 17:59:31 +03:00
|
|
|
$.error(
|
|
|
|
`Failed to find ${Selector.BMD_FORM_GROUP} for ${Util.describe(
|
|
|
|
this.$element
|
|
|
|
)}`
|
|
|
|
);
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
2017-08-11 17:59:31 +03:00
|
|
|
return mfg;
|
2016-01-26 21:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// private
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// static
|
|
|
|
}
|
|
|
|
|
2017-08-11 17:59:31 +03:00
|
|
|
return Base;
|
|
|
|
})(jQuery);
|
2016-01-26 21:12:48 +03:00
|
|
|
|
2017-08-11 17:59:31 +03:00
|
|
|
export default Base;
|