Skip to content

Commit

Permalink
Taking brackets out of the callback.
Browse files Browse the repository at this point in the history
The Yahoo API doesn't accept quotes in the callback (e.g. foo['bar']).  Since the callback registry is an object and all identifiers are prefixed with "c" now, we can use dot notation.
  • Loading branch information
tschaub committed Mar 21, 2012
1 parent 127abf8 commit 609e5f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/OpenLayers/Protocol/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ 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}']".
* for the registry. Should include ${id}. The ${id} variable will be
* replaced with a string identifier prefixed with a "c" (e.g. c1, c2).
* Default is "OpenLayers.Protocol.Script.registry.${id}".
*/
callbackTemplate: "OpenLayers.Protocol.Script.registry['${id}']",
callbackTemplate: "OpenLayers.Protocol.Script.registry.${id}",

/**
* APIProperty: callbackKey
Expand Down
14 changes: 8 additions & 6 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(5);
t.plan(6);
var protocol = new OpenLayers.Protocol.Script({
callbackKey: 'cb_key',
callbackPrefix: 'cb_prefix:'
Expand All @@ -153,15 +153,17 @@

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(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');

protocol.callbackTemplate = "OpenLayers.Protocol.Script.registry.${id}";
script = protocol.createRequest('http://bar_url/', {'k': 'bar_param'}, 'bar_callback');
t.eq(script.src, 'http://bar_url/?k=bar_param&cb_key=cb_prefix%3AOpenLayers.Protocol.Script.registry.bar',
'created script has a correct url with different template');
protocol.callbackTemplate = "customCallback(${id})";
script = protocol.createRequest('http://bar_url/', {'k': 'bar_param2'}, 'bar_callback');

params = OpenLayers.Util.getParameters(script.src);
t.eq(params.k, "bar_param2", "custom query string param");
t.eq(params.cb_key, "cb_prefix:customCallback(bar)", "custom callback with prefix");

OpenLayers.Protocol.Script.register = _register;

Expand Down

0 comments on commit 609e5f7

Please sign in to comment.