From 4447d3c8db6adc3ae25d18836c57b33a00e5cd13 Mon Sep 17 00:00:00 2001 From: Xavier Mamano Date: Tue, 20 Sep 2011 23:13:57 -0400 Subject: [PATCH 1/6] Modify build script to support minimizing with jsmin before passing to closure webservice for closure_ws. (Closes #3422) --- build/build.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/build/build.py b/build/build.py index d91878146f..d688a31e35 100755 --- a/build/build.py +++ b/build/build.py @@ -55,7 +55,20 @@ def build(config_file = None, output_file = None, options = None): elif use_compressor == "minimize": minimized = minimize.minimize(merged) elif use_compressor == "closure_ws": - minimized = closure_ws.minimize(merged) + if len(merged) > 1000000: # The maximum file size for this web service is 1000 KB. + print "\nPre-compressing using jsmin" + merged = jsmin.jsmin(merged) + print "\nIs being compressed using Closure Compiler Service." + try: + minimized = closure_ws.minimize(merged) + except Exception, E: + print "\nAbnormal termination." + sys.exit("ERROR: Closure Compilation using Web service failed!\n%s" % E) + if len(minimized) <= 2: + print "\nAbnormal termination due to compilation errors." + sys.exit("ERROR: Closure Compilation using Web service failed!") + else: + print '\nClosure Compilation using Web service has completed successfully.' elif use_compressor == "closure": minimized = closure.minimize(merged) else: # fallback From 6b30856a072dcfb0351e759a05a3d8477b102779 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Thu, 22 Sep 2011 02:57:39 +0200 Subject: [PATCH 2/6] Give our requests the popular but non-standard X-Requested-With header (r=crschmidt, closes #3491). --- lib/OpenLayers/Request.js | 19 ++++++++++++++ tests/Request.html | 53 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index 6c00d5af77..227af6d82f 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -122,6 +122,25 @@ OpenLayers.Request = { {proxy: OpenLayers.ProxyHost} ); config = OpenLayers.Util.applyDefaults(config, defaultConfig); + + // Always set the "X-Requested-With" header to signal that this request + // was issued through the XHR-object. Since header keys are case + // insensitive and we want to allow overriding of the "X-Requested-With" + // header through the user we cannot use applyDefaults, but have to + // check manually whether we were called with a "X-Requested-With" + // header. + var customRequestedWithHeader = false; + for(headerKey in config.headers) { + if (config.headers.hasOwnProperty( headerKey )) { + if (headerKey.toLowerCase() === 'x-requested-with') { + customRequestedWithHeader = true; + } + } + } + if (customRequestedWithHeader === false) { + // we did not have a custom "X-Requested-With" header + config.headers['X-Requested-With'] = 'XMLHttpRequest'; + } // create request, open, and set headers var request = new OpenLayers.Request.XMLHttpRequest(); diff --git a/tests/Request.html b/tests/Request.html index 52643e450d..29ced665ae 100644 --- a/tests/Request.html +++ b/tests/Request.html @@ -20,7 +20,7 @@ function test_issue(t) { setup(); - t.plan(22); + t.plan(25); var request, config; var proto = OpenLayers.Request.XMLHttpRequest.prototype; var issue = OpenLayers.Function.bind(OpenLayers.Request.issue, @@ -96,19 +96,35 @@ // reset open method proto.open = _open; - // test that headers are correctly set - 4 tests + // test that headers are correctly set - 6 tests var _setRequestHeader = proto.setRequestHeader; config = { headers: { foo: "bar", - chicken: "soup" + chicken: "soup", + // This checks whether the autoadded 'X-Requested-With'-header + // can be overridden, even though the given key here is spelled + // in lowercase. + 'x-requested-with': 'humpty' } }; + // we also track how often setRequestHeader is being called, it should + // be called once for every header, even with the above defined + // custom 'x-requested-with' header which we usually autoadd. + // If the numbers match, we make sure to not send duplicate headers like + // x-requested-with: humpty AND + // X-Requested-With: XMLHttpRequest + var actualSetHeaderCnt = 0; + var expectedSetHeaderCnt = 3; // and not four! proto.setRequestHeader = function(key, value) { + actualSetHeaderCnt++; t.ok(key in config.headers, "setRequestHeader called with key: " + key); t.eq(value, config.headers[key], "setRequestHeader called with correct value: " + value); - } + }; request = issue(config); + + t.eq(actualSetHeaderCnt, expectedSetHeaderCnt, 'A custom "x-requested-with" header overrides the default "X-Requested-With" header.'); + proto.setRequestHeader = _setRequestHeader; // test that callback is called (no scope) - 1 test @@ -444,6 +460,35 @@ var req = OpenLayers.Request.GET(); req.abort(); } + + function test_XRequestedWithHeaderAutoadded(t) { + t.plan( 2 ); + + var headerSet = false; + var headerGot = ''; + var headerExpected = 'XMLHttpRequest'; + + // save to be able to restore later + var _setRequestHeader = OpenLayers.Request.XMLHttpRequest.prototype.setRequestHeader; + + OpenLayers.Request.XMLHttpRequest.prototype.setRequestHeader = function(field, value) { + if (field === 'X-Requested-With') { + headerSet = true; + headerGot = value; + } + }; + + var req = OpenLayers.Request.issue({ + url: location.href, + async: false + }); + + t.ok( headerSet, 'We call the method "setRequestHeader" to set a "X-Requested-With"-header' ); + t.eq( headerGot, headerExpected, 'The "X-Requested-With"-header is set to "' + headerExpected + '" as expected.' ); + + // restore old setRequestHeader + OpenLayers.Request.XMLHttpRequest.prototype.setRequestHeader = _setRequestHeader; + } From 8bcbb069b56c3a810a94c55224e726a13d3096a2 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Thu, 22 Sep 2011 04:52:35 +0200 Subject: [PATCH 3/6] Remove global variable 'headerKey', no functional change. --- lib/OpenLayers/Request.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index 227af6d82f..3a5865bc0a 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -129,7 +129,8 @@ OpenLayers.Request = { // header through the user we cannot use applyDefaults, but have to // check manually whether we were called with a "X-Requested-With" // header. - var customRequestedWithHeader = false; + var customRequestedWithHeader = false, + headerKey; for(headerKey in config.headers) { if (config.headers.hasOwnProperty( headerKey )) { if (headerKey.toLowerCase() === 'x-requested-with') { From 807b0eabaa825af2c6627fdcf422ff2da2e61ea0 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 23 Sep 2011 14:44:23 +0200 Subject: [PATCH 4/6] cannot draw a label with value 0, r=fredj (closes #3258) --- lib/OpenLayers/Style.js | 2 +- tests/Style.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Style.js b/lib/OpenLayers/Style.js index 302a9f2e15..55ed81e0c9 100644 --- a/lib/OpenLayers/Style.js +++ b/lib/OpenLayers/Style.js @@ -191,7 +191,7 @@ OpenLayers.Style = OpenLayers.Class({ style.display = "none"; } - if (style.label && typeof style.label !== "string") { + if (style.label != null && typeof style.label !== "string") { style.label = String(style.label); } diff --git a/tests/Style.html b/tests/Style.html index 2c3a18b176..0b8b33b467 100644 --- a/tests/Style.html +++ b/tests/Style.html @@ -176,9 +176,9 @@ // c) test that label in returned symbolizer is a string even if property value is a number var symbolizer = style.createSymbolizer( - new OpenLayers.Feature.Vector(null, {foo: "bar", labelValue: 10}) + new OpenLayers.Feature.Vector(null, {foo: "bar", labelValue: 0}) ); - t.eq(symbolizer.label, "10", "c) feature property cast to string when used as symbolizer label"); + t.eq(symbolizer.label, "0", "c) feature property cast to string when used as symbolizer label"); } From a46489db1aedfd94dc188dd4acc1ba8e699d9321 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 23 Sep 2011 14:47:07 +0200 Subject: [PATCH 5/6] DragFeature control should trigger afterfeaturemodified, r=crschmidt (closes #3277) --- lib/OpenLayers/Control/DragFeature.js | 28 +++++++++++++++++++++++---- tests/Control/DragFeature.html | 11 +++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/OpenLayers/Control/DragFeature.js b/lib/OpenLayers/Control/DragFeature.js index 012ac76142..d84d6f7738 100644 --- a/lib/OpenLayers/Control/DragFeature.js +++ b/lib/OpenLayers/Control/DragFeature.js @@ -26,10 +26,14 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { * send a list of strings corresponding to the geometry class names. */ geometryTypes: null, - + /** * APIProperty: onStart - * {Function} Define this function if you want to know when a drag starts. + * {Function} *Deprecated*. Register for "beforefeaturemodified" instead. + * The "beforefeaturemodified" event is triggered on the layer before + * any modification begins. + * + * Define this function if you want to know when a drag starts. * The function should expect to receive two arguments: the feature * that is about to be dragged and the pixel location of the mouse. * @@ -42,7 +46,11 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { /** * APIProperty: onDrag - * {Function} Define this function if you want to know about each move of a + * {Function} *Deprecated*. Register for "featuremodified" instead. + * The "featuremodified" event is triggered on the layer with each + * feature modification. + * + * Define this function if you want to know about each move of a * feature. The function should expect to receive two arguments: the * feature that is being dragged and the pixel location of the mouse. * @@ -54,7 +62,11 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { /** * APIProperty: onComplete - * {Function} Define this function if you want to know when a feature is + * {Function} *Deprecated*. Register for "afterfeaturemodified" instead. + * The "afterfeaturemodified" event is triggered on the layer after + * a feature has been modified. + * + * Define this function if you want to know when a feature is * done dragging. The function should expect to receive two arguments: * the feature that is being dragged and the pixel location of the * mouse. @@ -273,6 +285,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { downFeature: function(pixel) { this.lastPixel = pixel; this.onStart(this.feature, pixel); + return this.layer.events.triggerEvent( + "beforefeaturemodified", {feature: this.feature} + ); }, /** @@ -290,6 +305,8 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { this.layer.drawFeature(this.feature); this.lastPixel = pixel; this.onDrag(this.feature, pixel); + this.layer.events.triggerEvent("featuremodified", + {feature: this.feature}); }, /** @@ -315,6 +332,9 @@ OpenLayers.Control.DragFeature = OpenLayers.Class(OpenLayers.Control, { */ doneDragging: function(pixel) { this.onComplete(this.feature, pixel); + this.layer.events.triggerEvent("afterfeaturemodified", { + feature: this.feature + }); }, /** diff --git a/tests/Control/DragFeature.html b/tests/Control/DragFeature.html index cfc3a631f4..03496eea4f 100644 --- a/tests/Control/DragFeature.html +++ b/tests/Control/DragFeature.html @@ -168,9 +168,13 @@ } function test_Control_DragFeature_move(t) { - t.plan(3); + t.plan(5); var map = new OpenLayers.Map("map"); var layer = new OpenLayers.Layer.Vector(); + layer.events.on({ + 'beforefeaturemodified': function(evt) { t.ok(true, "beforefeaturemodified is triggered on the layer"); }, + 'featuremodified': function(evt) { t.ok(true, "featuremodified is triggered on the layer"); } + }); map.addLayer(layer); var control = new OpenLayers.Control.DragFeature(layer); map.addControl(control); @@ -257,10 +261,13 @@ } function test_Control_DragFeature_done(t) { - t.plan(2); + t.plan(3); var map = new OpenLayers.Map("map"); var layer = new OpenLayers.Layer.Vector(); map.addLayer(layer); + layer.events.on({ + 'afterfeaturemodified': function(evt) { t.ok(true, "afterfeaturemodified is triggered on the layer"); } + }); var control = new OpenLayers.Control.DragFeature(layer); map.addControl(control); From 6936acd7c7dc8474988932f2da7d7899c8b919de Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 23 Sep 2011 15:36:18 +0200 Subject: [PATCH 6/6] ArgParser does not deal well with fractionalZoom, r=fredj (closes #3515) --- lib/OpenLayers/Control/ArgParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Control/ArgParser.js b/lib/OpenLayers/Control/ArgParser.js index 3ba0d49adb..170edd299f 100644 --- a/lib/OpenLayers/Control/ArgParser.js +++ b/lib/OpenLayers/Control/ArgParser.js @@ -122,7 +122,7 @@ OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, { this.center = new OpenLayers.LonLat(parseFloat(args.lon), parseFloat(args.lat)); if (args.zoom) { - this.zoom = parseInt(args.zoom); + this.zoom = parseFloat(args.zoom); } // when we add a new baselayer to see when we can set the center