diff --git a/resources/templates/index.html b/resources/templates/index.html index 5e84d41..d67baba 100644 --- a/resources/templates/index.html +++ b/resources/templates/index.html @@ -142,7 +142,10 @@ .no-empty .empty { display: none; } - {{style}} + + .highlight { + background-color: lightyellow; + }
@@ -163,9 +166,6 @@ classList.add(classname); } } - window.option = function (value) { - toggleClass(document.getElementById('page'), value); - }; window.onload = function () { var COLLAPSE_CLASS = 'collapse'; document.getElementById('ast').addEventListener('click', function (e) { @@ -178,6 +178,26 @@ } }); }; + window.addEventListener('message', ({ data }) => { + if (!Array.isArray(data)) return; + const [action, message] = data; + switch(action) { + case 'SET_OPTION': + document.getElementById('page').className = message.join(' '); + break; + case 'HIGHLIGHT': { + const highlightClassName = 'highlight'; + Array.prototype.forEach.call( + document.getElementsByClassName(highlightClassName), + el => el.classList.remove(highlightClassName) + ); + message.forEach(line => + document.getElementsByClassName(`line-${line}`)[0].classList.add(highlightClassName) + ); + break; + } + } + });