@travlrcom/uikit
Version:
TRAVLR UiKit
68 lines (56 loc) • 2.11 kB
JavaScript
/**
****************************************************
*** ******* ****** ****
*** ****** ****** *****
*********** ************** ****** ******
*********** ************* ****** *******
*********** ************ ****** ********
*********** *********** ****** *********
*********** ********** ****** **********
*********** ********* ****** ***********
*********** ******** ****** ************
*********** ******* ****** *************
*********** ****** ****** **************
****************************************************
* --------------------------------------------------
* Travlr UiKit: attributeHandler.js
* By Travlr Team
* --------------------------------------------------
*/
import ErrorMessageHandler from './errorMessageHandler'
// const
const NAME = 'attributeHandler'
const ErrorMessages = [
{
ERROR_ID: 0,
ERROR_MESSAGE: 'Config must be an object'
}
]
const ConfigErrorMessage = {
errorId: 0,
errorMessages: ErrorMessages
}
class AttributeHandler {
constructor (config) {
if (typeof config !== 'object') {
const ConfigError = Object.assign({}, ConfigErrorMessage, {
errorId: 0
})
new ErrorMessageHandler(ConfigError)
}
this._config = config
this._element = this._config.element ? this._config.element : null
this._attributeName = this._config.attributeName ? this._config.attributeName : null
this._attributeValue = this._config.attributeValue
}
getAttribute () {
return this._element !== null && this._attributeName !== null ? this._element.getAttribute(this._attributeName) : null
}
setAttribute () {
this._element !== null && this._attributeName !== null ? this._element.setAttribute(this._attributeName, this._attributeValue) : null
}
removeAttribute () {
this._element !== null && this._attributeName !== null ? this._element.removeAttribute(this._attributeName) : null
}
}
export default AttributeHandler