Util methods to detect vendor prefix for DOM properties and CSS
This commit is contained in:
@@ -1508,6 +1508,88 @@ OpenLayers.Util.getBrowserName = function() {
|
|||||||
return OpenLayers.BROWSER_NAME;
|
return OpenLayers.BROWSER_NAME;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: VENDOR_DOM_PREFIXES
|
||||||
|
* {Array} A list of prefixes to test support for vendor-prefixed properties
|
||||||
|
*/
|
||||||
|
OpenLayers.Util.VENDOR_DOM_PREFIXES = ["", "O", "ms", "Moz", "Webkit"];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getVendorPrefixedCss
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* property - {String} The standard CSS property name
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {String} The CSS property name supported by the browser or null if
|
||||||
|
* unsupported
|
||||||
|
*/
|
||||||
|
OpenLayers.Util.getVendorPrefixedCss = (function() {
|
||||||
|
var cache = {};
|
||||||
|
|
||||||
|
function domToCss(prefixedDom) {
|
||||||
|
return prefixedDom.
|
||||||
|
replace(/([A-Z])/g, function(char) { return "-" + char.toLowerCase(); }).
|
||||||
|
replace(/^ms-/, "-ms-");
|
||||||
|
}
|
||||||
|
|
||||||
|
return function(property) {
|
||||||
|
// clear cache for tests
|
||||||
|
if (property === "clear cache") { cache = {}; return; }
|
||||||
|
|
||||||
|
if (cache[property] === undefined) {
|
||||||
|
var domProperty = property.
|
||||||
|
replace(/(-.)/g, function(c) { return c.charAt(1).toUpperCase(); });
|
||||||
|
var prefixedDom = OpenLayers.Util.getVendorPrefixedDom(domProperty);
|
||||||
|
cache[property] = domToCss(prefixedDom);
|
||||||
|
}
|
||||||
|
return cache[property];
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getVendorPrefixedDom
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* property - {String} The standard DOM property name
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {String} The DOM property name supported by the browser or null if
|
||||||
|
* unsupported
|
||||||
|
*/
|
||||||
|
OpenLayers.Util.getVendorPrefixedDom = (function() {
|
||||||
|
var cache = {};
|
||||||
|
|
||||||
|
return function(property) {
|
||||||
|
// clear cache for tests
|
||||||
|
if (property === "clear cache") { cache = {}; return; }
|
||||||
|
|
||||||
|
if (cache[property] === undefined) {
|
||||||
|
var el = document.createElement("div"),
|
||||||
|
tmpProp,
|
||||||
|
i = 0,
|
||||||
|
l = OpenLayers.Util.VENDOR_DOM_PREFIXES.length,
|
||||||
|
prefix;
|
||||||
|
|
||||||
|
cache[property] = null;
|
||||||
|
for(var i=0,l=OpenLayers.Util.VENDOR_DOM_PREFIXES.length; i<l; i++) {
|
||||||
|
prefix = OpenLayers.Util.VENDOR_DOM_PREFIXES[i];
|
||||||
|
if(prefix) {
|
||||||
|
tmpProp = prefix + property.charAt(0).toUpperCase() + property.slice(1);
|
||||||
|
} else {
|
||||||
|
tmpProp = property;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(el.style[tmpProp] !== undefined) {
|
||||||
|
cache[property] = tmpProp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cache[property];
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: getRenderedDimensions
|
* Method: getRenderedDimensions
|
||||||
* Renders the contentHTML offscreen to determine actual dimensions for
|
* Renders the contentHTML offscreen to determine actual dimensions for
|
||||||
|
|||||||
Reference in New Issue
Block a user