diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index cfa5ce2517..4c44dbe599 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -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;