# lib/goog/dom/vendor.js

    1// Copyright 2012 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415/**16 * @fileoverview Vendor prefix getters.17 */1819goog.provide('goog.dom.vendor');2021goog.require('goog.string');22goog.require('goog.userAgent');232425/**26 * Returns the JS vendor prefix used in CSS properties. Different vendors27 * use different methods of changing the case of the property names.28 *29 * @return {?string} The JS vendor prefix or null if there is none.30 */31goog.dom.vendor.getVendorJsPrefix = function() {32  if (goog.userAgent.WEBKIT) {33    return 'Webkit';34  } else if (goog.userAgent.GECKO) {35    return 'Moz';36  } else if (goog.userAgent.IE) {37    return 'ms';38  } else if (goog.userAgent.OPERA) {39    return 'O';40  }4142  return null;43};444546/**47 * Returns the vendor prefix used in CSS properties.48 *49 * @return {?string} The vendor prefix or null if there is none.50 */51goog.dom.vendor.getVendorPrefix = function() {52  if (goog.userAgent.WEBKIT) {53    return '-webkit';54  } else if (goog.userAgent.GECKO) {55    return '-moz';56  } else if (goog.userAgent.IE) {57    return '-ms';58  } else if (goog.userAgent.OPERA) {59    return '-o';60  }6162  return null;63};646566/**67 * @param {string} propertyName A property name.68 * @param {!Object=} opt_object If provided, we verify if the property exists in69 *     the object.70 * @return {?string} A vendor prefixed property name, or null if it does not71 *     exist.72 */73goog.dom.vendor.getPrefixedPropertyName = function(propertyName, opt_object) {74  // We first check for a non-prefixed property, if available.75  if (opt_object && propertyName in opt_object) {76    return propertyName;77  }78  var prefix = goog.dom.vendor.getVendorJsPrefix();79  if (prefix) {80    prefix = prefix.toLowerCase();81    var prefixedPropertyName = prefix + goog.string.toTitleCase(propertyName);82    return (!goog.isDef(opt_object) || prefixedPropertyName in opt_object) ?83        prefixedPropertyName : null;84  }85  return null;86};878889/**90 * @param {string} eventType An event type.91 * @return {string} A lower-cased vendor prefixed event type.92 */93goog.dom.vendor.getPrefixedEventType = function(eventType) {94  var prefix = goog.dom.vendor.getVendorJsPrefix() || '';95  return (prefix + eventType).toLowerCase();96};