Commit 04eaed80 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Used underscore to template list children to utilize their simple escaped interpolation

parent a62ae94d
......@@ -2,10 +2,12 @@ const DATA_TRIGGER = 'data-dropdown-trigger';
const DATA_DROPDOWN = 'data-dropdown';
const SELECTED_CLASS = 'droplab-item-selected';
const ACTIVE_CLASS = 'droplab-item-active';
const TEMPLATE_REGEX = /\{\{(.+?)\}\}/g;
export {
DATA_TRIGGER,
DATA_DROPDOWN,
SELECTED_CLASS,
ACTIVE_CLASS,
TEMPLATE_REGEX,
};
......@@ -93,7 +93,7 @@ Object.assign(DropDown.prototype, {
},
renderChildren: function(data) {
var html = utils.t(this.templateString, data);
var html = utils.template(this.templateString, data);
var template = document.createElement('div');
template.innerHTML = html;
......
/* eslint-disable */
import { DATA_TRIGGER, DATA_DROPDOWN } from './constants';
import { template as _template } from 'underscore';
import { DATA_TRIGGER, DATA_DROPDOWN, TEMPLATE_REGEX } from './constants';
const utils = {
toCamelCase(attr) {
return this.camelize(attr.split('-').slice(1).join(' '));
},
t(s, d) {
for (const p in d) {
if (Object.prototype.hasOwnProperty.call(d, p)) {
s = s.replace(new RegExp(`{{${p}}}`, 'g'), d[p]);
}
}
return s;
template(templateString, data) {
const template = _template(templateString, {
escape: TEMPLATE_REGEX,
});
return template(data);
},
camelize(str) {
......
......@@ -63,7 +63,7 @@ require('./filtered_search_dropdown');
Object.assign({
icon: `fa-${icon}`,
hint,
tag: `<${tag}>`,
tag: `<${tag}>`,
}, type && { type }),
);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment