diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index adaa52a43c..6e3282ddbd 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -7,7 +7,6 @@ */ OpenLayers.Popup = Class.create(); -OpenLayers.Popup.count = 0; OpenLayers.Popup.WIDTH = 200; OpenLayers.Popup.HEIGHT = 200; OpenLayers.Popup.COLOR = "white"; @@ -56,8 +55,11 @@ OpenLayers.Popup.prototype = { * @param {String} contentHTML */ initialize:function(id, lonlat, size, contentHTML) { - OpenLayers.Popup.count += 1; - this.id = (id != null) ? id : "Popup" + OpenLayers.Popup.count; + if (id == null) { + id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); + } + + this.id = id; this.lonlat = lonlat; this.size = (size != null) ? size : new OpenLayers.Size( diff --git a/tests/test_Popup.html b/tests/test_Popup.html index 01d7e17ff5..a717e27f69 100644 --- a/tests/test_Popup.html +++ b/tests/test_Popup.html @@ -12,7 +12,8 @@ popup = new OpenLayers.Popup(); t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); - t.ok(popup.id.startsWith("Popup"), "good default popup.id"); + t.ok(popup.id.startsWith("OpenLayers.Popup"), "valid default popupid"); + var firstID = popup.id; t.ok(popup.size.equals(size), "good default popup.size"); t.eq(popup.contentHTML, "", "good default popup.contentHTML"); t.eq(popup.backgroundColor, OpenLayers.Popup.COLOR, "good default popup.backgroundColor"); @@ -20,12 +21,9 @@ t.eq(popup.border, OpenLayers.Popup.BORDER, "good default popup.border"); - var oldIndex = parseInt(popup.id.slice("Popup".length)); - popup = new OpenLayers.Popup(); - var newIndex = parseInt(popup.id.slice("Popup".length)); - - t.eq(newIndex, oldIndex + 1, "default id generator incrementing correctly"); + var newID = popup.id; + t.ok(newID != firstID, "default id generator creating unique ids"); } function test_02_Popup_constructor (t) {