diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2021-07-31 11:35:39 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2021-07-31 11:35:39 -0600 |
commit | f1998c321a4eec6d75b58d84aa8610971bf21979 (patch) | |
tree | a90783eb296cc50e1c48433f241624f26b99be27 /static/src/assets/viz/2/goog/dom | |
parent | 03a35dcc38b055f15df160bd300969e3b703d4b1 (diff) |
move static files into static sub-dir, refactor nix a bit
Diffstat (limited to 'static/src/assets/viz/2/goog/dom')
-rw-r--r-- | static/src/assets/viz/2/goog/dom/asserts.js | 311 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/browserfeature.js | 73 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/dom.js | 3233 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/htmlelement.js | 29 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/nodetype.js | 48 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/safe.js | 458 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/tagname.js | 562 | ||||
-rw-r--r-- | static/src/assets/viz/2/goog/dom/tags.js | 41 |
8 files changed, 4755 insertions, 0 deletions
diff --git a/static/src/assets/viz/2/goog/dom/asserts.js b/static/src/assets/viz/2/goog/dom/asserts.js new file mode 100644 index 0000000..a8f93ba --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/asserts.js @@ -0,0 +1,311 @@ +// Copyright 2017 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +goog.provide('goog.dom.asserts'); + +goog.require('goog.asserts'); + +/** + * @fileoverview Custom assertions to ensure that an element has the appropriate + * type. + * + * Using a goog.dom.safe wrapper on an object on the incorrect type (via an + * incorrect static type cast) can result in security bugs: For instance, + * g.d.s.setAnchorHref ensures that the URL assigned to the .href attribute + * satisfies the SafeUrl contract, i.e., is safe to dereference as a hyperlink. + * However, the value assigned to a HTMLLinkElement's .href property requires + * the stronger TrustedResourceUrl contract, since it can refer to a stylesheet. + * Thus, using g.d.s.setAnchorHref on an (incorrectly statically typed) object + * of type HTMLLinkElement can result in a security vulnerability. + * Assertions of the correct run-time type help prevent such incorrect use. + * + * In some cases, code using the DOM API is tested using mock objects (e.g., a + * plain object such as {'href': url} instead of an actual Location object). + * To allow such mocking, the assertions permit objects of types that are not + * relevant DOM API objects at all (for instance, not Element or Location). + * + * Note that instanceof checks don't work straightforwardly in older versions of + * IE, or across frames (see, + * http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object, + * http://stackoverflow.com/questions/26248599/instanceof-htmlelement-in-iframe-is-not-element-or-object). + * + * Hence, these assertions may pass vacuously in such scenarios. The resulting + * risk of security bugs is limited by the following factors: + * - A bug can only arise in scenarios involving incorrect static typing (the + * wrapper methods are statically typed to demand objects of the appropriate, + * precise type). + * - Typically, code is tested and exercised in multiple browsers. + */ + +/** + * Asserts that a given object is a Location. + * + * To permit this assertion to pass in the context of tests where DOM APIs might + * be mocked, also accepts any other type except for subtypes of {!Element}. + * This is to ensure that, for instance, HTMLLinkElement is not being used in + * place of a Location, since this could result in security bugs due to stronger + * contracts required for assignments to the href property of the latter. + * + * @param {?Object} o The object whose type to assert. + * @return {!Location} + */ +goog.dom.asserts.assertIsLocation = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.Location != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && (o instanceof win.Location || !(o instanceof win.Element)), + 'Argument is not a Location (or a non-Element mock); got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!Location} */ (o); +}; + +/** + * Asserts that a given object is a HTMLAnchorElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not of type Location nor a subtype + * of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLAnchorElement} + */ +goog.dom.asserts.assertIsHTMLAnchorElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLAnchorElement != 'undefined' && + typeof win.Location != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLAnchorElement || + !((o instanceof win.Location) || (o instanceof win.Element))), + 'Argument is not a HTMLAnchorElement (or a non-Element mock); ' + + 'got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLAnchorElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLLinkElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLLinkElement} + */ +goog.dom.asserts.assertIsHTMLLinkElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLLinkElement != 'undefined' && + typeof win.Location != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLLinkElement || + !((o instanceof win.Location) || (o instanceof win.Element))), + 'Argument is not a HTMLLinkElement (or a non-Element mock); got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLLinkElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLImageElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLImageElement} + */ +goog.dom.asserts.assertIsHTMLImageElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLImageElement != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLImageElement || + !(o instanceof win.Element)), + 'Argument is not a HTMLImageElement (or a non-Element mock); got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLImageElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLEmbedElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLEmbedElement} + */ +goog.dom.asserts.assertIsHTMLEmbedElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLEmbedElement != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLEmbedElement || + !(o instanceof win.Element)), + 'Argument is not a HTMLEmbedElement (or a non-Element mock); got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLEmbedElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLFrameElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLFrameElement} + */ +goog.dom.asserts.assertIsHTMLFrameElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLFrameElement != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLFrameElement || + !(o instanceof win.Element)), + 'Argument is not a HTMLFrameElement (or a non-Element mock); got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLFrameElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLIFrameElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLIFrameElement} + */ +goog.dom.asserts.assertIsHTMLIFrameElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLIFrameElement != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLIFrameElement || + !(o instanceof win.Element)), + 'Argument is not a HTMLIFrameElement (or a non-Element mock); ' + + 'got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLIFrameElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLObjectElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLObjectElement} + */ +goog.dom.asserts.assertIsHTMLObjectElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLObjectElement != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLObjectElement || + !(o instanceof win.Element)), + 'Argument is not a HTMLObjectElement (or a non-Element mock); ' + + 'got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLObjectElement} */ (o); +}; + +/** + * Asserts that a given object is a HTMLScriptElement. + * + * To permit this assertion to pass in the context of tests where elements might + * be mocked, also accepts objects that are not a subtype of Element. + * + * @param {?Object} o The object whose type to assert. + * @return {!HTMLScriptElement} + */ +goog.dom.asserts.assertIsHTMLScriptElement = function(o) { + if (goog.asserts.ENABLE_ASSERTS) { + var win = goog.dom.asserts.getWindow_(o); + if (typeof win.HTMLScriptElement != 'undefined' && + typeof win.Element != 'undefined') { + goog.asserts.assert( + o && + (o instanceof win.HTMLScriptElement || + !(o instanceof win.Element)), + 'Argument is not a HTMLScriptElement (or a non-Element mock); ' + + 'got: %s', + goog.dom.asserts.debugStringForType_(o)); + } + } + return /** @type {!HTMLScriptElement} */ (o); +}; + +/** + * Returns a string representation of a value's type. + * + * @param {*} value An object, or primitive. + * @return {string} The best display name for the value. + * @private + */ +goog.dom.asserts.debugStringForType_ = function(value) { + if (goog.isObject(value)) { + return value.constructor.displayName || value.constructor.name || + Object.prototype.toString.call(value); + } else { + return value === undefined ? 'undefined' : + value === null ? 'null' : typeof value; + } +}; + +/** + * Gets window of element. + * @param {?Object} o + * @return {!Window} + * @private + */ +goog.dom.asserts.getWindow_ = function(o) { + var doc = o && o.ownerDocument; + var win = doc && /** @type {?Window} */ (doc.defaultView || doc.parentWindow); + return win || /** @type {!Window} */ (goog.global); +}; diff --git a/static/src/assets/viz/2/goog/dom/browserfeature.js b/static/src/assets/viz/2/goog/dom/browserfeature.js new file mode 100644 index 0000000..1172166 --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/browserfeature.js @@ -0,0 +1,73 @@ +// Copyright 2010 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Browser capability checks for the dom package. + * + */ + + +goog.provide('goog.dom.BrowserFeature'); + +goog.require('goog.userAgent'); + + +/** + * Enum of browser capabilities. + * @enum {boolean} + */ +goog.dom.BrowserFeature = { + /** + * Whether attributes 'name' and 'type' can be added to an element after it's + * created. False in Internet Explorer prior to version 9. + */ + CAN_ADD_NAME_OR_TYPE_ATTRIBUTES: + !goog.userAgent.IE || goog.userAgent.isDocumentModeOrHigher(9), + + /** + * Whether we can use element.children to access an element's Element + * children. Available since Gecko 1.9.1, IE 9. (IE<9 also includes comment + * nodes in the collection.) + */ + CAN_USE_CHILDREN_ATTRIBUTE: !goog.userAgent.GECKO && !goog.userAgent.IE || + goog.userAgent.IE && goog.userAgent.isDocumentModeOrHigher(9) || + goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9.1'), + + /** + * Opera, Safari 3, and Internet Explorer 9 all support innerText but they + * include text nodes in script and style tags. Not document-mode-dependent. + */ + CAN_USE_INNER_TEXT: + (goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('9')), + + /** + * MSIE, Opera, and Safari>=4 support element.parentElement to access an + * element's parent if it is an Element. + */ + CAN_USE_PARENT_ELEMENT_PROPERTY: + goog.userAgent.IE || goog.userAgent.OPERA || goog.userAgent.WEBKIT, + + /** + * Whether NoScope elements need a scoped element written before them in + * innerHTML. + * MSDN: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx#1 + */ + INNER_HTML_NEEDS_SCOPED_ELEMENT: goog.userAgent.IE, + + /** + * Whether we use legacy IE range API. + */ + LEGACY_IE_RANGES: + goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(9) +}; diff --git a/static/src/assets/viz/2/goog/dom/dom.js b/static/src/assets/viz/2/goog/dom/dom.js new file mode 100644 index 0000000..919a0b6 --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/dom.js @@ -0,0 +1,3233 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities for manipulating the browser's Document Object Model + * Inspiration taken *heavily* from mochikit (http://mochikit.com/). + * + * You can use {@link goog.dom.DomHelper} to create new dom helpers that refer + * to a different document object. This is useful if you are working with + * frames or multiple windows. + * + * @author arv@google.com (Erik Arvidsson) + */ + + +// TODO(arv): Rename/refactor getTextContent and getRawTextContent. The problem +// is that getTextContent should mimic the DOM3 textContent. We should add a +// getInnerText (or getText) which tries to return the visible text, innerText. + + +goog.provide('goog.dom'); +goog.provide('goog.dom.Appendable'); +goog.provide('goog.dom.DomHelper'); + +goog.require('goog.array'); +goog.require('goog.asserts'); +goog.require('goog.dom.BrowserFeature'); +goog.require('goog.dom.NodeType'); +goog.require('goog.dom.TagName'); +goog.require('goog.dom.safe'); +goog.require('goog.html.SafeHtml'); +goog.require('goog.html.uncheckedconversions'); +goog.require('goog.math.Coordinate'); +goog.require('goog.math.Size'); +goog.require('goog.object'); +goog.require('goog.string'); +goog.require('goog.string.Unicode'); +goog.require('goog.userAgent'); + + +/** + * @define {boolean} Whether we know at compile time that the browser is in + * quirks mode. + */ +goog.define('goog.dom.ASSUME_QUIRKS_MODE', false); + + +/** + * @define {boolean} Whether we know at compile time that the browser is in + * standards compliance mode. + */ +goog.define('goog.dom.ASSUME_STANDARDS_MODE', false); + + +/** + * Whether we know the compatibility mode at compile time. + * @type {boolean} + * @private + */ +goog.dom.COMPAT_MODE_KNOWN_ = + goog.dom.ASSUME_QUIRKS_MODE || goog.dom.ASSUME_STANDARDS_MODE; + + +/** + * Gets the DomHelper object for the document where the element resides. + * @param {(Node|Window)=} opt_element If present, gets the DomHelper for this + * element. + * @return {!goog.dom.DomHelper} The DomHelper. + */ +goog.dom.getDomHelper = function(opt_element) { + return opt_element ? + new goog.dom.DomHelper(goog.dom.getOwnerDocument(opt_element)) : + (goog.dom.defaultDomHelper_ || + (goog.dom.defaultDomHelper_ = new goog.dom.DomHelper())); +}; + + +/** + * Cached default DOM helper. + * @type {!goog.dom.DomHelper|undefined} + * @private + */ +goog.dom.defaultDomHelper_; + + +/** + * Gets the document object being used by the dom library. + * @return {!Document} Document object. + */ +goog.dom.getDocument = function() { + return document; +}; + + +/** + * Gets an element from the current document by element id. + * + * If an Element is passed in, it is returned. + * + * @param {string|Element} element Element ID or a DOM node. + * @return {Element} The element with the given ID, or the node passed in. + */ +goog.dom.getElement = function(element) { + return goog.dom.getElementHelper_(document, element); +}; + + +/** + * Gets an element by id from the given document (if present). + * If an element is given, it is returned. + * @param {!Document} doc + * @param {string|Element} element Element ID or a DOM node. + * @return {Element} The resulting element. + * @private + */ +goog.dom.getElementHelper_ = function(doc, element) { + return goog.isString(element) ? doc.getElementById(element) : element; +}; + + +/** + * Gets an element by id, asserting that the element is found. + * + * This is used when an element is expected to exist, and should fail with + * an assertion error if it does not (if assertions are enabled). + * + * @param {string} id Element ID. + * @return {!Element} The element with the given ID, if it exists. + */ +goog.dom.getRequiredElement = function(id) { + return goog.dom.getRequiredElementHelper_(document, id); +}; + + +/** + * Helper function for getRequiredElementHelper functions, both static and + * on DomHelper. Asserts the element with the given id exists. + * @param {!Document} doc + * @param {string} id + * @return {!Element} The element with the given ID, if it exists. + * @private + */ +goog.dom.getRequiredElementHelper_ = function(doc, id) { + // To prevent users passing in Elements as is permitted in getElement(). + goog.asserts.assertString(id); + var element = goog.dom.getElementHelper_(doc, id); + element = + goog.asserts.assertElement(element, 'No element found with id: ' + id); + return element; +}; + + +/** + * Alias for getElement. + * @param {string|Element} element Element ID or a DOM node. + * @return {Element} The element with the given ID, or the node passed in. + * @deprecated Use {@link goog.dom.getElement} instead. + */ +goog.dom.$ = goog.dom.getElement; + + +/** + * Gets elements by tag name. + * @param {!goog.dom.TagName<T>} tagName + * @param {(!Document|!Element)=} opt_parent Parent element or document where to + * look for elements. Defaults to document. + * @return {!NodeList<R>} List of elements. The members of the list are + * {!Element} if tagName is not a member of goog.dom.TagName or more + * specific types if it is (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.getElementsByTagName = function(tagName, opt_parent) { + var parent = opt_parent || document; + return parent.getElementsByTagName(String(tagName)); +}; + + +/** + * Looks up elements by both tag and class name, using browser native functions + * ({@code querySelectorAll}, {@code getElementsByTagName} or + * {@code getElementsByClassName}) where possible. This function + * is a useful, if limited, way of collecting a list of DOM elements + * with certain characteristics. {@code goog.dom.query} offers a + * more powerful and general solution which allows matching on CSS3 + * selector expressions, but at increased cost in code size. If all you + * need is particular tags belonging to a single class, this function + * is fast and sleek. + * + * Note that tag names are case sensitive in the SVG namespace, and this + * function converts opt_tag to uppercase for comparisons. For queries in the + * SVG namespace you should use querySelector or querySelectorAll instead. + * https://bugzilla.mozilla.org/show_bug.cgi?id=963870 + * https://bugs.webkit.org/show_bug.cgi?id=83438 + * + * @see {goog.dom.query} + * + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {!IArrayLike<R>} Array-like list of elements (only a length property + * and numerical indices are guaranteed to exist). The members of the array + * are {!Element} if opt_tag is not a member of goog.dom.TagName or more + * specific types if it is (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.getElementsByTagNameAndClass = function(opt_tag, opt_class, opt_el) { + return goog.dom.getElementsByTagNameAndClass_( + document, opt_tag, opt_class, opt_el); +}; + + +/** + * Gets the first element matching the tag and the class. + * + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {?R} Reference to a DOM node. The return type is {?Element} if + * tagName is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {?HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.getElementByTagNameAndClass = function(opt_tag, opt_class, opt_el) { + return goog.dom.getElementByTagNameAndClass_( + document, opt_tag, opt_class, opt_el); +}; + + +/** + * Returns a static, array-like list of the elements with the provided + * className. + * @see {goog.dom.query} + * @param {string} className the name of the class to look for. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {!IArrayLike<!Element>} The items found with the class name provided. + */ +goog.dom.getElementsByClass = function(className, opt_el) { + var parent = opt_el || document; + if (goog.dom.canUseQuerySelector_(parent)) { + return parent.querySelectorAll('.' + className); + } + return goog.dom.getElementsByTagNameAndClass_( + document, '*', className, opt_el); +}; + + +/** + * Returns the first element with the provided className. + * @see {goog.dom.query} + * @param {string} className the name of the class to look for. + * @param {Element|Document=} opt_el Optional element to look in. + * @return {Element} The first item with the class name provided. + */ +goog.dom.getElementByClass = function(className, opt_el) { + var parent = opt_el || document; + var retVal = null; + if (parent.getElementsByClassName) { + retVal = parent.getElementsByClassName(className)[0]; + } else { + retVal = + goog.dom.getElementByTagNameAndClass_(document, '*', className, opt_el); + } + return retVal || null; +}; + + +/** + * Ensures an element with the given className exists, and then returns the + * first element with the provided className. + * @see {goog.dom.query} + * @param {string} className the name of the class to look for. + * @param {!Element|!Document=} opt_root Optional element or document to look + * in. + * @return {!Element} The first item with the class name provided. + * @throws {goog.asserts.AssertionError} Thrown if no element is found. + */ +goog.dom.getRequiredElementByClass = function(className, opt_root) { + var retValue = goog.dom.getElementByClass(className, opt_root); + return goog.asserts.assert( + retValue, 'No element found with className: ' + className); +}; + + +/** + * Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and + * fast W3C Selectors API. + * @param {!(Element|Document)} parent The parent document object. + * @return {boolean} whether or not we can use parent.querySelector* APIs. + * @private + */ +goog.dom.canUseQuerySelector_ = function(parent) { + return !!(parent.querySelectorAll && parent.querySelector); +}; + + +/** + * Helper for {@code getElementsByTagNameAndClass}. + * @param {!Document} doc The document to get the elements in. + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {!IArrayLike<R>} Array-like list of elements (only a length property + * and numerical indices are guaranteed to exist). The members of the array + * are {!Element} if opt_tag is not a member of goog.dom.TagName or more + * specific types if it is (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + * @private + */ +goog.dom.getElementsByTagNameAndClass_ = function( + doc, opt_tag, opt_class, opt_el) { + var parent = opt_el || doc; + var tagName = + (opt_tag && opt_tag != '*') ? String(opt_tag).toUpperCase() : ''; + + if (goog.dom.canUseQuerySelector_(parent) && (tagName || opt_class)) { + var query = tagName + (opt_class ? '.' + opt_class : ''); + return parent.querySelectorAll(query); + } + + // Use the native getElementsByClassName if available, under the assumption + // that even when the tag name is specified, there will be fewer elements to + // filter through when going by class than by tag name + if (opt_class && parent.getElementsByClassName) { + var els = parent.getElementsByClassName(opt_class); + + if (tagName) { + var arrayLike = {}; + var len = 0; + + // Filter for specific tags if requested. + for (var i = 0, el; el = els[i]; i++) { + if (tagName == el.nodeName) { + arrayLike[len++] = el; + } + } + arrayLike.length = len; + + return /** @type {!IArrayLike<!Element>} */ (arrayLike); + } else { + return els; + } + } + + var els = parent.getElementsByTagName(tagName || '*'); + + if (opt_class) { + var arrayLike = {}; + var len = 0; + for (var i = 0, el; el = els[i]; i++) { + var className = el.className; + // Check if className has a split function since SVG className does not. + if (typeof className.split == 'function' && + goog.array.contains(className.split(/\s+/), opt_class)) { + arrayLike[len++] = el; + } + } + arrayLike.length = len; + return /** @type {!IArrayLike<!Element>} */ (arrayLike); + } else { + return els; + } +}; + + +/** + * Helper for goog.dom.getElementByTagNameAndClass. + * + * @param {!Document} doc The document to get the elements in. + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {?R} Reference to a DOM node. The return type is {?Element} if + * tagName is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {?HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + * @private + */ +goog.dom.getElementByTagNameAndClass_ = function( + doc, opt_tag, opt_class, opt_el) { + var parent = opt_el || doc; + var tag = (opt_tag && opt_tag != '*') ? String(opt_tag).toUpperCase() : ''; + if (goog.dom.canUseQuerySelector_(parent) && (tag || opt_class)) { + return parent.querySelector(tag + (opt_class ? '.' + opt_class : '')); + } + var elements = + goog.dom.getElementsByTagNameAndClass_(doc, opt_tag, opt_class, opt_el); + return elements[0] || null; +}; + + + +/** + * Alias for {@code getElementsByTagNameAndClass}. + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {Element=} opt_el Optional element to look in. + * @return {!IArrayLike<R>} Array-like list of elements (only a length property + * and numerical indices are guaranteed to exist). The members of the array + * are {!Element} if opt_tag is not a member of goog.dom.TagName or more + * specific types if it is (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + * @deprecated Use {@link goog.dom.getElementsByTagNameAndClass} instead. + */ +goog.dom.$$ = goog.dom.getElementsByTagNameAndClass; + + +/** + * Sets multiple properties, and sometimes attributes, on an element. Note that + * properties are simply object properties on the element instance, while + * attributes are visible in the DOM. Many properties map to attributes with the + * same names, some with different names, and there are also unmappable cases. + * + * This method sets properties by default (which means that custom attributes + * are not supported). These are the exeptions (some of which is legacy): + * - "style": Even though this is an attribute name, it is translated to a + * property, "style.cssText". Note that this property sanitizes and formats + * its value, unlike the attribute. + * - "class": This is an attribute name, it is translated to the "className" + * property. + * - "for": This is an attribute name, it is translated to the "htmlFor" + * property. + * - Entries in {@see goog.dom.DIRECT_ATTRIBUTE_MAP_} are set as attributes, + * this is probably due to browser quirks. + * - "aria-*", "data-*": Always set as attributes, they have no property + * counterparts. + * + * @param {Element} element DOM node to set properties on. + * @param {Object} properties Hash of property:value pairs. + * Property values can be strings or goog.string.TypedString values (such as + * goog.html.SafeUrl). + */ +goog.dom.setProperties = function(element, properties) { + goog.object.forEach(properties, function(val, key) { + if (val && val.implementsGoogStringTypedString) { + val = val.getTypedStringValue(); + } + if (key == 'style') { + element.style.cssText = val; + } else if (key == 'class') { + element.className = val; + } else if (key == 'for') { + element.htmlFor = val; + } else if (goog.dom.DIRECT_ATTRIBUTE_MAP_.hasOwnProperty(key)) { + element.setAttribute(goog.dom.DIRECT_ATTRIBUTE_MAP_[key], val); + } else if ( + goog.string.startsWith(key, 'aria-') || + goog.string.startsWith(key, 'data-')) { + element.setAttribute(key, val); + } else { + element[key] = val; + } + }); +}; + + +/** + * Map of attributes that should be set using + * element.setAttribute(key, val) instead of element[key] = val. Used + * by goog.dom.setProperties. + * + * @private {!Object<string, string>} + * @const + */ +goog.dom.DIRECT_ATTRIBUTE_MAP_ = { + 'cellpadding': 'cellPadding', + 'cellspacing': 'cellSpacing', + 'colspan': 'colSpan', + 'frameborder': 'frameBorder', + 'height': 'height', + 'maxlength': 'maxLength', + 'nonce': 'nonce', + 'role': 'role', + 'rowspan': 'rowSpan', + 'type': 'type', + 'usemap': 'useMap', + 'valign': 'vAlign', + 'width': 'width' +}; + + +/** + * Gets the dimensions of the viewport. + * + * Gecko Standards mode: + * docEl.clientWidth Width of viewport excluding scrollbar. + * win.innerWidth Width of viewport including scrollbar. + * body.clientWidth Width of body element. + * + * docEl.clientHeight Height of viewport excluding scrollbar. + * win.innerHeight Height of viewport including scrollbar. + * body.clientHeight Height of document. + * + * Gecko Backwards compatible mode: + * docEl.clientWidth Width of viewport excluding scrollbar. + * win.innerWidth Width of viewport including scrollbar. + * body.clientWidth Width of viewport excluding scrollbar. + * + * docEl.clientHeight Height of document. + * win.innerHeight Height of viewport including scrollbar. + * body.clientHeight Height of viewport excluding scrollbar. + * + * IE6/7 Standards mode: + * docEl.clientWidth Width of viewport excluding scrollbar. + * win.innerWidth Undefined. + * body.clientWidth Width of body element. + * + * docEl.clientHeight Height of viewport excluding scrollbar. + * win.innerHeight Undefined. + * body.clientHeight Height of document element. + * + * IE5 + IE6/7 Backwards compatible mode: + * docEl.clientWidth 0. + * win.innerWidth Undefined. + * body.clientWidth Width of viewport excluding scrollbar. + * + * docEl.clientHeight 0. + * win.innerHeight Undefined. + * body.clientHeight Height of viewport excluding scrollbar. + * + * Opera 9 Standards and backwards compatible mode: + * docEl.clientWidth Width of viewport excluding scrollbar. + * win.innerWidth Width of viewport including scrollbar. + * body.clientWidth Width of viewport excluding scrollbar. + * + * docEl.clientHeight Height of document. + * win.innerHeight Height of viewport including scrollbar. + * body.clientHeight Height of viewport excluding scrollbar. + * + * WebKit: + * Safari 2 + * docEl.clientHeight Same as scrollHeight. + * docEl.clientWidth Same as innerWidth. + * win.innerWidth Width of viewport excluding scrollbar. + * win.innerHeight Height of the viewport including scrollbar. + * frame.innerHeight Height of the viewport exluding scrollbar. + * + * Safari 3 (tested in 522) + * + * docEl.clientWidth Width of viewport excluding scrollbar. + * docEl.clientHeight Height of viewport excluding scrollbar in strict mode. + * body.clientHeight Height of viewport excluding scrollbar in quirks mode. + * + * @param {Window=} opt_window Optional window element to test. + * @return {!goog.math.Size} Object with values 'width' and 'height'. + */ +goog.dom.getViewportSize = function(opt_window) { + // TODO(arv): This should not take an argument + return goog.dom.getViewportSize_(opt_window || window); +}; + + +/** + * Helper for {@code getViewportSize}. + * @param {Window} win The window to get the view port size for. + * @return {!goog.math.Size} Object with values 'width' and 'height'. + * @private + */ +goog.dom.getViewportSize_ = function(win) { + var doc = win.document; + var el = goog.dom.isCss1CompatMode_(doc) ? doc.documentElement : doc.body; + return new goog.math.Size(el.clientWidth, el.clientHeight); +}; + + +/** + * Calculates the height of the document. + * + * @return {number} The height of the current document. + */ +goog.dom.getDocumentHeight = function() { + return goog.dom.getDocumentHeight_(window); +}; + +/** + * Calculates the height of the document of the given window. + * + * @param {!Window} win The window whose document height to retrieve. + * @return {number} The height of the document of the given window. + */ +goog.dom.getDocumentHeightForWindow = function(win) { + return goog.dom.getDocumentHeight_(win); +}; + +/** + * Calculates the height of the document of the given window. + * + * Function code copied from the opensocial gadget api: + * gadgets.window.adjustHeight(opt_height) + * + * @private + * @param {!Window} win The window whose document height to retrieve. + * @return {number} The height of the document of the given window. + */ +goog.dom.getDocumentHeight_ = function(win) { + // NOTE(eae): This method will return the window size rather than the document + // size in webkit quirks mode. + var doc = win.document; + var height = 0; + + if (doc) { + // Calculating inner content height is hard and different between + // browsers rendering in Strict vs. Quirks mode. We use a combination of + // three properties within document.body and document.documentElement: + // - scrollHeight + // - offsetHeight + // - clientHeight + // These values differ significantly between browsers and rendering modes. + // But there are patterns. It just takes a lot of time and persistence + // to figure out. + + var body = doc.body; + var docEl = /** @type {!HTMLElement} */ (doc.documentElement); + if (!(docEl && body)) { + return 0; + } + + // Get the height of the viewport + var vh = goog.dom.getViewportSize_(win).height; + if (goog.dom.isCss1CompatMode_(doc) && docEl.scrollHeight) { + // In Strict mode: + // The inner content height is contained in either: + // document.documentElement.scrollHeight + // document.documentElement.offsetHeight + // Based on studying the values output by different browsers, + // use the value that's NOT equal to the viewport height found above. + height = + docEl.scrollHeight != vh ? docEl.scrollHeight : docEl.offsetHeight; + } else { + // In Quirks mode: + // documentElement.clientHeight is equal to documentElement.offsetHeight + // except in IE. In most browsers, document.documentElement can be used + // to calculate the inner content height. + // However, in other browsers (e.g. IE), document.body must be used + // instead. How do we know which one to use? + // If document.documentElement.clientHeight does NOT equal + // document.documentElement.offsetHeight, then use document.body. + var sh = docEl.scrollHeight; + var oh = docEl.offsetHeight; + if (docEl.clientHeight != oh) { + sh = body.scrollHeight; + oh = body.offsetHeight; + } + + // Detect whether the inner content height is bigger or smaller + // than the bounding box (viewport). If bigger, take the larger + // value. If smaller, take the smaller value. + if (sh > vh) { + // Content is larger + height = sh > oh ? sh : oh; + } else { + // Content is smaller + height = sh < oh ? sh : oh; + } + } + } + + return height; +}; + + +/** + * Gets the page scroll distance as a coordinate object. + * + * @param {Window=} opt_window Optional window element to test. + * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. + * @deprecated Use {@link goog.dom.getDocumentScroll} instead. + */ +goog.dom.getPageScroll = function(opt_window) { + var win = opt_window || goog.global || window; + return goog.dom.getDomHelper(win.document).getDocumentScroll(); +}; + + +/** + * Gets the document scroll distance as a coordinate object. + * + * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. + */ +goog.dom.getDocumentScroll = function() { + return goog.dom.getDocumentScroll_(document); +}; + + +/** + * Helper for {@code getDocumentScroll}. + * + * @param {!Document} doc The document to get the scroll for. + * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. + * @private + */ +goog.dom.getDocumentScroll_ = function(doc) { + var el = goog.dom.getDocumentScrollElement_(doc); + var win = goog.dom.getWindow_(doc); + if (goog.userAgent.IE && goog.userAgent.isVersionOrHigher('10') && + win.pageYOffset != el.scrollTop) { + // The keyboard on IE10 touch devices shifts the page using the pageYOffset + // without modifying scrollTop. For this case, we want the body scroll + // offsets. + return new goog.math.Coordinate(el.scrollLeft, el.scrollTop); + } + return new goog.math.Coordinate( + win.pageXOffset || el.scrollLeft, win.pageYOffset || el.scrollTop); +}; + + +/** + * Gets the document scroll element. + * @return {!Element} Scrolling element. + */ +goog.dom.getDocumentScrollElement = function() { + return goog.dom.getDocumentScrollElement_(document); +}; + + +/** + * Helper for {@code getDocumentScrollElement}. + * @param {!Document} doc The document to get the scroll element for. + * @return {!Element} Scrolling element. + * @private + */ +goog.dom.getDocumentScrollElement_ = function(doc) { + // Old WebKit needs body.scrollLeft in both quirks mode and strict mode. We + // also default to the documentElement if the document does not have a body + // (e.g. a SVG document). + // Uses http://dev.w3.org/csswg/cssom-view/#dom-document-scrollingelement to + // avoid trying to guess about browser behavior from the UA string. + if (doc.scrollingElement) { + return doc.scrollingElement; + } + if (!goog.userAgent.WEBKIT && goog.dom.isCss1CompatMode_(doc)) { + return doc.documentElement; + } + return doc.body || doc.documentElement; +}; + + +/** + * Gets the window object associated with the given document. + * + * @param {Document=} opt_doc Document object to get window for. + * @return {!Window} The window associated with the given document. + */ +goog.dom.getWindow = function(opt_doc) { + // TODO(arv): This should not take an argument. + return opt_doc ? goog.dom.getWindow_(opt_doc) : window; +}; + + +/** + * Helper for {@code getWindow}. + * + * @param {!Document} doc Document object to get window for. + * @return {!Window} The window associated with the given document. + * @private + */ +goog.dom.getWindow_ = function(doc) { + return /** @type {!Window} */ (doc.parentWindow || doc.defaultView); +}; + + +/** + * Returns a dom node with a set of attributes. This function accepts varargs + * for subsequent nodes to be added. Subsequent nodes will be added to the + * first node as childNodes. + * + * So: + * <code>createDom(goog.dom.TagName.DIV, null, createDom(goog.dom.TagName.P), + * createDom(goog.dom.TagName.P));</code> would return a div with two child + * paragraphs + * + * For passing properties, please see {@link goog.dom.setProperties} for more + * information. + * + * @param {string|!goog.dom.TagName<T>} tagName Tag to create. + * @param {?Object|?Array<string>|string=} opt_attributes If object, then a map + * of name-value pairs for attributes. If a string, then this is the + * className of the new element. If an array, the elements will be joined + * together as the className of the new element. + * @param {...(Object|string|Array|NodeList)} var_args Further DOM nodes or + * strings for text nodes. If one of the var_args is an array or NodeList, + * its elements will be added as childNodes instead. + * @return {R} Reference to a DOM node. The return type is {!Element} if tagName + * is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.createDom = function(tagName, opt_attributes, var_args) { + return goog.dom.createDom_(document, arguments); +}; + + +/** + * Helper for {@code createDom}. + * @param {!Document} doc The document to create the DOM in. + * @param {!Arguments} args Argument object passed from the callers. See + * {@code goog.dom.createDom} for details. + * @return {!Element} Reference to a DOM node. + * @private + */ +goog.dom.createDom_ = function(doc, args) { + var tagName = String(args[0]); + var attributes = args[1]; + + // Internet Explorer is dumb: + // name: https://msdn.microsoft.com/en-us/library/ms534184(v=vs.85).aspx + // type: https://msdn.microsoft.com/en-us/library/ms534700(v=vs.85).aspx + // Also does not allow setting of 'type' attribute on 'input' or 'button'. + if (!goog.dom.BrowserFeature.CAN_ADD_NAME_OR_TYPE_ATTRIBUTES && attributes && + (attributes.name || attributes.type)) { + var tagNameArr = ['<', tagName]; + if (attributes.name) { + tagNameArr.push(' name="', goog.string.htmlEscape(attributes.name), '"'); + } + if (attributes.type) { + tagNameArr.push(' type="', goog.string.htmlEscape(attributes.type), '"'); + + // Clone attributes map to remove 'type' without mutating the input. + var clone = {}; + goog.object.extend(clone, attributes); + + // JSCompiler can't see how goog.object.extend added this property, + // because it was essentially added by reflection. + // So it needs to be quoted. + delete clone['type']; + + attributes = clone; + } + tagNameArr.push('>'); + tagName = tagNameArr.join(''); + } + + var element = doc.createElement(tagName); + + if (attributes) { + if (goog.isString(attributes)) { + element.className = attributes; + } else if (goog.isArray(attributes)) { + element.className = attributes.join(' '); + } else { + goog.dom.setProperties(element, attributes); + } + } + + if (args.length > 2) { + goog.dom.append_(doc, element, args, 2); + } + + return element; +}; + + +/** + * Appends a node with text or other nodes. + * @param {!Document} doc The document to create new nodes in. + * @param {!Node} parent The node to append nodes to. + * @param {!Arguments} args The values to add. See {@code goog.dom.append}. + * @param {number} startIndex The index of the array to start from. + * @private + */ +goog.dom.append_ = function(doc, parent, args, startIndex) { + function childHandler(child) { + // TODO(user): More coercion, ala MochiKit? + if (child) { + parent.appendChild( + goog.isString(child) ? doc.createTextNode(child) : child); + } + } + + for (var i = startIndex; i < args.length; i++) { + var arg = args[i]; + // TODO(attila): Fix isArrayLike to return false for a text node. + if (goog.isArrayLike(arg) && !goog.dom.isNodeLike(arg)) { + // If the argument is a node list, not a real array, use a clone, + // because forEach can't be used to mutate a NodeList. + goog.array.forEach( + goog.dom.isNodeList(arg) ? goog.array.toArray(arg) : arg, + childHandler); + } else { + childHandler(arg); + } + } +}; + + +/** + * Alias for {@code createDom}. + * @param {string|!goog.dom.TagName<T>} tagName Tag to create. + * @param {?Object|?Array<string>|string=} opt_attributes If object, then a map + * of name-value pairs for attributes. If a string, then this is the + * className of the new element. If an array, the elements will be joined + * together as the className of the new element. + * @param {...(Object|string|Array|NodeList)} var_args Further DOM nodes or + * strings for text nodes. If one of the var_args is an array, its + * children will be added as childNodes instead. + * @return {R} Reference to a DOM node. The return type is {!Element} if tagName + * is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + * @deprecated Use {@link goog.dom.createDom} instead. + */ +goog.dom.$dom = goog.dom.createDom; + + +/** + * Creates a new element. + * @param {string|!goog.dom.TagName<T>} name Tag to create. + * @return {R} The new element. The return type is {!Element} if name is + * a string or a more specific type if it is a member of goog.dom.TagName + * (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.createElement = function(name) { + return goog.dom.createElement_(document, name); +}; + + +/** + * Creates a new element. + * @param {!Document} doc The document to create the element in. + * @param {string|!goog.dom.TagName<T>} name Tag to create. + * @return {R} The new element. The return type is {!Element} if name is + * a string or a more specific type if it is a member of goog.dom.TagName + * (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + * @private + */ +goog.dom.createElement_ = function(doc, name) { + return doc.createElement(String(name)); +}; + + +/** + * Creates a new text node. + * @param {number|string} content Content. + * @return {!Text} The new text node. + */ +goog.dom.createTextNode = function(content) { + return document.createTextNode(String(content)); +}; + + +/** + * Create a table. + * @param {number} rows The number of rows in the table. Must be >= 1. + * @param {number} columns The number of columns in the table. Must be >= 1. + * @param {boolean=} opt_fillWithNbsp If true, fills table entries with + * {@code goog.string.Unicode.NBSP} characters. + * @return {!Element} The created table. + */ +goog.dom.createTable = function(rows, columns, opt_fillWithNbsp) { + // TODO(mlourenco): Return HTMLTableElement, also in prototype function. + // Callers need to be updated to e.g. not assign numbers to table.cellSpacing. + return goog.dom.createTable_(document, rows, columns, !!opt_fillWithNbsp); +}; + + +/** + * Create a table. + * @param {!Document} doc Document object to use to create the table. + * @param {number} rows The number of rows in the table. Must be >= 1. + * @param {number} columns The number of columns in the table. Must be >= 1. + * @param {boolean} fillWithNbsp If true, fills table entries with + * {@code goog.string.Unicode.NBSP} characters. + * @return {!HTMLTableElement} The created table. + * @private + */ +goog.dom.createTable_ = function(doc, rows, columns, fillWithNbsp) { + var table = goog.dom.createElement_(doc, goog.dom.TagName.TABLE); + var tbody = + table.appendChild(goog.dom.createElement_(doc, goog.dom.TagName.TBODY)); + for (var i = 0; i < rows; i++) { + var tr = goog.dom.createElement_(doc, goog.dom.TagName.TR); + for (var j = 0; j < columns; j++) { + var td = goog.dom.createElement_(doc, goog.dom.TagName.TD); + // IE <= 9 will create a text node if we set text content to the empty + // string, so we avoid doing it unless necessary. This ensures that the + // same DOM tree is returned on all browsers. + if (fillWithNbsp) { + goog.dom.setTextContent(td, goog.string.Unicode.NBSP); + } + tr.appendChild(td); + } + tbody.appendChild(tr); + } + return table; +}; + + + +/** + * Creates a new Node from constant strings of HTML markup. + * @param {...!goog.string.Const} var_args The HTML strings to concatenate then + * convert into a node. + * @return {!Node} + */ +goog.dom.constHtmlToNode = function(var_args) { + var stringArray = goog.array.map(arguments, goog.string.Const.unwrap); + var safeHtml = + goog.html.uncheckedconversions + .safeHtmlFromStringKnownToSatisfyTypeContract( + goog.string.Const.from( + 'Constant HTML string, that gets turned into a ' + + 'Node later, so it will be automatically balanced.'), + stringArray.join('')); + return goog.dom.safeHtmlToNode(safeHtml); +}; + + +/** + * Converts HTML markup into a node. This is a safe version of + * {@code goog.dom.htmlToDocumentFragment} which is now deleted. + * @param {!goog.html.SafeHtml} html The HTML markup to convert. + * @return {!Node} The resulting node. + */ +goog.dom.safeHtmlToNode = function(html) { + return goog.dom.safeHtmlToNode_(document, html); +}; + + +/** + * Helper for {@code safeHtmlToNode}. + * @param {!Document} doc The document. + * @param {!goog.html.SafeHtml} html The HTML markup to convert. + * @return {!Node} The resulting node. + * @private + */ +goog.dom.safeHtmlToNode_ = function(doc, html) { + var tempDiv = goog.dom.createElement_(doc, goog.dom.TagName.DIV); + if (goog.dom.BrowserFeature.INNER_HTML_NEEDS_SCOPED_ELEMENT) { + goog.dom.safe.setInnerHtml( + tempDiv, goog.html.SafeHtml.concat(goog.html.SafeHtml.BR, html)); + tempDiv.removeChild(tempDiv.firstChild); + } else { + goog.dom.safe.setInnerHtml(tempDiv, html); + } + return goog.dom.childrenToNode_(doc, tempDiv); +}; + + +/** + * Helper for {@code safeHtmlToNode_}. + * @param {!Document} doc The document. + * @param {!Node} tempDiv The input node. + * @return {!Node} The resulting node. + * @private + */ +goog.dom.childrenToNode_ = function(doc, tempDiv) { + if (tempDiv.childNodes.length == 1) { + return tempDiv.removeChild(tempDiv.firstChild); + } else { + var fragment = doc.createDocumentFragment(); + while (tempDiv.firstChild) { + fragment.appendChild(tempDiv.firstChild); + } + return fragment; + } +}; + + +/** + * Returns true if the browser is in "CSS1-compatible" (standards-compliant) + * mode, false otherwise. + * @return {boolean} True if in CSS1-compatible mode. + */ +goog.dom.isCss1CompatMode = function() { + return goog.dom.isCss1CompatMode_(document); +}; + + +/** + * Returns true if the browser is in "CSS1-compatible" (standards-compliant) + * mode, false otherwise. + * @param {!Document} doc The document to check. + * @return {boolean} True if in CSS1-compatible mode. + * @private + */ +goog.dom.isCss1CompatMode_ = function(doc) { + if (goog.dom.COMPAT_MODE_KNOWN_) { + return goog.dom.ASSUME_STANDARDS_MODE; + } + + return doc.compatMode == 'CSS1Compat'; +}; + + +/** + * Determines if the given node can contain children, intended to be used for + * HTML generation. + * + * IE natively supports node.canHaveChildren but has inconsistent behavior. + * Prior to IE8 the base tag allows children and in IE9 all nodes return true + * for canHaveChildren. + * + * In practice all non-IE browsers allow you to add children to any node, but + * the behavior is inconsistent: + * + * <pre> + * var a = goog.dom.createElement(goog.dom.TagName.BR); + * a.appendChild(document.createTextNode('foo')); + * a.appendChild(document.createTextNode('bar')); + * console.log(a.childNodes.length); // 2 + * console.log(a.innerHTML); // Chrome: "", IE9: "foobar", FF3.5: "foobar" + * </pre> + * + * For more information, see: + * http://dev.w3.org/html5/markup/syntax.html#syntax-elements + * + * TODO(user): Rename shouldAllowChildren() ? + * + * @param {Node} node The node to check. + * @return {boolean} Whether the node can contain children. + */ +goog.dom.canHaveChildren = function(node) { + if (node.nodeType != goog.dom.NodeType.ELEMENT) { + return false; + } + switch (/** @type {!Element} */ (node).tagName) { + case String(goog.dom.TagName.APPLET): + case String(goog.dom.TagName.AREA): + case String(goog.dom.TagName.BASE): + case String(goog.dom.TagName.BR): + case String(goog.dom.TagName.COL): + case String(goog.dom.TagName.COMMAND): + case String(goog.dom.TagName.EMBED): + case String(goog.dom.TagName.FRAME): + case String(goog.dom.TagName.HR): + case String(goog.dom.TagName.IMG): + case String(goog.dom.TagName.INPUT): + case String(goog.dom.TagName.IFRAME): + case String(goog.dom.TagName.ISINDEX): + case String(goog.dom.TagName.KEYGEN): + case String(goog.dom.TagName.LINK): + case String(goog.dom.TagName.NOFRAMES): + case String(goog.dom.TagName.NOSCRIPT): + case String(goog.dom.TagName.META): + case String(goog.dom.TagName.OBJECT): + case String(goog.dom.TagName.PARAM): + case String(goog.dom.TagName.SCRIPT): + case String(goog.dom.TagName.SOURCE): + case String(goog.dom.TagName.STYLE): + case String(goog.dom.TagName.TRACK): + case String(goog.dom.TagName.WBR): + return false; + } + return true; +}; + + +/** + * Appends a child to a node. + * @param {Node} parent Parent. + * @param {Node} child Child. + */ +goog.dom.appendChild = function(parent, child) { + parent.appendChild(child); +}; + + +/** + * Appends a node with text or other nodes. + * @param {!Node} parent The node to append nodes to. + * @param {...goog.dom.Appendable} var_args The things to append to the node. + * If this is a Node it is appended as is. + * If this is a string then a text node is appended. + * If this is an array like object then fields 0 to length - 1 are appended. + */ +goog.dom.append = function(parent, var_args) { + goog.dom.append_(goog.dom.getOwnerDocument(parent), parent, arguments, 1); +}; + + +/** + * Removes all the child nodes on a DOM node. + * @param {Node} node Node to remove children from. + */ +goog.dom.removeChildren = function(node) { + // Note: Iterations over live collections can be slow, this is the fastest + // we could find. The double parenthesis are used to prevent JsCompiler and + // strict warnings. + var child; + while ((child = node.firstChild)) { + node.removeChild(child); + } +}; + + +/** + * Inserts a new node before an existing reference node (i.e. as the previous + * sibling). If the reference node has no parent, then does nothing. + * @param {Node} newNode Node to insert. + * @param {Node} refNode Reference node to insert before. + */ +goog.dom.insertSiblingBefore = function(newNode, refNode) { + if (refNode.parentNode) { + refNode.parentNode.insertBefore(newNode, refNode); + } +}; + + +/** + * Inserts a new node after an existing reference node (i.e. as the next + * sibling). If the reference node has no parent, then does nothing. + * @param {Node} newNode Node to insert. + * @param {Node} refNode Reference node to insert after. + */ +goog.dom.insertSiblingAfter = function(newNode, refNode) { + if (refNode.parentNode) { + refNode.parentNode.insertBefore(newNode, refNode.nextSibling); + } +}; + + +/** + * Insert a child at a given index. If index is larger than the number of child + * nodes that the parent currently has, the node is inserted as the last child + * node. + * @param {Element} parent The element into which to insert the child. + * @param {Node} child The element to insert. + * @param {number} index The index at which to insert the new child node. Must + * not be negative. + */ +goog.dom.insertChildAt = function(parent, child, index) { + // Note that if the second argument is null, insertBefore + // will append the child at the end of the list of children. + parent.insertBefore(child, parent.childNodes[index] || null); +}; + + +/** + * Removes a node from its parent. + * @param {Node} node The node to remove. + * @return {Node} The node removed if removed; else, null. + */ +goog.dom.removeNode = function(node) { + return node && node.parentNode ? node.parentNode.removeChild(node) : null; +}; + + +/** + * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no + * parent. + * @param {Node} newNode Node to insert. + * @param {Node} oldNode Node to replace. + */ +goog.dom.replaceNode = function(newNode, oldNode) { + var parent = oldNode.parentNode; + if (parent) { + parent.replaceChild(newNode, oldNode); + } +}; + + +/** + * Flattens an element. That is, removes it and replace it with its children. + * Does nothing if the element is not in the document. + * @param {Element} element The element to flatten. + * @return {Element|undefined} The original element, detached from the document + * tree, sans children; or undefined, if the element was not in the document + * to begin with. + */ +goog.dom.flattenElement = function(element) { + var child, parent = element.parentNode; + if (parent && parent.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT) { + // Use IE DOM method (supported by Opera too) if available + if (element.removeNode) { + return /** @type {Element} */ (element.removeNode(false)); + } else { + // Move all children of the original node up one level. + while ((child = element.firstChild)) { + parent.insertBefore(child, element); + } + + // Detach the original element. + return /** @type {Element} */ (goog.dom.removeNode(element)); + } + } +}; + + +/** + * Returns an array containing just the element children of the given element. + * @param {Element} element The element whose element children we want. + * @return {!(Array<!Element>|NodeList<!Element>)} An array or array-like list + * of just the element children of the given element. + */ +goog.dom.getChildren = function(element) { + // We check if the children attribute is supported for child elements + // since IE8 misuses the attribute by also including comments. + if (goog.dom.BrowserFeature.CAN_USE_CHILDREN_ATTRIBUTE && + element.children != undefined) { + return element.children; + } + // Fall back to manually filtering the element's child nodes. + return goog.array.filter(element.childNodes, function(node) { + return node.nodeType == goog.dom.NodeType.ELEMENT; + }); +}; + + +/** + * Returns the first child node that is an element. + * @param {Node} node The node to get the first child element of. + * @return {Element} The first child node of {@code node} that is an element. + */ +goog.dom.getFirstElementChild = function(node) { + if (goog.isDef(node.firstElementChild)) { + return /** @type {!Element} */ (node).firstElementChild; + } + return goog.dom.getNextElementNode_(node.firstChild, true); +}; + + +/** + * Returns the last child node that is an element. + * @param {Node} node The node to get the last child element of. + * @return {Element} The last child node of {@code node} that is an element. + */ +goog.dom.getLastElementChild = function(node) { + if (goog.isDef(node.lastElementChild)) { + return /** @type {!Element} */ (node).lastElementChild; + } + return goog.dom.getNextElementNode_(node.lastChild, false); +}; + + +/** + * Returns the first next sibling that is an element. + * @param {Node} node The node to get the next sibling element of. + * @return {Element} The next sibling of {@code node} that is an element. + */ +goog.dom.getNextElementSibling = function(node) { + if (goog.isDef(node.nextElementSibling)) { + return /** @type {!Element} */ (node).nextElementSibling; + } + return goog.dom.getNextElementNode_(node.nextSibling, true); +}; + + +/** + * Returns the first previous sibling that is an element. + * @param {Node} node The node to get the previous sibling element of. + * @return {Element} The first previous sibling of {@code node} that is + * an element. + */ +goog.dom.getPreviousElementSibling = function(node) { + if (goog.isDef(node.previousElementSibling)) { + return /** @type {!Element} */ (node).previousElementSibling; + } + return goog.dom.getNextElementNode_(node.previousSibling, false); +}; + + +/** + * Returns the first node that is an element in the specified direction, + * starting with {@code node}. + * @param {Node} node The node to get the next element from. + * @param {boolean} forward Whether to look forwards or backwards. + * @return {Element} The first element. + * @private + */ +goog.dom.getNextElementNode_ = function(node, forward) { + while (node && node.nodeType != goog.dom.NodeType.ELEMENT) { + node = forward ? node.nextSibling : node.previousSibling; + } + + return /** @type {Element} */ (node); +}; + + +/** + * Returns the next node in source order from the given node. + * @param {Node} node The node. + * @return {Node} The next node in the DOM tree, or null if this was the last + * node. + */ +goog.dom.getNextNode = function(node) { + if (!node) { + return null; + } + + if (node.firstChild) { + return node.firstChild; + } + + while (node && !node.nextSibling) { + node = node.parentNode; + } + + return node ? node.nextSibling : null; +}; + + +/** + * Returns the previous node in source order from the given node. + * @param {Node} node The node. + * @return {Node} The previous node in the DOM tree, or null if this was the + * first node. + */ +goog.dom.getPreviousNode = function(node) { + if (!node) { + return null; + } + + if (!node.previousSibling) { + return node.parentNode; + } + + node = node.previousSibling; + while (node && node.lastChild) { + node = node.lastChild; + } + + return node; +}; + + +/** + * Whether the object looks like a DOM node. + * @param {?} obj The object being tested for node likeness. + * @return {boolean} Whether the object looks like a DOM node. + */ +goog.dom.isNodeLike = function(obj) { + return goog.isObject(obj) && obj.nodeType > 0; +}; + + +/** + * Whether the object looks like an Element. + * @param {?} obj The object being tested for Element likeness. + * @return {boolean} Whether the object looks like an Element. + */ +goog.dom.isElement = function(obj) { + return goog.isObject(obj) && obj.nodeType == goog.dom.NodeType.ELEMENT; +}; + + +/** + * Returns true if the specified value is a Window object. This includes the + * global window for HTML pages, and iframe windows. + * @param {?} obj Variable to test. + * @return {boolean} Whether the variable is a window. + */ +goog.dom.isWindow = function(obj) { + return goog.isObject(obj) && obj['window'] == obj; +}; + + +/** + * Returns an element's parent, if it's an Element. + * @param {Element} element The DOM element. + * @return {Element} The parent, or null if not an Element. + */ +goog.dom.getParentElement = function(element) { + var parent; + if (goog.dom.BrowserFeature.CAN_USE_PARENT_ELEMENT_PROPERTY) { + var isIe9 = goog.userAgent.IE && goog.userAgent.isVersionOrHigher('9') && + !goog.userAgent.isVersionOrHigher('10'); + // SVG elements in IE9 can't use the parentElement property. + // goog.global['SVGElement'] is not defined in IE9 quirks mode. + if (!(isIe9 && goog.global['SVGElement'] && + element instanceof goog.global['SVGElement'])) { + parent = element.parentElement; + if (parent) { + return parent; + } + } + } + parent = element.parentNode; + return goog.dom.isElement(parent) ? /** @type {!Element} */ (parent) : null; +}; + + +/** + * Whether a node contains another node. + * @param {?Node|undefined} parent The node that should contain the other node. + * @param {?Node|undefined} descendant The node to test presence of. + * @return {boolean} Whether the parent node contains the descendent node. + */ +goog.dom.contains = function(parent, descendant) { + if (!parent || !descendant) { + return false; + } + // We use browser specific methods for this if available since it is faster + // that way. + + // IE DOM + if (parent.contains && descendant.nodeType == goog.dom.NodeType.ELEMENT) { + return parent == descendant || parent.contains(descendant); + } + + // W3C DOM Level 3 + if (typeof parent.compareDocumentPosition != 'undefined') { + return parent == descendant || + Boolean(parent.compareDocumentPosition(descendant) & 16); + } + + // W3C DOM Level 1 + while (descendant && parent != descendant) { + descendant = descendant.parentNode; + } + return descendant == parent; +}; + + +/** + * Compares the document order of two nodes, returning 0 if they are the same + * node, a negative number if node1 is before node2, and a positive number if + * node2 is before node1. Note that we compare the order the tags appear in the + * document so in the tree <b><i>text</i></b> the B node is considered to be + * before the I node. + * + * @param {Node} node1 The first node to compare. + * @param {Node} node2 The second node to compare. + * @return {number} 0 if the nodes are the same node, a negative number if node1 + * is before node2, and a positive number if node2 is before node1. + */ +goog.dom.compareNodeOrder = function(node1, node2) { + // Fall out quickly for equality. + if (node1 == node2) { + return 0; + } + + // Use compareDocumentPosition where available + if (node1.compareDocumentPosition) { + // 4 is the bitmask for FOLLOWS. + return node1.compareDocumentPosition(node2) & 2 ? 1 : -1; + } + + // Special case for document nodes on IE 7 and 8. + if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(9)) { + if (node1.nodeType == goog.dom.NodeType.DOCUMENT) { + return -1; + } + if (node2.nodeType == goog.dom.NodeType.DOCUMENT) { + return 1; + } + } + + // Process in IE using sourceIndex - we check to see if the first node has + // a source index or if its parent has one. + if ('sourceIndex' in node1 || + (node1.parentNode && 'sourceIndex' in node1.parentNode)) { + var isElement1 = node1.nodeType == goog.dom.NodeType.ELEMENT; + var isElement2 = node2.nodeType == goog.dom.NodeType.ELEMENT; + + if (isElement1 && isElement2) { + return node1.sourceIndex - node2.sourceIndex; + } else { + var parent1 = node1.parentNode; + var parent2 = node2.parentNode; + + if (parent1 == parent2) { + return goog.dom.compareSiblingOrder_(node1, node2); + } + + if (!isElement1 && goog.dom.contains(parent1, node2)) { + return -1 * goog.dom.compareParentsDescendantNodeIe_(node1, node2); + } + + + if (!isElement2 && goog.dom.contains(parent2, node1)) { + return goog.dom.compareParentsDescendantNodeIe_(node2, node1); + } + + return (isElement1 ? node1.sourceIndex : parent1.sourceIndex) - + (isElement2 ? node2.sourceIndex : parent2.sourceIndex); + } + } + + // For Safari, we compare ranges. + var doc = goog.dom.getOwnerDocument(node1); + + var range1, range2; + range1 = doc.createRange(); + range1.selectNode(node1); + range1.collapse(true); + + range2 = doc.createRange(); + range2.selectNode(node2); + range2.collapse(true); + + return range1.compareBoundaryPoints( + goog.global['Range'].START_TO_END, range2); +}; + + +/** + * Utility function to compare the position of two nodes, when + * {@code textNode}'s parent is an ancestor of {@code node}. If this entry + * condition is not met, this function will attempt to reference a null object. + * @param {!Node} textNode The textNode to compare. + * @param {Node} node The node to compare. + * @return {number} -1 if node is before textNode, +1 otherwise. + * @private + */ +goog.dom.compareParentsDescendantNodeIe_ = function(textNode, node) { + var parent = textNode.parentNode; + if (parent == node) { + // If textNode is a child of node, then node comes first. + return -1; + } + var sibling = node; + while (sibling.parentNode != parent) { + sibling = sibling.parentNode; + } + return goog.dom.compareSiblingOrder_(sibling, textNode); +}; + + +/** + * Utility function to compare the position of two nodes known to be non-equal + * siblings. + * @param {Node} node1 The first node to compare. + * @param {!Node} node2 The second node to compare. + * @return {number} -1 if node1 is before node2, +1 otherwise. + * @private + */ +goog.dom.compareSiblingOrder_ = function(node1, node2) { + var s = node2; + while ((s = s.previousSibling)) { + if (s == node1) { + // We just found node1 before node2. + return -1; + } + } + + // Since we didn't find it, node1 must be after node2. + return 1; +}; + + +/** + * Find the deepest common ancestor of the given nodes. + * @param {...Node} var_args The nodes to find a common ancestor of. + * @return {Node} The common ancestor of the nodes, or null if there is none. + * null will only be returned if two or more of the nodes are from different + * documents. + */ +goog.dom.findCommonAncestor = function(var_args) { + var i, count = arguments.length; + if (!count) { + return null; + } else if (count == 1) { + return arguments[0]; + } + + var paths = []; + var minLength = Infinity; + for (i = 0; i < count; i++) { + // Compute the list of ancestors. + var ancestors = []; + var node = arguments[i]; + while (node) { + ancestors.unshift(node); + node = node.parentNode; + } + + // Save the list for comparison. + paths.push(ancestors); + minLength = Math.min(minLength, ancestors.length); + } + var output = null; + for (i = 0; i < minLength; i++) { + var first = paths[0][i]; + for (var j = 1; j < count; j++) { + if (first != paths[j][i]) { + return output; + } + } + output = first; + } + return output; +}; + + +/** + * Returns the owner document for a node. + * @param {Node|Window} node The node to get the document for. + * @return {!Document} The document owning the node. + */ +goog.dom.getOwnerDocument = function(node) { + // TODO(nnaze): Update param signature to be non-nullable. + goog.asserts.assert(node, 'Node cannot be null or undefined.'); + return /** @type {!Document} */ ( + node.nodeType == goog.dom.NodeType.DOCUMENT ? node : node.ownerDocument || + node.document); +}; + + +/** + * Cross-browser function for getting the document element of a frame or iframe. + * @param {Element} frame Frame element. + * @return {!Document} The frame content document. + */ +goog.dom.getFrameContentDocument = function(frame) { + return frame.contentDocument || + /** @type {!HTMLFrameElement} */ (frame).contentWindow.document; +}; + + +/** + * Cross-browser function for getting the window of a frame or iframe. + * @param {Element} frame Frame element. + * @return {Window} The window associated with the given frame, or null if none + * exists. + */ +goog.dom.getFrameContentWindow = function(frame) { + try { + return frame.contentWindow || + (frame.contentDocument ? goog.dom.getWindow(frame.contentDocument) : + null); + } catch (e) { + // NOTE(user): In IE8, checking the contentWindow or contentDocument + // properties will throw a "Unspecified Error" exception if the iframe is + // not inserted in the DOM. If we get this we can be sure that no window + // exists, so return null. + } + return null; +}; + + +/** + * Sets the text content of a node, with cross-browser support. + * @param {Node} node The node to change the text content of. + * @param {string|number} text The value that should replace the node's content. + */ +goog.dom.setTextContent = function(node, text) { + goog.asserts.assert( + node != null, + 'goog.dom.setTextContent expects a non-null value for node'); + + if ('textContent' in node) { + node.textContent = text; + } else if (node.nodeType == goog.dom.NodeType.TEXT) { + /** @type {!Text} */ (node).data = String(text); + } else if ( + node.firstChild && node.firstChild.nodeType == goog.dom.NodeType.TEXT) { + // If the first child is a text node we just change its data and remove the + // rest of the children. + while (node.lastChild != node.firstChild) { + node.removeChild(node.lastChild); + } + /** @type {!Text} */ (node.firstChild).data = String(text); + } else { + goog.dom.removeChildren(node); + var doc = goog.dom.getOwnerDocument(node); + node.appendChild(doc.createTextNode(String(text))); + } +}; + + +/** + * Gets the outerHTML of a node, which islike innerHTML, except that it + * actually contains the HTML of the node itself. + * @param {Element} element The element to get the HTML of. + * @return {string} The outerHTML of the given element. + */ +goog.dom.getOuterHtml = function(element) { + goog.asserts.assert( + element !== null, + 'goog.dom.getOuterHtml expects a non-null value for element'); + // IE, Opera and WebKit all have outerHTML. + if ('outerHTML' in element) { + return element.outerHTML; + } else { + var doc = goog.dom.getOwnerDocument(element); + var div = goog.dom.createElement_(doc, goog.dom.TagName.DIV); + div.appendChild(element.cloneNode(true)); + return div.innerHTML; + } +}; + + +/** + * Finds the first descendant node that matches the filter function, using + * a depth first search. This function offers the most general purpose way + * of finding a matching element. You may also wish to consider + * {@code goog.dom.query} which can express many matching criteria using + * CSS selector expressions. These expressions often result in a more + * compact representation of the desired result. + * @see goog.dom.query + * + * @param {Node} root The root of the tree to search. + * @param {function(Node) : boolean} p The filter function. + * @return {Node|undefined} The found node or undefined if none is found. + */ +goog.dom.findNode = function(root, p) { + var rv = []; + var found = goog.dom.findNodes_(root, p, rv, true); + return found ? rv[0] : undefined; +}; + + +/** + * Finds all the descendant nodes that match the filter function, using a + * a depth first search. This function offers the most general-purpose way + * of finding a set of matching elements. You may also wish to consider + * {@code goog.dom.query} which can express many matching criteria using + * CSS selector expressions. These expressions often result in a more + * compact representation of the desired result. + + * @param {Node} root The root of the tree to search. + * @param {function(Node) : boolean} p The filter function. + * @return {!Array<!Node>} The found nodes or an empty array if none are found. + */ +goog.dom.findNodes = function(root, p) { + var rv = []; + goog.dom.findNodes_(root, p, rv, false); + return rv; +}; + + +/** + * Finds the first or all the descendant nodes that match the filter function, + * using a depth first search. + * @param {Node} root The root of the tree to search. + * @param {function(Node) : boolean} p The filter function. + * @param {!Array<!Node>} rv The found nodes are added to this array. + * @param {boolean} findOne If true we exit after the first found node. + * @return {boolean} Whether the search is complete or not. True in case findOne + * is true and the node is found. False otherwise. + * @private + */ +goog.dom.findNodes_ = function(root, p, rv, findOne) { + if (root != null) { + var child = root.firstChild; + while (child) { + if (p(child)) { + rv.push(child); + if (findOne) { + return true; + } + } + if (goog.dom.findNodes_(child, p, rv, findOne)) { + return true; + } + child = child.nextSibling; + } + } + return false; +}; + + +/** + * Map of tags whose content to ignore when calculating text length. + * @private {!Object<string, number>} + * @const + */ +goog.dom.TAGS_TO_IGNORE_ = { + 'SCRIPT': 1, + 'STYLE': 1, + 'HEAD': 1, + 'IFRAME': 1, + 'OBJECT': 1 +}; + + +/** + * Map of tags which have predefined values with regard to whitespace. + * @private {!Object<string, string>} + * @const + */ +goog.dom.PREDEFINED_TAG_VALUES_ = { + 'IMG': ' ', + 'BR': '\n' +}; + + +/** + * Returns true if the element has a tab index that allows it to receive + * keyboard focus (tabIndex >= 0), false otherwise. Note that some elements + * natively support keyboard focus, even if they have no tab index. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element has a tab index that allows keyboard + * focus. + */ +goog.dom.isFocusableTabIndex = function(element) { + return goog.dom.hasSpecifiedTabIndex_(element) && + goog.dom.isTabIndexFocusable_(element); +}; + + +/** + * Enables or disables keyboard focus support on the element via its tab index. + * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true + * (or elements that natively support keyboard focus, like form elements) can + * receive keyboard focus. See http://go/tabindex for more info. + * @param {Element} element Element whose tab index is to be changed. + * @param {boolean} enable Whether to set or remove a tab index on the element + * that supports keyboard focus. + */ +goog.dom.setFocusableTabIndex = function(element, enable) { + if (enable) { + element.tabIndex = 0; + } else { + // Set tabIndex to -1 first, then remove it. This is a workaround for + // Safari (confirmed in version 4 on Windows). When removing the attribute + // without setting it to -1 first, the element remains keyboard focusable + // despite not having a tabIndex attribute anymore. + element.tabIndex = -1; + element.removeAttribute('tabIndex'); // Must be camelCase! + } +}; + + +/** + * Returns true if the element can be focused, i.e. it has a tab index that + * allows it to receive keyboard focus (tabIndex >= 0), or it is an element + * that natively supports keyboard focus. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element allows keyboard focus. + */ +goog.dom.isFocusable = function(element) { + var focusable; + // Some elements can have unspecified tab index and still receive focus. + if (goog.dom.nativelySupportsFocus_(element)) { + // Make sure the element is not disabled ... + focusable = !element.disabled && + // ... and if a tab index is specified, it allows focus. + (!goog.dom.hasSpecifiedTabIndex_(element) || + goog.dom.isTabIndexFocusable_(element)); + } else { + focusable = goog.dom.isFocusableTabIndex(element); + } + + // IE requires elements to be visible in order to focus them. + return focusable && goog.userAgent.IE ? + goog.dom.hasNonZeroBoundingRect_(/** @type {!HTMLElement} */ (element)) : + focusable; +}; + + +/** + * Returns true if the element has a specified tab index. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element has a specified tab index. + * @private + */ +goog.dom.hasSpecifiedTabIndex_ = function(element) { + // IE8 and below don't support hasAttribute(), instead check whether the + // 'tabindex' attributeNode is specified. Otherwise check hasAttribute(). + if (goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('9')) { + var attrNode = element.getAttributeNode('tabindex'); // Must be lowercase! + return goog.isDefAndNotNull(attrNode) && attrNode.specified; + } else { + return element.hasAttribute('tabindex'); + } +}; + + +/** + * Returns true if the element's tab index allows the element to be focused. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element's tab index allows focus. + * @private + */ +goog.dom.isTabIndexFocusable_ = function(element) { + var index = /** @type {!HTMLElement} */ (element).tabIndex; + // NOTE: IE9 puts tabIndex in 16-bit int, e.g. -2 is 65534. + return goog.isNumber(index) && index >= 0 && index < 32768; +}; + + +/** + * Returns true if the element is focusable even when tabIndex is not set. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element natively supports focus. + * @private + */ +goog.dom.nativelySupportsFocus_ = function(element) { + return element.tagName == goog.dom.TagName.A || + element.tagName == goog.dom.TagName.INPUT || + element.tagName == goog.dom.TagName.TEXTAREA || + element.tagName == goog.dom.TagName.SELECT || + element.tagName == goog.dom.TagName.BUTTON; +}; + + +/** + * Returns true if the element has a bounding rectangle that would be visible + * (i.e. its width and height are greater than zero). + * @param {!HTMLElement} element Element to check. + * @return {boolean} Whether the element has a non-zero bounding rectangle. + * @private + */ +goog.dom.hasNonZeroBoundingRect_ = function(element) { + var rect; + if (!goog.isFunction(element['getBoundingClientRect']) || + // In IE, getBoundingClientRect throws on detached nodes. + (goog.userAgent.IE && element.parentElement == null)) { + rect = {'height': element.offsetHeight, 'width': element.offsetWidth}; + } else { + rect = element.getBoundingClientRect(); + } + return goog.isDefAndNotNull(rect) && rect.height > 0 && rect.width > 0; +}; + + +/** + * Returns the text content of the current node, without markup and invisible + * symbols. New lines are stripped and whitespace is collapsed, + * such that each character would be visible. + * + * In browsers that support it, innerText is used. Other browsers attempt to + * simulate it via node traversal. Line breaks are canonicalized in IE. + * + * @param {Node} node The node from which we are getting content. + * @return {string} The text content. + */ +goog.dom.getTextContent = function(node) { + var textContent; + // Note(arv): IE9, Opera, and Safari 3 support innerText but they include + // text nodes in script tags. So we revert to use a user agent test here. + if (goog.dom.BrowserFeature.CAN_USE_INNER_TEXT && node !== null && + ('innerText' in node)) { + textContent = goog.string.canonicalizeNewlines(node.innerText); + // Unfortunately .innerText() returns text with ­ symbols + // We need to filter it out and then remove duplicate whitespaces + } else { + var buf = []; + goog.dom.getTextContent_(node, buf, true); + textContent = buf.join(''); + } + + // Strip ­ entities. goog.format.insertWordBreaks inserts them in Opera. + textContent = textContent.replace(/ \xAD /g, ' ').replace(/\xAD/g, ''); + // Strip ​ entities. goog.format.insertWordBreaks inserts them in IE8. + textContent = textContent.replace(/\u200B/g, ''); + + // Skip this replacement on old browsers with working innerText, which + // automatically turns into ' ' and / +/ into ' ' when reading + // innerText. + if (!goog.dom.BrowserFeature.CAN_USE_INNER_TEXT) { + textContent = textContent.replace(/ +/g, ' '); + } + if (textContent != ' ') { + textContent = textContent.replace(/^\s*/, ''); + } + + return textContent; +}; + + +/** + * Returns the text content of the current node, without markup. + * + * Unlike {@code getTextContent} this method does not collapse whitespaces + * or normalize lines breaks. + * + * @param {Node} node The node from which we are getting content. + * @return {string} The raw text content. + */ +goog.dom.getRawTextContent = function(node) { + var buf = []; + goog.dom.getTextContent_(node, buf, false); + + return buf.join(''); +}; + + +/** + * Recursive support function for text content retrieval. + * + * @param {Node} node The node from which we are getting content. + * @param {Array<string>} buf string buffer. + * @param {boolean} normalizeWhitespace Whether to normalize whitespace. + * @private + */ +goog.dom.getTextContent_ = function(node, buf, normalizeWhitespace) { + if (node.nodeName in goog.dom.TAGS_TO_IGNORE_) { + // ignore certain tags + } else if (node.nodeType == goog.dom.NodeType.TEXT) { + if (normalizeWhitespace) { + buf.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, '')); + } else { + buf.push(node.nodeValue); + } + } else if (node.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) { + buf.push(goog.dom.PREDEFINED_TAG_VALUES_[node.nodeName]); + } else { + var child = node.firstChild; + while (child) { + goog.dom.getTextContent_(child, buf, normalizeWhitespace); + child = child.nextSibling; + } + } +}; + + +/** + * Returns the text length of the text contained in a node, without markup. This + * is equivalent to the selection length if the node was selected, or the number + * of cursor movements to traverse the node. Images & BRs take one space. New + * lines are ignored. + * + * @param {Node} node The node whose text content length is being calculated. + * @return {number} The length of {@code node}'s text content. + */ +goog.dom.getNodeTextLength = function(node) { + return goog.dom.getTextContent(node).length; +}; + + +/** + * Returns the text offset of a node relative to one of its ancestors. The text + * length is the same as the length calculated by goog.dom.getNodeTextLength. + * + * @param {Node} node The node whose offset is being calculated. + * @param {Node=} opt_offsetParent The node relative to which the offset will + * be calculated. Defaults to the node's owner document's body. + * @return {number} The text offset. + */ +goog.dom.getNodeTextOffset = function(node, opt_offsetParent) { + var root = opt_offsetParent || goog.dom.getOwnerDocument(node).body; + var buf = []; + while (node && node != root) { + var cur = node; + while ((cur = cur.previousSibling)) { + buf.unshift(goog.dom.getTextContent(cur)); + } + node = node.parentNode; + } + // Trim left to deal with FF cases when there might be line breaks and empty + // nodes at the front of the text + return goog.string.trimLeft(buf.join('')).replace(/ +/g, ' ').length; +}; + + +/** + * Returns the node at a given offset in a parent node. If an object is + * provided for the optional third parameter, the node and the remainder of the + * offset will stored as properties of this object. + * @param {Node} parent The parent node. + * @param {number} offset The offset into the parent node. + * @param {Object=} opt_result Object to be used to store the return value. The + * return value will be stored in the form {node: Node, remainder: number} + * if this object is provided. + * @return {Node} The node at the given offset. + */ +goog.dom.getNodeAtOffset = function(parent, offset, opt_result) { + var stack = [parent], pos = 0, cur = null; + while (stack.length > 0 && pos < offset) { + cur = stack.pop(); + if (cur.nodeName in goog.dom.TAGS_TO_IGNORE_) { + // ignore certain tags + } else if (cur.nodeType == goog.dom.NodeType.TEXT) { + var text = cur.nodeValue.replace(/(\r\n|\r|\n)/g, '').replace(/ +/g, ' '); + pos += text.length; + } else if (cur.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) { + pos += goog.dom.PREDEFINED_TAG_VALUES_[cur.nodeName].length; + } else { + for (var i = cur.childNodes.length - 1; i >= 0; i--) { + stack.push(cur.childNodes[i]); + } + } + } + if (goog.isObject(opt_result)) { + opt_result.remainder = cur ? cur.nodeValue.length + offset - pos - 1 : 0; + opt_result.node = cur; + } + + return cur; +}; + + +/** + * Returns true if the object is a {@code NodeList}. To qualify as a NodeList, + * the object must have a numeric length property and an item function (which + * has type 'string' on IE for some reason). + * @param {Object} val Object to test. + * @return {boolean} Whether the object is a NodeList. + */ +goog.dom.isNodeList = function(val) { + // TODO(attila): Now the isNodeList is part of goog.dom we can use + // goog.userAgent to make this simpler. + // A NodeList must have a length property of type 'number' on all platforms. + if (val && typeof val.length == 'number') { + // A NodeList is an object everywhere except Safari, where it's a function. + if (goog.isObject(val)) { + // A NodeList must have an item function (on non-IE platforms) or an item + // property of type 'string' (on IE). + return typeof val.item == 'function' || typeof val.item == 'string'; + } else if (goog.isFunction(val)) { + // On Safari, a NodeList is a function with an item property that is also + // a function. + return typeof val.item == 'function'; + } + } + + // Not a NodeList. + return false; +}; + + +/** + * Walks up the DOM hierarchy returning the first ancestor that has the passed + * tag name and/or class name. If the passed element matches the specified + * criteria, the element itself is returned. + * @param {Node} element The DOM node to start with. + * @param {?(goog.dom.TagName<T>|string)=} opt_tag The tag name to match (or + * null/undefined to match only based on class name). + * @param {?string=} opt_class The class name to match (or null/undefined to + * match only based on tag name). + * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the + * dom. + * @return {?R} The first ancestor that matches the passed criteria, or + * null if no match is found. The return type is {?Element} if opt_tag is + * not a member of goog.dom.TagName or a more specific type if it is (e.g. + * {?HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.getAncestorByTagNameAndClass = function( + element, opt_tag, opt_class, opt_maxSearchSteps) { + if (!opt_tag && !opt_class) { + return null; + } + var tagName = opt_tag ? String(opt_tag).toUpperCase() : null; + return /** @type {Element} */ (goog.dom.getAncestor(element, function(node) { + return (!tagName || node.nodeName == tagName) && + (!opt_class || + goog.isString(node.className) && + goog.array.contains(node.className.split(/\s+/), opt_class)); + }, true, opt_maxSearchSteps)); +}; + + +/** + * Walks up the DOM hierarchy returning the first ancestor that has the passed + * class name. If the passed element matches the specified criteria, the + * element itself is returned. + * @param {Node} element The DOM node to start with. + * @param {string} className The class name to match. + * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the + * dom. + * @return {Element} The first ancestor that matches the passed criteria, or + * null if none match. + */ +goog.dom.getAncestorByClass = function(element, className, opt_maxSearchSteps) { + return goog.dom.getAncestorByTagNameAndClass( + element, null, className, opt_maxSearchSteps); +}; + + +/** + * Walks up the DOM hierarchy returning the first ancestor that passes the + * matcher function. + * @param {Node} element The DOM node to start with. + * @param {function(Node) : boolean} matcher A function that returns true if the + * passed node matches the desired criteria. + * @param {boolean=} opt_includeNode If true, the node itself is included in + * the search (the first call to the matcher will pass startElement as + * the node to test). + * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the + * dom. + * @return {Node} DOM node that matched the matcher, or null if there was + * no match. + */ +goog.dom.getAncestor = function( + element, matcher, opt_includeNode, opt_maxSearchSteps) { + if (element && !opt_includeNode) { + element = element.parentNode; + } + var steps = 0; + while (element && + (opt_maxSearchSteps == null || steps <= opt_maxSearchSteps)) { + goog.asserts.assert(element.name != 'parentNode'); + if (matcher(element)) { + return element; + } + element = element.parentNode; + steps++; + } + // Reached the root of the DOM without a match + return null; +}; + + +/** + * Determines the active element in the given document. + * @param {Document} doc The document to look in. + * @return {Element} The active element. + */ +goog.dom.getActiveElement = function(doc) { + try { + return doc && doc.activeElement; + } catch (e) { + // NOTE(nicksantos): Sometimes, evaluating document.activeElement in IE + // throws an exception. I'm not 100% sure why, but I suspect it chokes + // on document.activeElement if the activeElement has been recently + // removed from the DOM by a JS operation. + // + // We assume that an exception here simply means + // "there is no active element." + } + + return null; +}; + + +/** + * Gives the current devicePixelRatio. + * + * By default, this is the value of window.devicePixelRatio (which should be + * preferred if present). + * + * If window.devicePixelRatio is not present, the ratio is calculated with + * window.matchMedia, if present. Otherwise, gives 1.0. + * + * Some browsers (including Chrome) consider the browser zoom level in the pixel + * ratio, so the value may change across multiple calls. + * + * @return {number} The number of actual pixels per virtual pixel. + */ +goog.dom.getPixelRatio = function() { + var win = goog.dom.getWindow(); + if (goog.isDef(win.devicePixelRatio)) { + return win.devicePixelRatio; + } else if (win.matchMedia) { + // Should be for IE10 and FF6-17 (this basically clamps to lower) + // Note that the order of these statements is important + return goog.dom.matchesPixelRatio_(3) || goog.dom.matchesPixelRatio_(2) || + goog.dom.matchesPixelRatio_(1.5) || goog.dom.matchesPixelRatio_(1) || + .75; + } + return 1; +}; + + +/** + * Calculates a mediaQuery to check if the current device supports the + * given actual to virtual pixel ratio. + * @param {number} pixelRatio The ratio of actual pixels to virtual pixels. + * @return {number} pixelRatio if applicable, otherwise 0. + * @private + */ +goog.dom.matchesPixelRatio_ = function(pixelRatio) { + var win = goog.dom.getWindow(); + /** + * Due to the 1:96 fixed ratio of CSS in to CSS px, 1dppx is equivalent to + * 96dpi. + * @const {number} + */ + var dpiPerDppx = 96; + var query = + // FF16-17 + '(min-resolution: ' + pixelRatio + 'dppx),' + + // FF6-15 + '(min--moz-device-pixel-ratio: ' + pixelRatio + '),' + + // IE10 (this works for the two browsers above too but I don't want to + // trust the 1:96 fixed ratio magic) + '(min-resolution: ' + (pixelRatio * dpiPerDppx) + 'dpi)'; + return win.matchMedia(query).matches ? pixelRatio : 0; +}; + + +/** + * Gets '2d' context of a canvas. Shortcut for canvas.getContext('2d') with a + * type information. + * @param {!HTMLCanvasElement} canvas + * @return {!CanvasRenderingContext2D} + */ +goog.dom.getCanvasContext2D = function(canvas) { + return /** @type {!CanvasRenderingContext2D} */ (canvas.getContext('2d')); +}; + + + +/** + * Create an instance of a DOM helper with a new document object. + * @param {Document=} opt_document Document object to associate with this + * DOM helper. + * @constructor + */ +goog.dom.DomHelper = function(opt_document) { + /** + * Reference to the document object to use + * @type {!Document} + * @private + */ + this.document_ = opt_document || goog.global.document || document; +}; + + +/** + * Gets the dom helper object for the document where the element resides. + * @param {Node=} opt_node If present, gets the DomHelper for this node. + * @return {!goog.dom.DomHelper} The DomHelper. + */ +goog.dom.DomHelper.prototype.getDomHelper = goog.dom.getDomHelper; + + +/** + * Sets the document object. + * @param {!Document} document Document object. + */ +goog.dom.DomHelper.prototype.setDocument = function(document) { + this.document_ = document; +}; + + +/** + * Gets the document object being used by the dom library. + * @return {!Document} Document object. + */ +goog.dom.DomHelper.prototype.getDocument = function() { + return this.document_; +}; + + +/** + * Alias for {@code getElementById}. If a DOM node is passed in then we just + * return that. + * @param {string|Element} element Element ID or a DOM node. + * @return {Element} The element with the given ID, or the node passed in. + */ +goog.dom.DomHelper.prototype.getElement = function(element) { + return goog.dom.getElementHelper_(this.document_, element); +}; + + +/** + * Gets an element by id, asserting that the element is found. + * + * This is used when an element is expected to exist, and should fail with + * an assertion error if it does not (if assertions are enabled). + * + * @param {string} id Element ID. + * @return {!Element} The element with the given ID, if it exists. + */ +goog.dom.DomHelper.prototype.getRequiredElement = function(id) { + return goog.dom.getRequiredElementHelper_(this.document_, id); +}; + + +/** + * Alias for {@code getElement}. + * @param {string|Element} element Element ID or a DOM node. + * @return {Element} The element with the given ID, or the node passed in. + * @deprecated Use {@link goog.dom.DomHelper.prototype.getElement} instead. + */ +goog.dom.DomHelper.prototype.$ = goog.dom.DomHelper.prototype.getElement; + + +/** + * Gets elements by tag name. + * @param {!goog.dom.TagName<T>} tagName + * @param {(!Document|!Element)=} opt_parent Parent element or document where to + * look for elements. Defaults to document of this DomHelper. + * @return {!NodeList<R>} List of elements. The members of the list are + * {!Element} if tagName is not a member of goog.dom.TagName or more + * specific types if it is (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.getElementsByTagName = + function(tagName, opt_parent) { + var parent = opt_parent || this.document_; + return parent.getElementsByTagName(String(tagName)); +}; + + +/** + * Looks up elements by both tag and class name, using browser native functions + * ({@code querySelectorAll}, {@code getElementsByTagName} or + * {@code getElementsByClassName}) where possible. The returned array is a live + * NodeList or a static list depending on the code path taken. + * + * @see goog.dom.query + * + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name or * for all + * tags. + * @param {?string=} opt_class Optional class name. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {!IArrayLike<R>} Array-like list of elements (only a length property + * and numerical indices are guaranteed to exist). The members of the array + * are {!Element} if opt_tag is not a member of goog.dom.TagName or more + * specific types if it is (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.getElementsByTagNameAndClass = function( + opt_tag, opt_class, opt_el) { + return goog.dom.getElementsByTagNameAndClass_( + this.document_, opt_tag, opt_class, opt_el); +}; + + +/** + * Gets the first element matching the tag and the class. + * + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {(Document|Element)=} opt_el Optional element to look in. + * @return {?R} Reference to a DOM node. The return type is {?Element} if + * tagName is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {?HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.getElementByTagNameAndClass = function( + opt_tag, opt_class, opt_el) { + return goog.dom.getElementByTagNameAndClass_( + this.document_, opt_tag, opt_class, opt_el); +}; + + +/** + * Returns an array of all the elements with the provided className. + * @see {goog.dom.query} + * @param {string} className the name of the class to look for. + * @param {Element|Document=} opt_el Optional element to look in. + * @return {!IArrayLike<!Element>} The items found with the class name provided. + */ +goog.dom.DomHelper.prototype.getElementsByClass = function(className, opt_el) { + var doc = opt_el || this.document_; + return goog.dom.getElementsByClass(className, doc); +}; + + +/** + * Returns the first element we find matching the provided class name. + * @see {goog.dom.query} + * @param {string} className the name of the class to look for. + * @param {(Element|Document)=} opt_el Optional element to look in. + * @return {Element} The first item found with the class name provided. + */ +goog.dom.DomHelper.prototype.getElementByClass = function(className, opt_el) { + var doc = opt_el || this.document_; + return goog.dom.getElementByClass(className, doc); +}; + + +/** + * Ensures an element with the given className exists, and then returns the + * first element with the provided className. + * @see {goog.dom.query} + * @param {string} className the name of the class to look for. + * @param {(!Element|!Document)=} opt_root Optional element or document to look + * in. + * @return {!Element} The first item found with the class name provided. + * @throws {goog.asserts.AssertionError} Thrown if no element is found. + */ +goog.dom.DomHelper.prototype.getRequiredElementByClass = function( + className, opt_root) { + var root = opt_root || this.document_; + return goog.dom.getRequiredElementByClass(className, root); +}; + + +/** + * Alias for {@code getElementsByTagNameAndClass}. + * @deprecated Use DomHelper getElementsByTagNameAndClass. + * @see goog.dom.query + * + * @param {(string|?goog.dom.TagName<T>)=} opt_tag Element tag name. + * @param {?string=} opt_class Optional class name. + * @param {Element=} opt_el Optional element to look in. + * @return {!IArrayLike<R>} Array-like list of elements (only a length property + * and numerical indices are guaranteed to exist). The members of the array + * are {!Element} if opt_tag is a string or more specific types if it is + * a member of goog.dom.TagName (e.g. {!HTMLAnchorElement} for + * goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.$$ = + goog.dom.DomHelper.prototype.getElementsByTagNameAndClass; + + +/** + * Sets a number of properties on a node. + * @param {Element} element DOM node to set properties on. + * @param {Object} properties Hash of property:value pairs. + */ +goog.dom.DomHelper.prototype.setProperties = goog.dom.setProperties; + + +/** + * Gets the dimensions of the viewport. + * @param {Window=} opt_window Optional window element to test. Defaults to + * the window of the Dom Helper. + * @return {!goog.math.Size} Object with values 'width' and 'height'. + */ +goog.dom.DomHelper.prototype.getViewportSize = function(opt_window) { + // TODO(arv): This should not take an argument. That breaks the rule of a + // a DomHelper representing a single frame/window/document. + return goog.dom.getViewportSize(opt_window || this.getWindow()); +}; + + +/** + * Calculates the height of the document. + * + * @return {number} The height of the document. + */ +goog.dom.DomHelper.prototype.getDocumentHeight = function() { + return goog.dom.getDocumentHeight_(this.getWindow()); +}; + + +/** + * Typedef for use with goog.dom.createDom and goog.dom.append. + * @typedef {Object|string|Array|NodeList} + */ +goog.dom.Appendable; + + +/** + * Returns a dom node with a set of attributes. This function accepts varargs + * for subsequent nodes to be added. Subsequent nodes will be added to the + * first node as childNodes. + * + * So: + * <code>createDom(goog.dom.TagName.DIV, null, createDom(goog.dom.TagName.P), + * createDom(goog.dom.TagName.P));</code> would return a div with two child + * paragraphs + * + * An easy way to move all child nodes of an existing element to a new parent + * element is: + * <code>createDom(goog.dom.TagName.DIV, null, oldElement.childNodes);</code> + * which will remove all child nodes from the old element and add them as + * child nodes of the new DIV. + * + * @param {string|!goog.dom.TagName<T>} tagName Tag to create. + * @param {?Object|?Array<string>|string=} opt_attributes If object, then a map + * of name-value pairs for attributes. If a string, then this is the + * className of the new element. If an array, the elements will be joined + * together as the className of the new element. + * @param {...goog.dom.Appendable} var_args Further DOM nodes or + * strings for text nodes. If one of the var_args is an array or + * NodeList, its elements will be added as childNodes instead. + * @return {R} Reference to a DOM node. The return type is {!Element} if tagName + * is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.createDom = function( + tagName, opt_attributes, var_args) { + return goog.dom.createDom_(this.document_, arguments); +}; + + +/** + * Alias for {@code createDom}. + * @param {string|!goog.dom.TagName<T>} tagName Tag to create. + * @param {?Object|?Array<string>|string=} opt_attributes If object, then a map + * of name-value pairs for attributes. If a string, then this is the + * className of the new element. If an array, the elements will be joined + * together as the className of the new element. + * @param {...goog.dom.Appendable} var_args Further DOM nodes or strings for + * text nodes. If one of the var_args is an array, its children will be + * added as childNodes instead. + * @return {R} Reference to a DOM node. The return type is {!Element} if tagName + * is a string or a more specific type if it is a member of + * goog.dom.TagName (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + * @deprecated Use {@link goog.dom.DomHelper.prototype.createDom} instead. + */ +goog.dom.DomHelper.prototype.$dom = goog.dom.DomHelper.prototype.createDom; + + +/** + * Creates a new element. + * @param {string|!goog.dom.TagName<T>} name Tag to create. + * @return {R} The new element. The return type is {!Element} if name is + * a string or a more specific type if it is a member of goog.dom.TagName + * (e.g. {!HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.createElement = function(name) { + return goog.dom.createElement_(this.document_, name); +}; + + +/** + * Creates a new text node. + * @param {number|string} content Content. + * @return {!Text} The new text node. + */ +goog.dom.DomHelper.prototype.createTextNode = function(content) { + return this.document_.createTextNode(String(content)); +}; + + +/** + * Create a table. + * @param {number} rows The number of rows in the table. Must be >= 1. + * @param {number} columns The number of columns in the table. Must be >= 1. + * @param {boolean=} opt_fillWithNbsp If true, fills table entries with + * {@code goog.string.Unicode.NBSP} characters. + * @return {!HTMLElement} The created table. + */ +goog.dom.DomHelper.prototype.createTable = function( + rows, columns, opt_fillWithNbsp) { + return goog.dom.createTable_( + this.document_, rows, columns, !!opt_fillWithNbsp); +}; + + +/** + * Converts an HTML into a node or a document fragment. A single Node is used if + * {@code html} only generates a single node. If {@code html} generates multiple + * nodes then these are put inside a {@code DocumentFragment}. This is a safe + * version of {@code goog.dom.DomHelper#htmlToDocumentFragment} which is now + * deleted. + * @param {!goog.html.SafeHtml} html The HTML markup to convert. + * @return {!Node} The resulting node. + */ +goog.dom.DomHelper.prototype.safeHtmlToNode = function(html) { + return goog.dom.safeHtmlToNode_(this.document_, html); +}; + + +/** + * Returns true if the browser is in "CSS1-compatible" (standards-compliant) + * mode, false otherwise. + * @return {boolean} True if in CSS1-compatible mode. + */ +goog.dom.DomHelper.prototype.isCss1CompatMode = function() { + return goog.dom.isCss1CompatMode_(this.document_); +}; + + +/** + * Gets the window object associated with the document. + * @return {!Window} The window associated with the given document. + */ +goog.dom.DomHelper.prototype.getWindow = function() { + return goog.dom.getWindow_(this.document_); +}; + + +/** + * Gets the document scroll element. + * @return {!Element} Scrolling element. + */ +goog.dom.DomHelper.prototype.getDocumentScrollElement = function() { + return goog.dom.getDocumentScrollElement_(this.document_); +}; + + +/** + * Gets the document scroll distance as a coordinate object. + * @return {!goog.math.Coordinate} Object with properties 'x' and 'y'. + */ +goog.dom.DomHelper.prototype.getDocumentScroll = function() { + return goog.dom.getDocumentScroll_(this.document_); +}; + + +/** + * Determines the active element in the given document. + * @param {Document=} opt_doc The document to look in. + * @return {Element} The active element. + */ +goog.dom.DomHelper.prototype.getActiveElement = function(opt_doc) { + return goog.dom.getActiveElement(opt_doc || this.document_); +}; + + +/** + * Appends a child to a node. + * @param {Node} parent Parent. + * @param {Node} child Child. + */ +goog.dom.DomHelper.prototype.appendChild = goog.dom.appendChild; + + +/** + * Appends a node with text or other nodes. + * @param {!Node} parent The node to append nodes to. + * @param {...goog.dom.Appendable} var_args The things to append to the node. + * If this is a Node it is appended as is. + * If this is a string then a text node is appended. + * If this is an array like object then fields 0 to length - 1 are appended. + */ +goog.dom.DomHelper.prototype.append = goog.dom.append; + + +/** + * Determines if the given node can contain children, intended to be used for + * HTML generation. + * + * @param {Node} node The node to check. + * @return {boolean} Whether the node can contain children. + */ +goog.dom.DomHelper.prototype.canHaveChildren = goog.dom.canHaveChildren; + + +/** + * Removes all the child nodes on a DOM node. + * @param {Node} node Node to remove children from. + */ +goog.dom.DomHelper.prototype.removeChildren = goog.dom.removeChildren; + + +/** + * Inserts a new node before an existing reference node (i.e., as the previous + * sibling). If the reference node has no parent, then does nothing. + * @param {Node} newNode Node to insert. + * @param {Node} refNode Reference node to insert before. + */ +goog.dom.DomHelper.prototype.insertSiblingBefore = goog.dom.insertSiblingBefore; + + +/** + * Inserts a new node after an existing reference node (i.e., as the next + * sibling). If the reference node has no parent, then does nothing. + * @param {Node} newNode Node to insert. + * @param {Node} refNode Reference node to insert after. + */ +goog.dom.DomHelper.prototype.insertSiblingAfter = goog.dom.insertSiblingAfter; + + +/** + * Insert a child at a given index. If index is larger than the number of child + * nodes that the parent currently has, the node is inserted as the last child + * node. + * @param {Element} parent The element into which to insert the child. + * @param {Node} child The element to insert. + * @param {number} index The index at which to insert the new child node. Must + * not be negative. + */ +goog.dom.DomHelper.prototype.insertChildAt = goog.dom.insertChildAt; + + +/** + * Removes a node from its parent. + * @param {Node} node The node to remove. + * @return {Node} The node removed if removed; else, null. + */ +goog.dom.DomHelper.prototype.removeNode = goog.dom.removeNode; + + +/** + * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no + * parent. + * @param {Node} newNode Node to insert. + * @param {Node} oldNode Node to replace. + */ +goog.dom.DomHelper.prototype.replaceNode = goog.dom.replaceNode; + + +/** + * Flattens an element. That is, removes it and replace it with its children. + * @param {Element} element The element to flatten. + * @return {Element|undefined} The original element, detached from the document + * tree, sans children, or undefined if the element was already not in the + * document. + */ +goog.dom.DomHelper.prototype.flattenElement = goog.dom.flattenElement; + + +/** + * Returns an array containing just the element children of the given element. + * @param {Element} element The element whose element children we want. + * @return {!(Array<!Element>|NodeList<!Element>)} An array or array-like list + * of just the element children of the given element. + */ +goog.dom.DomHelper.prototype.getChildren = goog.dom.getChildren; + + +/** + * Returns the first child node that is an element. + * @param {Node} node The node to get the first child element of. + * @return {Element} The first child node of {@code node} that is an element. + */ +goog.dom.DomHelper.prototype.getFirstElementChild = + goog.dom.getFirstElementChild; + + +/** + * Returns the last child node that is an element. + * @param {Node} node The node to get the last child element of. + * @return {Element} The last child node of {@code node} that is an element. + */ +goog.dom.DomHelper.prototype.getLastElementChild = goog.dom.getLastElementChild; + + +/** + * Returns the first next sibling that is an element. + * @param {Node} node The node to get the next sibling element of. + * @return {Element} The next sibling of {@code node} that is an element. + */ +goog.dom.DomHelper.prototype.getNextElementSibling = + goog.dom.getNextElementSibling; + + +/** + * Returns the first previous sibling that is an element. + * @param {Node} node The node to get the previous sibling element of. + * @return {Element} The first previous sibling of {@code node} that is + * an element. + */ +goog.dom.DomHelper.prototype.getPreviousElementSibling = + goog.dom.getPreviousElementSibling; + + +/** + * Returns the next node in source order from the given node. + * @param {Node} node The node. + * @return {Node} The next node in the DOM tree, or null if this was the last + * node. + */ +goog.dom.DomHelper.prototype.getNextNode = goog.dom.getNextNode; + + +/** + * Returns the previous node in source order from the given node. + * @param {Node} node The node. + * @return {Node} The previous node in the DOM tree, or null if this was the + * first node. + */ +goog.dom.DomHelper.prototype.getPreviousNode = goog.dom.getPreviousNode; + + +/** + * Whether the object looks like a DOM node. + * @param {?} obj The object being tested for node likeness. + * @return {boolean} Whether the object looks like a DOM node. + */ +goog.dom.DomHelper.prototype.isNodeLike = goog.dom.isNodeLike; + + +/** + * Whether the object looks like an Element. + * @param {?} obj The object being tested for Element likeness. + * @return {boolean} Whether the object looks like an Element. + */ +goog.dom.DomHelper.prototype.isElement = goog.dom.isElement; + + +/** + * Returns true if the specified value is a Window object. This includes the + * global window for HTML pages, and iframe windows. + * @param {?} obj Variable to test. + * @return {boolean} Whether the variable is a window. + */ +goog.dom.DomHelper.prototype.isWindow = goog.dom.isWindow; + + +/** + * Returns an element's parent, if it's an Element. + * @param {Element} element The DOM element. + * @return {Element} The parent, or null if not an Element. + */ +goog.dom.DomHelper.prototype.getParentElement = goog.dom.getParentElement; + + +/** + * Whether a node contains another node. + * @param {Node} parent The node that should contain the other node. + * @param {Node} descendant The node to test presence of. + * @return {boolean} Whether the parent node contains the descendent node. + */ +goog.dom.DomHelper.prototype.contains = goog.dom.contains; + + +/** + * Compares the document order of two nodes, returning 0 if they are the same + * node, a negative number if node1 is before node2, and a positive number if + * node2 is before node1. Note that we compare the order the tags appear in the + * document so in the tree <b><i>text</i></b> the B node is considered to be + * before the I node. + * + * @param {Node} node1 The first node to compare. + * @param {Node} node2 The second node to compare. + * @return {number} 0 if the nodes are the same node, a negative number if node1 + * is before node2, and a positive number if node2 is before node1. + */ +goog.dom.DomHelper.prototype.compareNodeOrder = goog.dom.compareNodeOrder; + + +/** + * Find the deepest common ancestor of the given nodes. + * @param {...Node} var_args The nodes to find a common ancestor of. + * @return {Node} The common ancestor of the nodes, or null if there is none. + * null will only be returned if two or more of the nodes are from different + * documents. + */ +goog.dom.DomHelper.prototype.findCommonAncestor = goog.dom.findCommonAncestor; + + +/** + * Returns the owner document for a node. + * @param {Node} node The node to get the document for. + * @return {!Document} The document owning the node. + */ +goog.dom.DomHelper.prototype.getOwnerDocument = goog.dom.getOwnerDocument; + + +/** + * Cross browser function for getting the document element of an iframe. + * @param {Element} iframe Iframe element. + * @return {!Document} The frame content document. + */ +goog.dom.DomHelper.prototype.getFrameContentDocument = + goog.dom.getFrameContentDocument; + + +/** + * Cross browser function for getting the window of a frame or iframe. + * @param {Element} frame Frame element. + * @return {Window} The window associated with the given frame. + */ +goog.dom.DomHelper.prototype.getFrameContentWindow = + goog.dom.getFrameContentWindow; + + +/** + * Sets the text content of a node, with cross-browser support. + * @param {Node} node The node to change the text content of. + * @param {string|number} text The value that should replace the node's content. + */ +goog.dom.DomHelper.prototype.setTextContent = goog.dom.setTextContent; + + +/** + * Gets the outerHTML of a node, which islike innerHTML, except that it + * actually contains the HTML of the node itself. + * @param {Element} element The element to get the HTML of. + * @return {string} The outerHTML of the given element. + */ +goog.dom.DomHelper.prototype.getOuterHtml = goog.dom.getOuterHtml; + + +/** + * Finds the first descendant node that matches the filter function. This does + * a depth first search. + * @param {Node} root The root of the tree to search. + * @param {function(Node) : boolean} p The filter function. + * @return {Node|undefined} The found node or undefined if none is found. + */ +goog.dom.DomHelper.prototype.findNode = goog.dom.findNode; + + +/** + * Finds all the descendant nodes that matches the filter function. This does a + * depth first search. + * @param {Node} root The root of the tree to search. + * @param {function(Node) : boolean} p The filter function. + * @return {Array<Node>} The found nodes or an empty array if none are found. + */ +goog.dom.DomHelper.prototype.findNodes = goog.dom.findNodes; + + +/** + * Returns true if the element has a tab index that allows it to receive + * keyboard focus (tabIndex >= 0), false otherwise. Note that some elements + * natively support keyboard focus, even if they have no tab index. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element has a tab index that allows keyboard + * focus. + */ +goog.dom.DomHelper.prototype.isFocusableTabIndex = goog.dom.isFocusableTabIndex; + + +/** + * Enables or disables keyboard focus support on the element via its tab index. + * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true + * (or elements that natively support keyboard focus, like form elements) can + * receive keyboard focus. See http://go/tabindex for more info. + * @param {Element} element Element whose tab index is to be changed. + * @param {boolean} enable Whether to set or remove a tab index on the element + * that supports keyboard focus. + */ +goog.dom.DomHelper.prototype.setFocusableTabIndex = + goog.dom.setFocusableTabIndex; + + +/** + * Returns true if the element can be focused, i.e. it has a tab index that + * allows it to receive keyboard focus (tabIndex >= 0), or it is an element + * that natively supports keyboard focus. + * @param {!Element} element Element to check. + * @return {boolean} Whether the element allows keyboard focus. + */ +goog.dom.DomHelper.prototype.isFocusable = goog.dom.isFocusable; + + +/** + * Returns the text contents of the current node, without markup. New lines are + * stripped and whitespace is collapsed, such that each character would be + * visible. + * + * In browsers that support it, innerText is used. Other browsers attempt to + * simulate it via node traversal. Line breaks are canonicalized in IE. + * + * @param {Node} node The node from which we are getting content. + * @return {string} The text content. + */ +goog.dom.DomHelper.prototype.getTextContent = goog.dom.getTextContent; + + +/** + * Returns the text length of the text contained in a node, without markup. This + * is equivalent to the selection length if the node was selected, or the number + * of cursor movements to traverse the node. Images & BRs take one space. New + * lines are ignored. + * + * @param {Node} node The node whose text content length is being calculated. + * @return {number} The length of {@code node}'s text content. + */ +goog.dom.DomHelper.prototype.getNodeTextLength = goog.dom.getNodeTextLength; + + +/** + * Returns the text offset of a node relative to one of its ancestors. The text + * length is the same as the length calculated by + * {@code goog.dom.getNodeTextLength}. + * + * @param {Node} node The node whose offset is being calculated. + * @param {Node=} opt_offsetParent Defaults to the node's owner document's body. + * @return {number} The text offset. + */ +goog.dom.DomHelper.prototype.getNodeTextOffset = goog.dom.getNodeTextOffset; + + +/** + * Returns the node at a given offset in a parent node. If an object is + * provided for the optional third parameter, the node and the remainder of the + * offset will stored as properties of this object. + * @param {Node} parent The parent node. + * @param {number} offset The offset into the parent node. + * @param {Object=} opt_result Object to be used to store the return value. The + * return value will be stored in the form {node: Node, remainder: number} + * if this object is provided. + * @return {Node} The node at the given offset. + */ +goog.dom.DomHelper.prototype.getNodeAtOffset = goog.dom.getNodeAtOffset; + + +/** + * Returns true if the object is a {@code NodeList}. To qualify as a NodeList, + * the object must have a numeric length property and an item function (which + * has type 'string' on IE for some reason). + * @param {Object} val Object to test. + * @return {boolean} Whether the object is a NodeList. + */ +goog.dom.DomHelper.prototype.isNodeList = goog.dom.isNodeList; + + +/** + * Walks up the DOM hierarchy returning the first ancestor that has the passed + * tag name and/or class name. If the passed element matches the specified + * criteria, the element itself is returned. + * @param {Node} element The DOM node to start with. + * @param {?(goog.dom.TagName<T>|string)=} opt_tag The tag name to match (or + * null/undefined to match only based on class name). + * @param {?string=} opt_class The class name to match (or null/undefined to + * match only based on tag name). + * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the + * dom. + * @return {?R} The first ancestor that matches the passed criteria, or + * null if no match is found. The return type is {?Element} if opt_tag is + * not a member of goog.dom.TagName or a more specific type if it is (e.g. + * {?HTMLAnchorElement} for goog.dom.TagName.A). + * @template T + * @template R := cond(isUnknown(T), 'Element', T) =: + */ +goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass = + goog.dom.getAncestorByTagNameAndClass; + + +/** + * Walks up the DOM hierarchy returning the first ancestor that has the passed + * class name. If the passed element matches the specified criteria, the + * element itself is returned. + * @param {Node} element The DOM node to start with. + * @param {string} class The class name to match. + * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the + * dom. + * @return {Element} The first ancestor that matches the passed criteria, or + * null if none match. + */ +goog.dom.DomHelper.prototype.getAncestorByClass = goog.dom.getAncestorByClass; + + +/** + * Walks up the DOM hierarchy returning the first ancestor that passes the + * matcher function. + * @param {Node} element The DOM node to start with. + * @param {function(Node) : boolean} matcher A function that returns true if the + * passed node matches the desired criteria. + * @param {boolean=} opt_includeNode If true, the node itself is included in + * the search (the first call to the matcher will pass startElement as + * the node to test). + * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the + * dom. + * @return {Node} DOM node that matched the matcher, or null if there was + * no match. + */ +goog.dom.DomHelper.prototype.getAncestor = goog.dom.getAncestor; + + +/** + * Gets '2d' context of a canvas. Shortcut for canvas.getContext('2d') with a + * type information. + * @param {!HTMLCanvasElement} canvas + * @return {!CanvasRenderingContext2D} + */ +goog.dom.DomHelper.prototype.getCanvasContext2D = goog.dom.getCanvasContext2D; diff --git a/static/src/assets/viz/2/goog/dom/htmlelement.js b/static/src/assets/viz/2/goog/dom/htmlelement.js new file mode 100644 index 0000000..c48f753 --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/htmlelement.js @@ -0,0 +1,29 @@ +// Copyright 2017 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +goog.provide('goog.dom.HtmlElement'); + + + +/** + * This subclass of HTMLElement is used when only a HTMLElement is possible and + * not any of its subclasses. Normally, a type can refer to an instance of + * itself or an instance of any subtype. More concretely, if HTMLElement is used + * then the compiler must assume that it might still be e.g. HTMLScriptElement. + * With this, the type check knows that it couldn't be any special element. + * + * @constructor + * @extends {HTMLElement} + */ +goog.dom.HtmlElement = function() {}; diff --git a/static/src/assets/viz/2/goog/dom/nodetype.js b/static/src/assets/viz/2/goog/dom/nodetype.js new file mode 100644 index 0000000..cccb470 --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/nodetype.js @@ -0,0 +1,48 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of goog.dom.NodeType. + */ + +goog.provide('goog.dom.NodeType'); + + +/** + * Constants for the nodeType attribute in the Node interface. + * + * These constants match those specified in the Node interface. These are + * usually present on the Node object in recent browsers, but not in older + * browsers (specifically, early IEs) and thus are given here. + * + * In some browsers (early IEs), these are not defined on the Node object, + * so they are provided here. + * + * See http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247 + * @enum {number} + */ +goog.dom.NodeType = { + ELEMENT: 1, + ATTRIBUTE: 2, + TEXT: 3, + CDATA_SECTION: 4, + ENTITY_REFERENCE: 5, + ENTITY: 6, + PROCESSING_INSTRUCTION: 7, + COMMENT: 8, + DOCUMENT: 9, + DOCUMENT_TYPE: 10, + DOCUMENT_FRAGMENT: 11, + NOTATION: 12 +}; diff --git a/static/src/assets/viz/2/goog/dom/safe.js b/static/src/assets/viz/2/goog/dom/safe.js new file mode 100644 index 0000000..b9390a0 --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/safe.js @@ -0,0 +1,458 @@ +// Copyright 2013 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Type-safe wrappers for unsafe DOM APIs. + * + * This file provides type-safe wrappers for DOM APIs that can result in + * cross-site scripting (XSS) vulnerabilities, if the API is supplied with + * untrusted (attacker-controlled) input. Instead of plain strings, the type + * safe wrappers consume values of types from the goog.html package whose + * contract promises that values are safe to use in the corresponding context. + * + * Hence, a program that exclusively uses the wrappers in this file (i.e., whose + * only reference to security-sensitive raw DOM APIs are in this file) is + * guaranteed to be free of XSS due to incorrect use of such DOM APIs (modulo + * correctness of code that produces values of the respective goog.html types, + * and absent code that violates type safety). + * + * For example, assigning to an element's .innerHTML property a string that is + * derived (even partially) from untrusted input typically results in an XSS + * vulnerability. The type-safe wrapper goog.dom.safe.setInnerHtml consumes a + * value of type goog.html.SafeHtml, whose contract states that using its values + * in a HTML context will not result in XSS. Hence a program that is free of + * direct assignments to any element's innerHTML property (with the exception of + * the assignment to .innerHTML in this file) is guaranteed to be free of XSS + * due to assignment of untrusted strings to the innerHTML property. + */ + +goog.provide('goog.dom.safe'); +goog.provide('goog.dom.safe.InsertAdjacentHtmlPosition'); + +goog.require('goog.asserts'); +goog.require('goog.dom.asserts'); +goog.require('goog.html.SafeHtml'); +goog.require('goog.html.SafeScript'); +goog.require('goog.html.SafeStyle'); +goog.require('goog.html.SafeUrl'); +goog.require('goog.html.TrustedResourceUrl'); +goog.require('goog.string'); +goog.require('goog.string.Const'); + + +/** @enum {string} */ +goog.dom.safe.InsertAdjacentHtmlPosition = { + AFTERBEGIN: 'afterbegin', + AFTEREND: 'afterend', + BEFOREBEGIN: 'beforebegin', + BEFOREEND: 'beforeend' +}; + + +/** + * Inserts known-safe HTML into a Node, at the specified position. + * @param {!Node} node The node on which to call insertAdjacentHTML. + * @param {!goog.dom.safe.InsertAdjacentHtmlPosition} position Position where + * to insert the HTML. + * @param {!goog.html.SafeHtml} html The known-safe HTML to insert. + */ +goog.dom.safe.insertAdjacentHtml = function(node, position, html) { + node.insertAdjacentHTML(position, goog.html.SafeHtml.unwrap(html)); +}; + + +/** + * Tags not allowed in goog.dom.safe.setInnerHtml. + * @private @const {!Object<string, boolean>} + */ +goog.dom.safe.SET_INNER_HTML_DISALLOWED_TAGS_ = { + 'MATH': true, + 'SCRIPT': true, + 'STYLE': true, + 'SVG': true, + 'TEMPLATE': true +}; + + +/** + * Assigns known-safe HTML to an element's innerHTML property. + * @param {!Element} elem The element whose innerHTML is to be assigned to. + * @param {!goog.html.SafeHtml} html The known-safe HTML to assign. + * @throws {Error} If called with one of these tags: math, script, style, svg, + * template. + */ +goog.dom.safe.setInnerHtml = function(elem, html) { + if (goog.asserts.ENABLE_ASSERTS) { + var tagName = elem.tagName.toUpperCase(); + if (goog.dom.safe.SET_INNER_HTML_DISALLOWED_TAGS_[tagName]) { + throw Error( + 'goog.dom.safe.setInnerHtml cannot be used to set content of ' + + elem.tagName + '.'); + } + } + elem.innerHTML = goog.html.SafeHtml.unwrap(html); +}; + + +/** + * Assigns known-safe HTML to an element's outerHTML property. + * @param {!Element} elem The element whose outerHTML is to be assigned to. + * @param {!goog.html.SafeHtml} html The known-safe HTML to assign. + */ +goog.dom.safe.setOuterHtml = function(elem, html) { + elem.outerHTML = goog.html.SafeHtml.unwrap(html); +}; + + +/** + * Sets the given element's style property to the contents of the provided + * SafeStyle object. + * @param {!Element} elem + * @param {!goog.html.SafeStyle} style + */ +goog.dom.safe.setStyle = function(elem, style) { + elem.style.cssText = goog.html.SafeStyle.unwrap(style); +}; + + +/** + * Writes known-safe HTML to a document. + * @param {!Document} doc The document to be written to. + * @param {!goog.html.SafeHtml} html The known-safe HTML to assign. + */ +goog.dom.safe.documentWrite = function(doc, html) { + doc.write(goog.html.SafeHtml.unwrap(html)); +}; + + +/** + * Safely assigns a URL to an anchor element's href property. + * + * If url is of type goog.html.SafeUrl, its value is unwrapped and assigned to + * anchor's href property. If url is of type string however, it is first + * sanitized using goog.html.SafeUrl.sanitize. + * + * Example usage: + * goog.dom.safe.setAnchorHref(anchorEl, url); + * which is a safe alternative to + * anchorEl.href = url; + * The latter can result in XSS vulnerabilities if url is a + * user-/attacker-controlled value. + * + * @param {!HTMLAnchorElement} anchor The anchor element whose href property + * is to be assigned to. + * @param {string|!goog.html.SafeUrl} url The URL to assign. + * @see goog.html.SafeUrl#sanitize + */ +goog.dom.safe.setAnchorHref = function(anchor, url) { + goog.dom.asserts.assertIsHTMLAnchorElement(anchor); + /** @type {!goog.html.SafeUrl} */ + var safeUrl; + if (url instanceof goog.html.SafeUrl) { + safeUrl = url; + } else { + safeUrl = goog.html.SafeUrl.sanitizeAssertUnchanged(url); + } + anchor.href = goog.html.SafeUrl.unwrap(safeUrl); +}; + + +/** + * Safely assigns a URL to an image element's src property. + * + * If url is of type goog.html.SafeUrl, its value is unwrapped and assigned to + * image's src property. If url is of type string however, it is first + * sanitized using goog.html.SafeUrl.sanitize. + * + * @param {!HTMLImageElement} imageElement The image element whose src property + * is to be assigned to. + * @param {string|!goog.html.SafeUrl} url The URL to assign. + * @see goog.html.SafeUrl#sanitize + */ +goog.dom.safe.setImageSrc = function(imageElement, url) { + goog.dom.asserts.assertIsHTMLImageElement(imageElement); + /** @type {!goog.html.SafeUrl} */ + var safeUrl; + if (url instanceof goog.html.SafeUrl) { + safeUrl = url; + } else { + safeUrl = goog.html.SafeUrl.sanitizeAssertUnchanged(url); + } + imageElement.src = goog.html.SafeUrl.unwrap(safeUrl); +}; + + +/** + * Safely assigns a URL to an embed element's src property. + * + * Example usage: + * goog.dom.safe.setEmbedSrc(embedEl, url); + * which is a safe alternative to + * embedEl.src = url; + * The latter can result in loading untrusted code unless it is ensured that + * the URL refers to a trustworthy resource. + * + * @param {!HTMLEmbedElement} embed The embed element whose src property + * is to be assigned to. + * @param {!goog.html.TrustedResourceUrl} url The URL to assign. + */ +goog.dom.safe.setEmbedSrc = function(embed, url) { + goog.dom.asserts.assertIsHTMLEmbedElement(embed); + embed.src = goog.html.TrustedResourceUrl.unwrap(url); +}; + + +/** + * Safely assigns a URL to a frame element's src property. + * + * Example usage: + * goog.dom.safe.setFrameSrc(frameEl, url); + * which is a safe alternative to + * frameEl.src = url; + * The latter can result in loading untrusted code unless it is ensured that + * the URL refers to a trustworthy resource. + * + * @param {!HTMLFrameElement} frame The frame element whose src property + * is to be assigned to. + * @param {!goog.html.TrustedResourceUrl} url The URL to assign. + */ +goog.dom.safe.setFrameSrc = function(frame, url) { + goog.dom.asserts.assertIsHTMLFrameElement(frame); + frame.src = goog.html.TrustedResourceUrl.unwrap(url); +}; + + +/** + * Safely assigns a URL to an iframe element's src property. + * + * Example usage: + * goog.dom.safe.setIframeSrc(iframeEl, url); + * which is a safe alternative to + * iframeEl.src = url; + * The latter can result in loading untrusted code unless it is ensured that + * the URL refers to a trustworthy resource. + * + * @param {!HTMLIFrameElement} iframe The iframe element whose src property + * is to be assigned to. + * @param {!goog.html.TrustedResourceUrl} url The URL to assign. + */ +goog.dom.safe.setIframeSrc = function(iframe, url) { + goog.dom.asserts.assertIsHTMLIFrameElement(iframe); + iframe.src = goog.html.TrustedResourceUrl.unwrap(url); +}; + + +/** + * Safely assigns HTML to an iframe element's srcdoc property. + * + * Example usage: + * goog.dom.safe.setIframeSrcdoc(iframeEl, safeHtml); + * which is a safe alternative to + * iframeEl.srcdoc = html; + * The latter can result in loading untrusted code. + * + * @param {!HTMLIFrameElement} iframe The iframe element whose srcdoc property + * is to be assigned to. + * @param {!goog.html.SafeHtml} html The HTML to assign. + */ +goog.dom.safe.setIframeSrcdoc = function(iframe, html) { + goog.dom.asserts.assertIsHTMLIFrameElement(iframe); + iframe.srcdoc = goog.html.SafeHtml.unwrap(html); +}; + + +/** + * Safely sets a link element's href and rel properties. Whether or not + * the URL assigned to href has to be a goog.html.TrustedResourceUrl + * depends on the value of the rel property. If rel contains "stylesheet" + * then a TrustedResourceUrl is required. + * + * Example usage: + * goog.dom.safe.setLinkHrefAndRel(linkEl, url, 'stylesheet'); + * which is a safe alternative to + * linkEl.rel = 'stylesheet'; + * linkEl.href = url; + * The latter can result in loading untrusted code unless it is ensured that + * the URL refers to a trustworthy resource. + * + * @param {!HTMLLinkElement} link The link element whose href property + * is to be assigned to. + * @param {string|!goog.html.SafeUrl|!goog.html.TrustedResourceUrl} url The URL + * to assign to the href property. Must be a TrustedResourceUrl if the + * value assigned to rel contains "stylesheet". A string value is + * sanitized with goog.html.SafeUrl.sanitize. + * @param {string} rel The value to assign to the rel property. + * @throws {Error} if rel contains "stylesheet" and url is not a + * TrustedResourceUrl + * @see goog.html.SafeUrl#sanitize + */ +goog.dom.safe.setLinkHrefAndRel = function(link, url, rel) { + goog.dom.asserts.assertIsHTMLLinkElement(link); + link.rel = rel; + if (goog.string.caseInsensitiveContains(rel, 'stylesheet')) { + goog.asserts.assert( + url instanceof goog.html.TrustedResourceUrl, + 'URL must be TrustedResourceUrl because "rel" contains "stylesheet"'); + link.href = goog.html.TrustedResourceUrl.unwrap(url); + } else if (url instanceof goog.html.TrustedResourceUrl) { + link.href = goog.html.TrustedResourceUrl.unwrap(url); + } else if (url instanceof goog.html.SafeUrl) { + link.href = goog.html.SafeUrl.unwrap(url); + } else { // string + // SafeUrl.sanitize must return legitimate SafeUrl when passed a string. + link.href = + goog.html.SafeUrl.sanitizeAssertUnchanged(url).getTypedStringValue(); + } +}; + + +/** + * Safely assigns a URL to an object element's data property. + * + * Example usage: + * goog.dom.safe.setObjectData(objectEl, url); + * which is a safe alternative to + * objectEl.data = url; + * The latter can result in loading untrusted code unless setit is ensured that + * the URL refers to a trustworthy resource. + * + * @param {!HTMLObjectElement} object The object element whose data property + * is to be assigned to. + * @param {!goog.html.TrustedResourceUrl} url The URL to assign. + */ +goog.dom.safe.setObjectData = function(object, url) { + goog.dom.asserts.assertIsHTMLObjectElement(object); + object.data = goog.html.TrustedResourceUrl.unwrap(url); +}; + + +/** + * Safely assigns a URL to a script element's src property. + * + * Example usage: + * goog.dom.safe.setScriptSrc(scriptEl, url); + * which is a safe alternative to + * scriptEl.src = url; + * The latter can result in loading untrusted code unless it is ensured that + * the URL refers to a trustworthy resource. + * + * @param {!HTMLScriptElement} script The script element whose src property + * is to be assigned to. + * @param {!goog.html.TrustedResourceUrl} url The URL to assign. + */ +goog.dom.safe.setScriptSrc = function(script, url) { + goog.dom.asserts.assertIsHTMLScriptElement(script); + script.src = goog.html.TrustedResourceUrl.unwrap(url); +}; + + +/** + * Safely assigns a value to a script element's content. + * + * Example usage: + * goog.dom.safe.setScriptContent(scriptEl, content); + * which is a safe alternative to + * scriptEl.text = content; + * The latter can result in executing untrusted code unless it is ensured that + * the code is loaded from a trustworthy resource. + * + * @param {!HTMLScriptElement} script The script element whose content is being + * set. + * @param {!goog.html.SafeScript} content The content to assign. + */ +goog.dom.safe.setScriptContent = function(script, content) { + goog.dom.asserts.assertIsHTMLScriptElement(script); + script.text = goog.html.SafeScript.unwrap(content); +}; + + +/** + * Safely assigns a URL to a Location object's href property. + * + * If url is of type goog.html.SafeUrl, its value is unwrapped and assigned to + * loc's href property. If url is of type string however, it is first sanitized + * using goog.html.SafeUrl.sanitize. + * + * Example usage: + * goog.dom.safe.setLocationHref(document.location, redirectUrl); + * which is a safe alternative to + * document.location.href = redirectUrl; + * The latter can result in XSS vulnerabilities if redirectUrl is a + * user-/attacker-controlled value. + * + * @param {!Location} loc The Location object whose href property is to be + * assigned to. + * @param {string|!goog.html.SafeUrl} url The URL to assign. + * @see goog.html.SafeUrl#sanitize + */ +goog.dom.safe.setLocationHref = function(loc, url) { + goog.dom.asserts.assertIsLocation(loc); + /** @type {!goog.html.SafeUrl} */ + var safeUrl; + if (url instanceof goog.html.SafeUrl) { + safeUrl = url; + } else { + safeUrl = goog.html.SafeUrl.sanitizeAssertUnchanged(url); + } + loc.href = goog.html.SafeUrl.unwrap(safeUrl); +}; + + +/** + * Safely opens a URL in a new window (via window.open). + * + * If url is of type goog.html.SafeUrl, its value is unwrapped and passed in to + * window.open. If url is of type string however, it is first sanitized + * using goog.html.SafeUrl.sanitize. + * + * Note that this function does not prevent leakages via the referer that is + * sent by window.open. It is advised to only use this to open 1st party URLs. + * + * Example usage: + * goog.dom.safe.openInWindow(url); + * which is a safe alternative to + * window.open(url); + * The latter can result in XSS vulnerabilities if redirectUrl is a + * user-/attacker-controlled value. + * + * @param {string|!goog.html.SafeUrl} url The URL to open. + * @param {Window=} opt_openerWin Window of which to call the .open() method. + * Defaults to the global window. + * @param {!goog.string.Const=} opt_name Name of the window to open in. Can be + * _top, etc as allowed by window.open(). + * @param {string=} opt_specs Comma-separated list of specifications, same as + * in window.open(). + * @param {boolean=} opt_replace Whether to replace the current entry in browser + * history, same as in window.open(). + * @return {Window} Window the url was opened in. + */ +goog.dom.safe.openInWindow = function( + url, opt_openerWin, opt_name, opt_specs, opt_replace) { + /** @type {!goog.html.SafeUrl} */ + var safeUrl; + if (url instanceof goog.html.SafeUrl) { + safeUrl = url; + } else { + safeUrl = goog.html.SafeUrl.sanitizeAssertUnchanged(url); + } + var win = opt_openerWin || window; + return win.open( + goog.html.SafeUrl.unwrap(safeUrl), + // If opt_name is undefined, simply passing that in to open() causes IE to + // reuse the current window instead of opening a new one. Thus we pass '' + // in instead, which according to spec opens a new window. See + // https://html.spec.whatwg.org/multipage/browsers.html#dom-open . + opt_name ? goog.string.Const.unwrap(opt_name) : '', opt_specs, + opt_replace); +}; diff --git a/static/src/assets/viz/2/goog/dom/tagname.js b/static/src/assets/viz/2/goog/dom/tagname.js new file mode 100644 index 0000000..b3808ad --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/tagname.js @@ -0,0 +1,562 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Defines the goog.dom.TagName class. Its constants enumerate + * all HTML tag names specified in either the the W3C HTML 4.01 index of + * elements or the HTML5 draft specification. + * + * References: + * http://www.w3.org/TR/html401/index/elements.html + * http://dev.w3.org/html5/spec/section-index.html + */ +goog.provide('goog.dom.TagName'); + +goog.require('goog.dom.HtmlElement'); + + +/** + * A tag name with the type of the element stored in the generic. + * @param {string} tagName + * @constructor + * @template T + */ +goog.dom.TagName = function(tagName) { + /** @private {string} */ + this.tagName_ = tagName; +}; + + +/** + * Returns the tag name. + * @return {string} + * @override + */ +goog.dom.TagName.prototype.toString = function() { + return this.tagName_; +}; + + +// Closure Compiler unconditionally converts the following constants to their +// string value (goog.dom.TagName.A -> 'A'). These are the consequences: +// 1. Don't add any members or static members to goog.dom.TagName as they +// couldn't be accessed after this optimization. +// 2. Keep the constant name and its string value the same: +// goog.dom.TagName.X = new goog.dom.TagName('Y'); +// is converted to 'X', not 'Y'. + + +/** @type {!goog.dom.TagName<!HTMLAnchorElement>} */ +goog.dom.TagName.A = new goog.dom.TagName('A'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.ABBR = new goog.dom.TagName('ABBR'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.ACRONYM = new goog.dom.TagName('ACRONYM'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.ADDRESS = new goog.dom.TagName('ADDRESS'); + + +/** @type {!goog.dom.TagName<!HTMLAppletElement>} */ +goog.dom.TagName.APPLET = new goog.dom.TagName('APPLET'); + + +/** @type {!goog.dom.TagName<!HTMLAreaElement>} */ +goog.dom.TagName.AREA = new goog.dom.TagName('AREA'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.ARTICLE = new goog.dom.TagName('ARTICLE'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.ASIDE = new goog.dom.TagName('ASIDE'); + + +/** @type {!goog.dom.TagName<!HTMLAudioElement>} */ +goog.dom.TagName.AUDIO = new goog.dom.TagName('AUDIO'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.B = new goog.dom.TagName('B'); + + +/** @type {!goog.dom.TagName<!HTMLBaseElement>} */ +goog.dom.TagName.BASE = new goog.dom.TagName('BASE'); + + +/** @type {!goog.dom.TagName<!HTMLBaseFontElement>} */ +goog.dom.TagName.BASEFONT = new goog.dom.TagName('BASEFONT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.BDI = new goog.dom.TagName('BDI'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.BDO = new goog.dom.TagName('BDO'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.BIG = new goog.dom.TagName('BIG'); + + +/** @type {!goog.dom.TagName<!HTMLQuoteElement>} */ +goog.dom.TagName.BLOCKQUOTE = new goog.dom.TagName('BLOCKQUOTE'); + + +/** @type {!goog.dom.TagName<!HTMLBodyElement>} */ +goog.dom.TagName.BODY = new goog.dom.TagName('BODY'); + + +/** @type {!goog.dom.TagName<!HTMLBRElement>} */ +goog.dom.TagName.BR = new goog.dom.TagName('BR'); + + +/** @type {!goog.dom.TagName<!HTMLButtonElement>} */ +goog.dom.TagName.BUTTON = new goog.dom.TagName('BUTTON'); + + +/** @type {!goog.dom.TagName<!HTMLCanvasElement>} */ +goog.dom.TagName.CANVAS = new goog.dom.TagName('CANVAS'); + + +/** @type {!goog.dom.TagName<!HTMLTableCaptionElement>} */ +goog.dom.TagName.CAPTION = new goog.dom.TagName('CAPTION'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.CENTER = new goog.dom.TagName('CENTER'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.CITE = new goog.dom.TagName('CITE'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.CODE = new goog.dom.TagName('CODE'); + + +/** @type {!goog.dom.TagName<!HTMLTableColElement>} */ +goog.dom.TagName.COL = new goog.dom.TagName('COL'); + + +/** @type {!goog.dom.TagName<!HTMLTableColElement>} */ +goog.dom.TagName.COLGROUP = new goog.dom.TagName('COLGROUP'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.COMMAND = new goog.dom.TagName('COMMAND'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.DATA = new goog.dom.TagName('DATA'); + + +/** @type {!goog.dom.TagName<!HTMLDataListElement>} */ +goog.dom.TagName.DATALIST = new goog.dom.TagName('DATALIST'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.DD = new goog.dom.TagName('DD'); + + +/** @type {!goog.dom.TagName<!HTMLModElement>} */ +goog.dom.TagName.DEL = new goog.dom.TagName('DEL'); + + +/** @type {!goog.dom.TagName<!HTMLDetailsElement>} */ +goog.dom.TagName.DETAILS = new goog.dom.TagName('DETAILS'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.DFN = new goog.dom.TagName('DFN'); + + +/** @type {!goog.dom.TagName<!HTMLDialogElement>} */ +goog.dom.TagName.DIALOG = new goog.dom.TagName('DIALOG'); + + +/** @type {!goog.dom.TagName<!HTMLDirectoryElement>} */ +goog.dom.TagName.DIR = new goog.dom.TagName('DIR'); + + +/** @type {!goog.dom.TagName<!HTMLDivElement>} */ +goog.dom.TagName.DIV = new goog.dom.TagName('DIV'); + + +/** @type {!goog.dom.TagName<!HTMLDListElement>} */ +goog.dom.TagName.DL = new goog.dom.TagName('DL'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.DT = new goog.dom.TagName('DT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.EM = new goog.dom.TagName('EM'); + + +/** @type {!goog.dom.TagName<!HTMLEmbedElement>} */ +goog.dom.TagName.EMBED = new goog.dom.TagName('EMBED'); + + +/** @type {!goog.dom.TagName<!HTMLFieldSetElement>} */ +goog.dom.TagName.FIELDSET = new goog.dom.TagName('FIELDSET'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.FIGCAPTION = new goog.dom.TagName('FIGCAPTION'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.FIGURE = new goog.dom.TagName('FIGURE'); + + +/** @type {!goog.dom.TagName<!HTMLFontElement>} */ +goog.dom.TagName.FONT = new goog.dom.TagName('FONT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.FOOTER = new goog.dom.TagName('FOOTER'); + + +/** @type {!goog.dom.TagName<!HTMLFormElement>} */ +goog.dom.TagName.FORM = new goog.dom.TagName('FORM'); + + +/** @type {!goog.dom.TagName<!HTMLFrameElement>} */ +goog.dom.TagName.FRAME = new goog.dom.TagName('FRAME'); + + +/** @type {!goog.dom.TagName<!HTMLFrameSetElement>} */ +goog.dom.TagName.FRAMESET = new goog.dom.TagName('FRAMESET'); + + +/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */ +goog.dom.TagName.H1 = new goog.dom.TagName('H1'); + + +/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */ +goog.dom.TagName.H2 = new goog.dom.TagName('H2'); + + +/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */ +goog.dom.TagName.H3 = new goog.dom.TagName('H3'); + + +/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */ +goog.dom.TagName.H4 = new goog.dom.TagName('H4'); + + +/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */ +goog.dom.TagName.H5 = new goog.dom.TagName('H5'); + + +/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */ +goog.dom.TagName.H6 = new goog.dom.TagName('H6'); + + +/** @type {!goog.dom.TagName<!HTMLHeadElement>} */ +goog.dom.TagName.HEAD = new goog.dom.TagName('HEAD'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.HEADER = new goog.dom.TagName('HEADER'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.HGROUP = new goog.dom.TagName('HGROUP'); + + +/** @type {!goog.dom.TagName<!HTMLHRElement>} */ +goog.dom.TagName.HR = new goog.dom.TagName('HR'); + + +/** @type {!goog.dom.TagName<!HTMLHtmlElement>} */ +goog.dom.TagName.HTML = new goog.dom.TagName('HTML'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.I = new goog.dom.TagName('I'); + + +/** @type {!goog.dom.TagName<!HTMLIFrameElement>} */ +goog.dom.TagName.IFRAME = new goog.dom.TagName('IFRAME'); + + +/** @type {!goog.dom.TagName<!HTMLImageElement>} */ +goog.dom.TagName.IMG = new goog.dom.TagName('IMG'); + + +/** @type {!goog.dom.TagName<!HTMLInputElement>} */ +goog.dom.TagName.INPUT = new goog.dom.TagName('INPUT'); + + +/** @type {!goog.dom.TagName<!HTMLModElement>} */ +goog.dom.TagName.INS = new goog.dom.TagName('INS'); + + +/** @type {!goog.dom.TagName<!HTMLIsIndexElement>} */ +goog.dom.TagName.ISINDEX = new goog.dom.TagName('ISINDEX'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.KBD = new goog.dom.TagName('KBD'); + + +// HTMLKeygenElement is deprecated. +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.KEYGEN = new goog.dom.TagName('KEYGEN'); + + +/** @type {!goog.dom.TagName<!HTMLLabelElement>} */ +goog.dom.TagName.LABEL = new goog.dom.TagName('LABEL'); + + +/** @type {!goog.dom.TagName<!HTMLLegendElement>} */ +goog.dom.TagName.LEGEND = new goog.dom.TagName('LEGEND'); + + +/** @type {!goog.dom.TagName<!HTMLLIElement>} */ +goog.dom.TagName.LI = new goog.dom.TagName('LI'); + + +/** @type {!goog.dom.TagName<!HTMLLinkElement>} */ +goog.dom.TagName.LINK = new goog.dom.TagName('LINK'); + + +/** @type {!goog.dom.TagName<!HTMLMapElement>} */ +goog.dom.TagName.MAP = new goog.dom.TagName('MAP'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.MARK = new goog.dom.TagName('MARK'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.MATH = new goog.dom.TagName('MATH'); + + +/** @type {!goog.dom.TagName<!HTMLMenuElement>} */ +goog.dom.TagName.MENU = new goog.dom.TagName('MENU'); + + +/** @type {!goog.dom.TagName<!HTMLMetaElement>} */ +goog.dom.TagName.META = new goog.dom.TagName('META'); + + +/** @type {!goog.dom.TagName<!HTMLMeterElement>} */ +goog.dom.TagName.METER = new goog.dom.TagName('METER'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.NAV = new goog.dom.TagName('NAV'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.NOFRAMES = new goog.dom.TagName('NOFRAMES'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.NOSCRIPT = new goog.dom.TagName('NOSCRIPT'); + + +/** @type {!goog.dom.TagName<!HTMLObjectElement>} */ +goog.dom.TagName.OBJECT = new goog.dom.TagName('OBJECT'); + + +/** @type {!goog.dom.TagName<!HTMLOListElement>} */ +goog.dom.TagName.OL = new goog.dom.TagName('OL'); + + +/** @type {!goog.dom.TagName<!HTMLOptGroupElement>} */ +goog.dom.TagName.OPTGROUP = new goog.dom.TagName('OPTGROUP'); + + +/** @type {!goog.dom.TagName<!HTMLOptionElement>} */ +goog.dom.TagName.OPTION = new goog.dom.TagName('OPTION'); + + +/** @type {!goog.dom.TagName<!HTMLOutputElement>} */ +goog.dom.TagName.OUTPUT = new goog.dom.TagName('OUTPUT'); + + +/** @type {!goog.dom.TagName<!HTMLParagraphElement>} */ +goog.dom.TagName.P = new goog.dom.TagName('P'); + + +/** @type {!goog.dom.TagName<!HTMLParamElement>} */ +goog.dom.TagName.PARAM = new goog.dom.TagName('PARAM'); + + +/** @type {!goog.dom.TagName<!HTMLPreElement>} */ +goog.dom.TagName.PRE = new goog.dom.TagName('PRE'); + + +/** @type {!goog.dom.TagName<!HTMLProgressElement>} */ +goog.dom.TagName.PROGRESS = new goog.dom.TagName('PROGRESS'); + + +/** @type {!goog.dom.TagName<!HTMLQuoteElement>} */ +goog.dom.TagName.Q = new goog.dom.TagName('Q'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.RP = new goog.dom.TagName('RP'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.RT = new goog.dom.TagName('RT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.RUBY = new goog.dom.TagName('RUBY'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.S = new goog.dom.TagName('S'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SAMP = new goog.dom.TagName('SAMP'); + + +/** @type {!goog.dom.TagName<!HTMLScriptElement>} */ +goog.dom.TagName.SCRIPT = new goog.dom.TagName('SCRIPT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SECTION = new goog.dom.TagName('SECTION'); + + +/** @type {!goog.dom.TagName<!HTMLSelectElement>} */ +goog.dom.TagName.SELECT = new goog.dom.TagName('SELECT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SMALL = new goog.dom.TagName('SMALL'); + + +/** @type {!goog.dom.TagName<!HTMLSourceElement>} */ +goog.dom.TagName.SOURCE = new goog.dom.TagName('SOURCE'); + + +/** @type {!goog.dom.TagName<!HTMLSpanElement>} */ +goog.dom.TagName.SPAN = new goog.dom.TagName('SPAN'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.STRIKE = new goog.dom.TagName('STRIKE'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.STRONG = new goog.dom.TagName('STRONG'); + + +/** @type {!goog.dom.TagName<!HTMLStyleElement>} */ +goog.dom.TagName.STYLE = new goog.dom.TagName('STYLE'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SUB = new goog.dom.TagName('SUB'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SUMMARY = new goog.dom.TagName('SUMMARY'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SUP = new goog.dom.TagName('SUP'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.SVG = new goog.dom.TagName('SVG'); + + +/** @type {!goog.dom.TagName<!HTMLTableElement>} */ +goog.dom.TagName.TABLE = new goog.dom.TagName('TABLE'); + + +/** @type {!goog.dom.TagName<!HTMLTableSectionElement>} */ +goog.dom.TagName.TBODY = new goog.dom.TagName('TBODY'); + + +/** @type {!goog.dom.TagName<!HTMLTableCellElement>} */ +goog.dom.TagName.TD = new goog.dom.TagName('TD'); + + +/** @type {!goog.dom.TagName<!HTMLTemplateElement>} */ +goog.dom.TagName.TEMPLATE = new goog.dom.TagName('TEMPLATE'); + + +/** @type {!goog.dom.TagName<!HTMLTextAreaElement>} */ +goog.dom.TagName.TEXTAREA = new goog.dom.TagName('TEXTAREA'); + + +/** @type {!goog.dom.TagName<!HTMLTableSectionElement>} */ +goog.dom.TagName.TFOOT = new goog.dom.TagName('TFOOT'); + + +/** @type {!goog.dom.TagName<!HTMLTableCellElement>} */ +goog.dom.TagName.TH = new goog.dom.TagName('TH'); + + +/** @type {!goog.dom.TagName<!HTMLTableSectionElement>} */ +goog.dom.TagName.THEAD = new goog.dom.TagName('THEAD'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.TIME = new goog.dom.TagName('TIME'); + + +/** @type {!goog.dom.TagName<!HTMLTitleElement>} */ +goog.dom.TagName.TITLE = new goog.dom.TagName('TITLE'); + + +/** @type {!goog.dom.TagName<!HTMLTableRowElement>} */ +goog.dom.TagName.TR = new goog.dom.TagName('TR'); + + +/** @type {!goog.dom.TagName<!HTMLTrackElement>} */ +goog.dom.TagName.TRACK = new goog.dom.TagName('TRACK'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.TT = new goog.dom.TagName('TT'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.U = new goog.dom.TagName('U'); + + +/** @type {!goog.dom.TagName<!HTMLUListElement>} */ +goog.dom.TagName.UL = new goog.dom.TagName('UL'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.VAR = new goog.dom.TagName('VAR'); + + +/** @type {!goog.dom.TagName<!HTMLVideoElement>} */ +goog.dom.TagName.VIDEO = new goog.dom.TagName('VIDEO'); + + +/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */ +goog.dom.TagName.WBR = new goog.dom.TagName('WBR'); diff --git a/static/src/assets/viz/2/goog/dom/tags.js b/static/src/assets/viz/2/goog/dom/tags.js new file mode 100644 index 0000000..7c12938 --- /dev/null +++ b/static/src/assets/viz/2/goog/dom/tags.js @@ -0,0 +1,41 @@ +// Copyright 2014 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities for HTML element tag names. + */ +goog.provide('goog.dom.tags'); + +goog.require('goog.object'); + + +/** + * The void elements specified by + * http://www.w3.org/TR/html-markup/syntax.html#void-elements. + * @const @private {!Object<string, boolean>} + */ +goog.dom.tags.VOID_TAGS_ = goog.object.createSet( + 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', + 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'); + + +/** + * Checks whether the tag is void (with no contents allowed and no legal end + * tag), for example 'br'. + * @param {string} tagName The tag name in lower case. + * @return {boolean} + */ +goog.dom.tags.isVoidTag = function(tagName) { + return goog.dom.tags.VOID_TAGS_[tagName] === true; +}; |