debian-mirror-gitlab/app/assets/javascripts/droplab/utils.js

46 lines
1 KiB
JavaScript
Raw Normal View History

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