diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 491448c9c9..cfa5ce2517 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -139,7 +139,8 @@ OpenLayers.Util.indexOf = function(array, obj) { * * Parameters: * element - {DOMElement} DOM element to modify. - * id - {String} The element id attribute to set. + * id - {String} The element id attribute to set. Note that dots (".") will be + * replaced with underscore ("_") in setting the element id. * px - {|Object} The element left and top position, * OpenLayers.Pixel or an object with * a 'x' and 'y' properties. @@ -157,7 +158,7 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, border, overflow, opacity) { if (id) { - element.id = id; + element.id = id.replace(/\./g, "_"); } if (px) { element.style.left = px.x + "px"; @@ -195,7 +196,8 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, * Parameters: * id - {String} An identifier for this element. If no id is * passed an identifier will be created - * automatically. + * automatically. Note that dots (".") will be replaced with + * underscore ("_") when generating ids. * px - {|Object} The element left and top position, * OpenLayers.Pixel or an object with * a 'x' and 'y' properties. @@ -928,6 +930,7 @@ OpenLayers.Util.lastSeqID = 0; * * Parameters: * prefix - {String} Optional string to prefix unique id. Default is "id_". + * Note that dots (".") in the prefix will be replaced with underscore ("_"). * * Returns: * {String} A unique id string, built on the passed in prefix. @@ -935,6 +938,8 @@ OpenLayers.Util.lastSeqID = 0; OpenLayers.Util.createUniqueID = function(prefix) { if (prefix == null) { prefix = "id_"; + } else { + prefix = prefix.replace(/\./g, "_"); } OpenLayers.Util.lastSeqID += 1; return prefix + OpenLayers.Util.lastSeqID; diff --git a/tests/Feature.html b/tests/Feature.html index 4a50d5143a..aa3db24a3d 100644 --- a/tests/Feature.html +++ b/tests/Feature.html @@ -21,7 +21,7 @@ t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" ); t.eq( feature.layer, layer, "feature.layer set correctly" ); - t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers.Feature_"), + t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers_Feature_"), "feature.id set correctly"); t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" ); t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" ); diff --git a/tests/Geometry.html b/tests/Geometry.html index e61326d34f..6bae0ca16f 100644 --- a/tests/Geometry.html +++ b/tests/Geometry.html @@ -11,7 +11,7 @@ var g = new OpenLayers.Geometry(); t.eq(g.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") - t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry_"), + t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers_Geometry_"), "id correctly set"); } @@ -22,7 +22,7 @@ var clone = geometry.clone(); t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") - t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers.Geometry_"), + t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers_Geometry_"), "id correctly set"); } diff --git a/tests/Popup.html b/tests/Popup.html index 2d6a90b98e..766ac59e0d 100644 --- a/tests/Popup.html +++ b/tests/Popup.html @@ -13,7 +13,7 @@ popup = new OpenLayers.Popup(); t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); - t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"), + t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers_Popup"), "valid default popupid"); var firstID = popup.id; t.ok(popup.contentSize.equals(size), "good default popup.size"); diff --git a/tests/Popup/Anchored.html b/tests/Popup/Anchored.html index f53546b0c0..3197e84655 100644 --- a/tests/Popup/Anchored.html +++ b/tests/Popup/Anchored.html @@ -11,7 +11,7 @@ popup = new OpenLayers.Popup.Anchored(); t.ok( popup instanceof OpenLayers.Popup.Anchored, "new OpenLayers.Popup.Anchored returns Popup.Anchored object" ); - t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup.Anchored"), "valid default popupid"); + t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers_Popup_Anchored"), "valid default popupid"); var firstID = popup.id; t.eq(popup.contentHTML, null, "good default popup.contentHTML");