auto-use fragment for multi-element templates
This commit is contained in:
parent
d07e3bd87f
commit
4f0691431c
|
@ -88,20 +88,20 @@ Object.assign(t, {
|
|||
text.replace(t.RX_WORD_BREAK, '$&\u00AD');
|
||||
},
|
||||
|
||||
createTemplate(node) {
|
||||
const frag = 'fragment' in node.dataset;
|
||||
const el = frag ? node.content : node.content.firstElementChild;
|
||||
t.NodeList(frag ? el.querySelectorAll('*') : el);
|
||||
t.template[node.dataset.id] = el;
|
||||
// Compress inter-tag whitespace to reduce DOM tree and avoid space between elements without flex
|
||||
createTemplate(el) {
|
||||
const {content} = el;
|
||||
const toRemove = [];
|
||||
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
||||
// Compress inter-tag whitespace to reduce DOM tree and avoid space between elements without flex
|
||||
const walker = document.createTreeWalker(content, NodeFilter.SHOW_TEXT);
|
||||
for (let n; (n = walker.nextNode());) {
|
||||
if (!/[\xA0\S]/.test(n.textContent)) { // allow \xA0 to keep
|
||||
if (!/[\xA0\S]/.test(n.textContent) || // allowing \xA0 so as to preserve
|
||||
n.nodeType === Node.COMMENT_NODE) {
|
||||
toRemove.push(n);
|
||||
}
|
||||
}
|
||||
toRemove.forEach(n => n.remove());
|
||||
t.NodeList(content.querySelectorAll('*'));
|
||||
t.template[el.dataset.id] = content.childNodes.length > 1 ? content : content.childNodes[0];
|
||||
},
|
||||
|
||||
createText(str) {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<link rel="stylesheet" href="options/onoffswitch.css">
|
||||
<link rel="stylesheet" href="options/options.css">
|
||||
|
||||
<template data-id="shortcutsFF" data-fragment>
|
||||
<template data-id="shortcutsFF">
|
||||
<p style="line-height: 1.5" i18n-text="shortcutsNoteFF"></p>
|
||||
<table style="margin: 0 auto">
|
||||
<tr>
|
||||
|
|
Loading…
Reference in New Issue
Block a user