gitlab-org--gitlab-foss/app/assets/javascripts/droplab/utils.js

39 lines
987 B
JavaScript
Raw Normal View History

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