Using compiled regexp to replace dots.
Though split and join appear to be more efficient in Chrome, a compiled regexp looks to be a safer bet across the board. See http://jsperf.com/dotless (and http://jsperf.com/dotless-nop for the NOP).
This commit is contained in:
@@ -130,6 +130,17 @@ OpenLayers.Util.indexOf = function(array, obj) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Property: dotless
|
||||
* {RegExp}
|
||||
* Compiled regular expression to match dots ("."). This is used for replacing
|
||||
* dots in identifiers. Because object identifiers are frequently used for
|
||||
* DOM element identifiers by the library, we avoid using dots to make for
|
||||
* more sensible CSS selectors.
|
||||
*
|
||||
* TODO: Use a module pattern to avoid bloating the API with stuff like this.
|
||||
*/
|
||||
OpenLayers.Util.dotless = /\./g;
|
||||
|
||||
/**
|
||||
* Function: modifyDOMElement
|
||||
@@ -158,7 +169,7 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position,
|
||||
border, overflow, opacity) {
|
||||
|
||||
if (id) {
|
||||
element.id = id.replace(/\./g, "_");
|
||||
element.id = id.replace(OpenLayers.Util.dotless, "_");
|
||||
}
|
||||
if (px) {
|
||||
element.style.left = px.x + "px";
|
||||
@@ -939,7 +950,7 @@ OpenLayers.Util.createUniqueID = function(prefix) {
|
||||
if (prefix == null) {
|
||||
prefix = "id_";
|
||||
} else {
|
||||
prefix = prefix.replace(/\./g, "_");
|
||||
prefix = prefix.replace(OpenLayers.Util.dotless, "_");
|
||||
}
|
||||
OpenLayers.Util.lastSeqID += 1;
|
||||
return prefix + OpenLayers.Util.lastSeqID;
|
||||
|
||||
Reference in New Issue
Block a user