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'; ...@@ -2,10 +2,12 @@ const DATA_TRIGGER = 'data-dropdown-trigger';
const DATA_DROPDOWN = 'data-dropdown'; const DATA_DROPDOWN = 'data-dropdown';
const SELECTED_CLASS = 'droplab-item-selected'; const SELECTED_CLASS = 'droplab-item-selected';
const ACTIVE_CLASS = 'droplab-item-active'; const ACTIVE_CLASS = 'droplab-item-active';
const TEMPLATE_REGEX = /\{\{(.+?)\}\}/g;
export { export {
DATA_TRIGGER, DATA_TRIGGER,
DATA_DROPDOWN, DATA_DROPDOWN,
SELECTED_CLASS, SELECTED_CLASS,
ACTIVE_CLASS, ACTIVE_CLASS,
TEMPLATE_REGEX,
}; };
...@@ -93,7 +93,7 @@ Object.assign(DropDown.prototype, { ...@@ -93,7 +93,7 @@ Object.assign(DropDown.prototype, {
}, },
renderChildren: function(data) { renderChildren: function(data) {
var html = utils.t(this.templateString, data); var html = utils.template(this.templateString, data);
var template = document.createElement('div'); var template = document.createElement('div');
template.innerHTML = html; template.innerHTML = html;
......
/* eslint-disable */ /* 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 = { const utils = {
toCamelCase(attr) { toCamelCase(attr) {
return this.camelize(attr.split('-').slice(1).join(' ')); return this.camelize(attr.split('-').slice(1).join(' '));
}, },
t(s, d) { template(templateString, data) {
for (const p in d) { const template = _template(templateString, {
if (Object.prototype.hasOwnProperty.call(d, p)) { escape: TEMPLATE_REGEX,
s = s.replace(new RegExp(`{{${p}}}`, 'g'), d[p]); });
}
} return template(data);
return s;
}, },
camelize(str) { camelize(str) {
......
...@@ -63,7 +63,7 @@ require('./filtered_search_dropdown'); ...@@ -63,7 +63,7 @@ require('./filtered_search_dropdown');
Object.assign({ Object.assign({
icon: `fa-${icon}`, icon: `fa-${icon}`,
hint, hint,
tag: `&lt;${tag}&gt;`, tag: `<${tag}>`,
}, type && { type }), }, 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