1 // Copyright 2012 The Closure Library Authors. All Rights Reserved.
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 at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // 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 and
13 // limitations under the License.
16 * @fileoverview Vendor prefix getters.
19 goog.provide('goog.dom.vendor');
21 goog.require('goog.string');
22 goog.require('goog.userAgent');
26 * Returns the JS vendor prefix used in CSS properties. Different vendors
27 * use different methods of changing the case of the property names.
29 * @return {?string} The JS vendor prefix or null if there is none.
31 goog.dom.vendor.getVendorJsPrefix = function() {
32 if (goog.userAgent.WEBKIT) {
34 } else if (goog.userAgent.GECKO) {
36 } else if (goog.userAgent.IE) {
38 } else if (goog.userAgent.OPERA) {
47 * Returns the vendor prefix used in CSS properties.
49 * @return {?string} The vendor prefix or null if there is none.
51 goog.dom.vendor.getVendorPrefix = function() {
52 if (goog.userAgent.WEBKIT) {
54 } else if (goog.userAgent.GECKO) {
56 } else if (goog.userAgent.IE) {
58 } else if (goog.userAgent.OPERA) {
67 * @param {string} propertyName A property name.
68 * @param {!Object=} opt_object If provided, we verify if the property exists in
70 * @return {?string} A vendor prefixed property name, or null if it does not
73 goog.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) {
78 var prefix = goog.dom.vendor.getVendorJsPrefix();
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;
90 * @param {string} eventType An event type.
91 * @return {string} A lower-cased vendor prefixed event type.
93 goog.dom.vendor.getPrefixedEventType = function(eventType) {
94 var prefix = goog.dom.vendor.getVendorJsPrefix() || '';
95 return (prefix + eventType).toLowerCase();