From 8533edd19bca5612e42e71f630ecf72ea09e633b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 17 Apr 2012 12:03:58 -0400 Subject: [PATCH 1/7] Toward dotless identifiers. --- lib/OpenLayers/Util.js | 11 ++++++++--- tests/Feature.html | 2 +- tests/Geometry.html | 4 ++-- tests/Popup.html | 2 +- tests/Popup/Anchored.html | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) 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"); From 163caf0e8d73cf2e31db8737a9851d62ea1b86be Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 18 Apr 2012 09:16:07 -0400 Subject: [PATCH 2/7] Underscore in canvas hit detection. --- lib/OpenLayers/Renderer/Canvas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Renderer/Canvas.js b/lib/OpenLayers/Renderer/Canvas.js index 7c2421ae96..feca10eef0 100644 --- a/lib/OpenLayers/Renderer/Canvas.js +++ b/lib/OpenLayers/Renderer/Canvas.js @@ -799,7 +799,7 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { if (data[3] === 255) { // antialiased var id = data[2] + (256 * (data[1] + (256 * data[0]))); if (id) { - featureId = "OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow); + featureId = "OpenLayers_Feature_Vector_" + (id - 1 + this.hitOverflow); try { feature = this.features[featureId][0]; } catch(err) { From faaa2cec1fc1edfe1a23feae4e871b3876bb2035 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 18 Apr 2012 09:46:24 -0400 Subject: [PATCH 3/7] 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). --- lib/OpenLayers/Util.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; From ab87c33670be23ec27fcbd9067bf3278f63f60d7 Mon Sep 17 00:00:00 2001 From: John Lien Date: Sun, 22 Apr 2012 14:48:12 -0400 Subject: [PATCH 4/7] Applied patch from ticket #3381 to Permalink tests and updated Permalink control to pass tests by maintaining anchors. All tests continue to pass. --- lib/OpenLayers/Control/Permalink.js | 11 ++++++++-- tests/Control/Permalink.html | 33 ++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Control/Permalink.js b/lib/OpenLayers/Control/Permalink.js index 36545655b3..bf168b04c4 100644 --- a/lib/OpenLayers/Control/Permalink.js +++ b/lib/OpenLayers/Control/Permalink.js @@ -172,11 +172,18 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, { updateLink: function() { var separator = this.anchor ? '#' : '?'; var href = this.base; + var anchor = null; + if (href.indexOf("#") != -1 && this.anchor == false) { + anchor = href.substring( href.indexOf("#"), href.length); + } if (href.indexOf(separator) != -1) { href = href.substring( 0, href.indexOf(separator) ); } - - href += separator + OpenLayers.Util.getParameterString(this.createParams()); + var splits = href.split("#"); + href = splits[0] + separator+ OpenLayers.Util.getParameterString(this.createParams()); + if (anchor) { + href += anchor; + } if (this.anchor && !this.element) { window.location.href = href; } diff --git a/tests/Control/Permalink.html b/tests/Control/Permalink.html index b398adf148..0b729da5bd 100644 --- a/tests/Control/Permalink.html +++ b/tests/Control/Permalink.html @@ -139,7 +139,7 @@ } function test_Control_Permalink_base_with_query (t) { t.plan( 3 ); - + control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar" ); map = new OpenLayers.Map('map'); layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" ); @@ -162,7 +162,38 @@ map.pan(-5, 0, {animate:false}); t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'"); map.destroy(); + } + function test_Control_Permalink_base_with_anchor (t) { + t.plan( 4 ); + control = new OpenLayers.Control.Permalink('permalink', "./edit.html#foo" ); + map = new OpenLayers.Map('map'); + layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" ); + map.addLayer(layer); + if (!map.getCenter()) map.zoomToMaxExtent(); + map.addControl(control); + map.pan(5, 0, {animate:false}); + OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B#foo'; + t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and anchor"); + + control = new OpenLayers.Control.Permalink('permalink', "./edit.html#" ); + map.addControl(control); + map.pan(0, 0, {animate:false}); + OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B#'; + t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and an empty anchor"); + + control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar#test" ); + OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&zoom=2&lat=0&lon=1.75781&layers=B#test'; + map.addControl(control); + map.pan(5, 0, {animate:false}); + map.pan(-5, 0, {animate:false}); + t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base, querystring and an anchor"); + + control = new OpenLayers.Control.Permalink('permalink', "./edit.html#foo", {anchor : true} ); + map.addControl(control); + map.pan(0, 0, {animate:false}); + OpenLayers.Util.getElement('edit_permalink').href = './edit.html#zoom=2&lat=0&lon=1.75781&layers=B'; + t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and an empty anchor"); } function test_Control_Permalink_nonRepeating (t) { From 3b91e4169060c6292dc30d294c7a506970fa4c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Mon, 23 Apr 2012 12:01:55 +0300 Subject: [PATCH 5/7] Mark context property as part of API. It's very useful and is used in examples (at least strategy-cluster-threshold) --- lib/OpenLayers/Style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Style.js b/lib/OpenLayers/Style.js index d33d79d194..3a8206645a 100644 --- a/lib/OpenLayers/Style.js +++ b/lib/OpenLayers/Style.js @@ -61,7 +61,7 @@ OpenLayers.Style = OpenLayers.Class({ rules: null, /** - * Property: context + * APIProperty: context * {Object} An optional object with properties that symbolizers' property * values should be evaluated against. If no context is specified, * feature.attributes will be used From 9a7b8b1cca31370c80765899c6b28b9a7428c49d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 23 Apr 2012 19:25:39 -0400 Subject: [PATCH 6/7] Add a bit to the release notes about dotless identifiers. --- notes/2.13.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 notes/2.13.md diff --git a/notes/2.13.md b/notes/2.13.md new file mode 100644 index 0000000000..c8d0938d6c --- /dev/null +++ b/notes/2.13.md @@ -0,0 +1,9 @@ +# Enhancements and Additions + +## Dotless identifiers + +Previously, objects generated by the library were given id properties with values that contained dots (e.g. "OpenLayers.Control.Navigation_2"). These same identifiers are also used for DOM elements in some case. Though uncommon, a developer may want to access these elements with a CSS selector. To facilitate this, we now always generate ids with underscore instead of dot. + +Corresponding issues/pull requests: + + * https://github.com/openlayers/openlayers/pull/416 From 77cf56a4b67d07ea495b267da33fa8dfcbfa16b9 Mon Sep 17 00:00:00 2001 From: Matt Priour Date: Tue, 24 Apr 2012 22:52:19 -0500 Subject: [PATCH 7/7] Add required OpenLayers.Filter deps to OpenLayers.Format.CQL --- lib/OpenLayers/Format/CQL.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/OpenLayers/Format/CQL.js b/lib/OpenLayers/Format/CQL.js index fa88d2a756..38d92e7f3f 100644 --- a/lib/OpenLayers/Format/CQL.js +++ b/lib/OpenLayers/Format/CQL.js @@ -5,6 +5,9 @@ /** * @requires OpenLayers/Format/WKT.js + * @requires OpenLayers/Filter/Comparison.js + * @requires OpenLayers/Filter/Logical.js + * @requires OpenLayers/Filter/Spatial.js */ /**