'use strict';
* @fileoverview
* Constants, utilities, and objects for DOM access.
*/
const STATE_KEY = {
LOAD_URL: 'load_url',
BEFORE_URL: 'before_url',
BYTE_UNIT: 'byteunit',
METHOD_COUNT: 'method_count',
MIN_SIZE: 'min_size',
GROUP_BY: 'group_by',
INCLUDE: 'include',
EXCLUDE: 'exclude',
TYPE: 'type',
FLAG_FILTER: 'flag_filter',
FOCUS: 'focus',
};
const dom = {
* Creates a document fragment from the given nodes.
* @param {Iterable<Node>} nodes
* @return {!DocumentFragment}
*/
createFragment(nodes) {
const fragment = document.createDocumentFragment();
for (const node of nodes)
fragment.appendChild(node);
return fragment;
},
* Removes all the existing children of `parent` and inserts `newChild` in
* their place.
* @param {!Element} parent
* @param {Node | null} newChild
*/
replace(parent, newChild) {
parent.innerHTML = '';
if (newChild)
parent.appendChild(newChild);
},
* Builds a text element in a single statement.
* @param {string} tagName Type of the element, such as "span".
* @param {string} text Text content for the element.
* @param {string} [className] Class to apply to the element.
*/
textElement(tagName, text, className) {
const element = document.createElement(tagName);
element.textContent = text;
if (className)
element.className = className;
return element;
},
* Schedule a one-time |task| call on next animation frame when |node| is
* added to the DOM, or if |node| is already in the DOM.
* @param {!Node} node
* @param {!function(): *} task
*/
onNodeAdded(node, task) {
if (document.contains(node)) {
requestAnimationFrame(task);
return;
}
let found = false;
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node.contains(node)) {
observer.disconnect();
found = true;
requestAnimationFrame(task);
return;
}
}
}
});
observer.observe(document, {subtree: true, childList: true});
},
};
class MainElements {
constructor() {
this.nlShowOptions =
(document.querySelectorAll('.toggle-options'));
this.divReviewInfo =
(this.query('#div-review-info'));
this.linkReviewText =
(this.query('#link-review-text'));
this.linkDownloadBefore =
(this.query('#link-download-before'));
this.linkDownloadLoad =
(this.query('#link-download-load'));
this.fileUpload =
(this.query('#file-upload'));
this.linkFaq =
(this.query('#link-faq'));
this.progAppbar =
(this.query('#prog-appbar'));
this.frmOptions =
(this.query('#frm-options'));
this.cbMethodCount =
(this.query('#cb-method-count'));
this.selByteUnit =
(this.query('#sel-byte-unit'));
this.nbMinSize =
(this.query('#nb-min-size'));
this.rnlGroupBy = (
this.frmOptions.elements.namedItem(STATE_KEY.GROUP_BY));
assert(this.rnlGroupBy.length > 0);
this.tbIncludeRegex =
(this.query('#tb-include-regex'));
this.tbExcludeRegex =
(this.query('#tb-exclude-regex'));
this.rnlType = (
this.frmOptions.elements.namedItem(STATE_KEY.TYPE));
assert(this.rnlType.length > 0);
this.fsTypesFilter =
(this.query('#fs-types-filter'));
this.btnTypeAll =
(this.query('#btn-type-all'));
this.btnTypeNone =
(this.query('#btn-type-none'));
this.rnlFlagFilter = (
this.frmOptions.elements.namedItem(STATE_KEY.FLAG_FILTER));
assert(this.rnlFlagFilter.length > 0);
this.divIcons =
(this.query('#div-icons'));
this.divDiffStatusIcons =
(this.query('#div-diff-status-icons'));
this.divMiscIcons =
(this.query('#div-misc-icons'));
this.tmplSymbolTreeGroup = (
this.query('#tmpl-symbol-tree-group'));
this.tmplSymbolTreeLeaf = (
this.query('#tmpl-symbol-tree-leaf'));
this.spanSizeHeader =
(this.query('#span-size-header'));
this.ulSymbolTree =
(this.query('#ul-symbol-tree'));
this.tmplMetricsTreeGroup = (
this.query('#tmpl-metrics-tree-group'));
this.tmplMetricsTreeLeaf = (
this.query('#tmpl-metrics-tree-leaf'));
this.divMetricsView =
(this.query('#div-metrics-view'));
this.ulMetricsTree =
(this.query('#ul-metrics-tree'));
this.divNoSymbolsMsg =
(this.query('#div-no-symbols-msg'));
* @type {!HTMLTemplateElement} Template for groups in the Metadata Tree.
*/
this.tmplMetadataTreeGroup = (
this.query('#tmpl-metadata-tree-group'));
* @type {!HTMLTemplateElement} Template for leaves in the Metadata Tree.
*/
this.tmplMetadataTreeLeaf = (
this.query('#tmpl-metadata-tree-leaf'));
this.divMetadataView =
(this.query('#div-metadata-view'));
this.ulMetadataTree =
(this.query('#ul-metadata-tree'));
this.divInfocardArtifact =
(this.query('#div-infocard-artifact'));
this.divInfocardSymbol =
(this.query('#div-infocard-symbol'));
this.divSigninModal =
(this.query('#div-signin-modal'));
this.divDisassemblyModal =
(this.query('#div-disassembly-modal'));
}
* @param {string} q Query string.
* @return {!Element}
* @private
*/
query(q) {
return (assertNotNull(document.querySelector(q)));
}
* @param {!Element} elt
* @return {!Element}
* @public
*/
getAriaDescribedBy(elt) {
const id = assertNotNull(elt.getAttribute('aria-describedby'));
return assertNotNull(document.getElementById(id));
}
}
const g_el = new MainElements();