2017-04-07 13:57:03 +00:00
|
|
|
/* eslint-disable */
|
|
|
|
|
2020-04-02 21:07:51 +00:00
|
|
|
import { template as _template } from 'lodash';
|
2017-04-12 07:11:12 +00:00
|
|
|
import { DATA_TRIGGER, DATA_DROPDOWN, TEMPLATE_REGEX } from './constants';
|
2017-04-07 13:57:03 +00:00
|
|
|
|
|
|
|
const utils = {
|
|
|
|
toCamelCase(attr) {
|
2020-12-23 12:10:26 +00:00
|
|
|
return this.camelize(attr.split('-').slice(1).join(' '));
|
2017-04-07 13:57:03 +00:00
|
|
|
},
|
|
|
|
|
2017-04-12 07:11:12 +00:00
|
|
|
template(templateString, data) {
|
|
|
|
const template = _template(templateString, {
|
|
|
|
escape: TEMPLATE_REGEX,
|
|
|
|
});
|
|
|
|
|
|
|
|
return template(data);
|
2017-04-07 13:57:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
camelize(str) {
|
2018-10-10 06:15:56 +00:00
|
|
|
return str
|
|
|
|
.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
|
|
|
|
return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
|
|
|
|
})
|
|
|
|
.replace(/\s+/g, '');
|
2017-04-07 13:57:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
closest(thisTag, stopTag) {
|
|
|
|
while (thisTag && thisTag.tagName !== stopTag && thisTag.tagName !== 'HTML') {
|
|
|
|
thisTag = thisTag.parentNode;
|
|
|
|
}
|
|
|
|
return thisTag;
|
|
|
|
},
|
|
|
|
|
|
|
|
isDropDownParts(target) {
|
2017-10-12 10:20:33 +00:00
|
|
|
if (!target || !target.hasAttribute || target.tagName === 'HTML') return false;
|
2017-04-07 13:57:03 +00:00
|
|
|
return target.hasAttribute(DATA_TRIGGER) || target.hasAttribute(DATA_DROPDOWN);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default utils;
|