//===-- HTMLLogger.js -----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Based on selected objects, hide/show sections & populate data from templates. // // For example, if the selection is {bb="BB4", elt="BB4.6" iter="BB4:2"}: // - show the "block" and "element" sections // - re-render templates within these sections (if selection changed) // - apply "bb-select" to items with class class "BB4", etc let selection = {}; function updateSelection(changes, data) { Object.assign(selection, changes); data = Object.create(data); data.selection = selection; for (root of document.querySelectorAll('[data-selection]')) updateSection(root, data); for (var k in changes) applyClassIf(k + '-select', classSelector(changes[k])); } // Given
: // - hide section if selections x or y are null // - re-render templates if x or y have changed function updateSection(root, data) { let changed = root.selection == null; root.selection ||= {}; for (key of root.dataset.selection.split(',')) { if (!key) continue; if (data.selection[key] != root.selection[key]) { root.selection[key] = data.selection[key]; changed = true; } if (data.selection[key] == null) { root.hidden = true; return; } } if (changed) { root.hidden = false; for (tmpl of root.getElementsByTagName('template')) reinflate(tmpl, data); } } // Expands template `tmpl` based on input `data`: // - interpolates {{expressions}} in text and attributes // -