Skip to content

Commit

Permalink
Correcting the callback for the script protocol.
Browse files Browse the repository at this point in the history
In f08119b, the default syntax for the script protocol's callback made it so the callbacks looked like `OpenLayers.Protocol.Script.registry[c1]`.  This essentially breaks the script protocol everywhere except where `c1` is defined and equals "c1" (the string).

Tests with this change demonstrate that default callbacks will now look like `OpenLayers.Protocol.Script.registry['c1']` (properly accessing the `c1` property of the registry object).
  • Loading branch information
tschaub committed Mar 20, 2012
1 parent 0feefaa commit 127abf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/OpenLayers/Protocol/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
* APIProperty: callbackTemplate
* {String} Template for creating a unique callback function name
* for the registry. Should include ${id}.
* Default is "OpenLayers.Protocol.Script.registry[${id}]".
* Default is "OpenLayers.Protocol.Script.registry['${id}']".
*/
callbackTemplate: "OpenLayers.Protocol.Script.registry[${id}]",
callbackTemplate: "OpenLayers.Protocol.Script.registry['${id}']",

/**
* APIProperty: callbackKey
Expand Down
9 changes: 6 additions & 3 deletions tests/Protocol/Script.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
}

function test_createRequest(t) {
t.plan(4);
t.plan(5);
var protocol = new OpenLayers.Protocol.Script({
callbackKey: 'cb_key',
callbackPrefix: 'cb_prefix:'
Expand All @@ -150,8 +150,11 @@

t.eq(script.type, 'text/javascript',
'created script has a correct type');
t.eq(script.src, 'http://bar_url/?k=bar_param&cb_key=cb_prefix%3AOpenLayers.Protocol.Script.registry%5Bbar%5D',
'created script has a correct url');

var params = OpenLayers.Util.getParameters(script.src);
t.eq(params.k, "bar_param", "custom query string param");
t.eq(params.cb_key, "cb_prefix:OpenLayers.Protocol.Script.registry['bar']", "callback with prefix");

t.eq(script.id, 'OpenLayers_Protocol_Script_bar',
'created script has a correct id');

Expand Down

0 comments on commit 127abf8

Please sign in to comment.