// Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The SFC licenses this file // to you 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 core DOM querying library for the atoms, with a * minimal set of dependencies. Notably, this file should never have a * dependency on CSS libraries such as sizzle. */ goog.provide('bot.dom.core'); goog.require('bot.Error'); goog.require('bot.ErrorCode'); goog.require('bot.userAgent'); goog.require('goog.array'); goog.require('goog.dom'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.TagName'); /** * Get the user-specified value of the given attribute of the element, or null * if the attribute is not present. * *

For boolean attributes such as "selected" or "checked", this method * returns the value of element.getAttribute(attributeName) cast to a String * when attribute is present. For modern browsers, this will be the string the * attribute is given in the HTML, but for IE8 it will be the name of the * attribute, and for IE7, it will be the string "true". To test whether a * boolean attribute is present, test whether the return value is non-null, the * same as one would for non-boolean attributes. Specifically, do *not* test * whether the boolean evaluation of the return value is true, because the value * of a boolean attribute that is present will often be the empty string. * *

For the style attribute, it standardizes the value by lower-casing the * property names and always including a trailing semicolon. * * @param {!Element} element The element to use. * @param {string} attributeName The name of the attribute to return. * @return {?string} The value of the attribute or "null" if entirely missing. */ bot.dom.core.getAttribute = function (element, attributeName) { attributeName = attributeName.toLowerCase(); // The style attribute should be a css text string that includes only what // the HTML element specifies itself (excluding what is inherited from parent // elements or style sheets). We standardize the format of this string via the // standardizeStyleAttribute method. if (attributeName == 'style') { return bot.dom.core.standardizeStyleAttribute_(element.style.cssText); } // In IE doc mode < 8, the "value" attribute of an is only accessible // as a property. if (bot.userAgent.IE_DOC_PRE8 && attributeName == 'value' && bot.dom.core.isElement(element, goog.dom.TagName.INPUT)) { return element['value']; } // In IE < 9, element.getAttributeNode will return null for some boolean // attributes that are present, such as the selected attribute on