Path: blob/trunk/third_party/closure/goog/dom/vendor.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Vendor prefix getters.16*/1718goog.provide('goog.dom.vendor');1920goog.require('goog.string');21goog.require('goog.userAgent');222324/**25* Returns the JS vendor prefix used in CSS properties. Different vendors26* use different methods of changing the case of the property names.27*28* @return {?string} The JS vendor prefix or null if there is none.29*/30goog.dom.vendor.getVendorJsPrefix = function() {31if (goog.userAgent.WEBKIT) {32return 'Webkit';33} else if (goog.userAgent.GECKO) {34return 'Moz';35} else if (goog.userAgent.IE) {36return 'ms';37} else if (goog.userAgent.OPERA) {38return 'O';39}4041return null;42};434445/**46* Returns the vendor prefix used in CSS properties.47*48* @return {?string} The vendor prefix or null if there is none.49*/50goog.dom.vendor.getVendorPrefix = function() {51if (goog.userAgent.WEBKIT) {52return '-webkit';53} else if (goog.userAgent.GECKO) {54return '-moz';55} else if (goog.userAgent.IE) {56return '-ms';57} else if (goog.userAgent.OPERA) {58return '-o';59}6061return null;62};636465/**66* @param {string} propertyName A property name.67* @param {!Object=} opt_object If provided, we verify if the property exists in68* the object.69* @return {?string} A vendor prefixed property name, or null if it does not70* exist.71*/72goog.dom.vendor.getPrefixedPropertyName = function(propertyName, opt_object) {73// We first check for a non-prefixed property, if available.74if (opt_object && propertyName in opt_object) {75return propertyName;76}77var prefix = goog.dom.vendor.getVendorJsPrefix();78if (prefix) {79prefix = prefix.toLowerCase();80var prefixedPropertyName = prefix + goog.string.toTitleCase(propertyName);81return (!goog.isDef(opt_object) || prefixedPropertyName in opt_object) ?82prefixedPropertyName :83null;84}85return 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) {94var prefix = goog.dom.vendor.getVendorJsPrefix() || '';95return (prefix + eventType).toLowerCase();96};979899