Avoiding unnecessary repeated checks of navigator.userAgent. The constants added here should not be used outside the library. In the future, they should be removed from the library. r=ahocevar (closes #2911)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10868 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-11-03 00:10:00 +00:00
parent 89c215bba4
commit aa9112c494
27 changed files with 91 additions and 81 deletions
+38 -21
View File
@@ -1540,6 +1540,43 @@ OpenLayers.Util.removeTail = function(url) {
return head;
};
/**
* Constant: IS_GECKO
* {Boolean} True if the userAgent reports the browser to use the Gecko engine
*/
OpenLayers.IS_GECKO = (function() {
return navigator.userAgent.toLowerCase().indexOf("gecko") != -1;
})();
/**
* Constant: BROWSER_NAME
* {String}
* A substring of the navigator.userAgent property. Depending on the userAgent
* property, this will be the empty string or one of the following:
* * "opera" -- Opera
* * "msie" -- Internet Explorer
* * "safari" -- Safari
* * "firefox" -- FireFox
* * "mozilla" -- Mozilla
*/
OpenLayers.BROWSER_NAME = (function() {
var name = "";
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("opera") != -1) {
name = "opera";
} else if (ua.indexOf("msie") != -1) {
name = "msie";
} else if (ua.indexOf("safari") != -1) {
name = "safari";
} else if (ua.indexOf("mozilla") != -1) {
if (ua.indexOf("firefox") != -1) {
name = "firefox";
} else {
name = "mozilla";
}
}
return name;
})();
/**
* Function: getBrowserName
@@ -1559,29 +1596,9 @@ OpenLayers.Util.removeTail = function(url) {
* return an empty string.
*/
OpenLayers.Util.getBrowserName = function() {
var browserName = "";
var ua = navigator.userAgent.toLowerCase();
if ( ua.indexOf( "opera" ) != -1 ) {
browserName = "opera";
} else if ( ua.indexOf( "msie" ) != -1 ) {
browserName = "msie";
} else if ( ua.indexOf( "safari" ) != -1 ) {
browserName = "safari";
} else if ( ua.indexOf( "mozilla" ) != -1 ) {
if ( ua.indexOf( "firefox" ) != -1 ) {
browserName = "firefox";
} else {
browserName = "mozilla";
}
}
return browserName;
return OpenLayers.BROWSER_NAME;
};
/**
* Method: getRenderedDimensions
* Renders the contentHTML offscreen to determine actual dimensions for