Skip to content

Commit 86d2562

Browse files
committed
Fixes crucial bug when passing along responses which are arrays, which will be considered multiple arguments by fireEvent
1 parent 46f1234 commit 86d2562

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

Source/Core/Log.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Script: Log.js
3+
Provides basic logging functionality for plugins to implement.
4+
5+
License:
6+
MIT-style license.
7+
8+
Authors:
9+
Guillermo Rauch
10+
*/
11+
12+
var Log = new Class({
13+
14+
log: function(){
15+
Log.logger.call(this, arguments);
16+
}
17+
18+
});
19+
20+
Log.logged = [];
21+
22+
Log.logger = function(){
23+
if(window.console && console.log) console.log.apply(console, arguments);
24+
else Log.logged.push(arguments);
25+
};

Source/Request/Request.JSONP.js

+17-22
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Script: Request.JSONP.js
1111

1212
Request.JSONP = new Class({
1313

14-
Implements: [Chain, Events, Options],
14+
Implements: [Chain, Events, Options, Log],
1515

1616
options: {/*
1717
onRetry: $empty(intRetries),
@@ -24,7 +24,7 @@ Request.JSONP = new Class({
2424
retries: 0,
2525
timeout: 0,
2626
link: 'ignore',
27-
callBackKey: 'callback',
27+
callbackKey: 'callback',
2828
injectScript: document.head
2929
},
3030

@@ -57,7 +57,7 @@ Request.JSONP = new Class({
5757

5858
(function(){
5959
var script = this.getScript(options);
60-
MooTools.log('JSONP retrieving script with url: ' + script.src);
60+
this.log('JSONP retrieving script with url: ' + script.src);
6161
this.fireEvent('request', script);
6262
this.running = true;
6363

@@ -72,6 +72,7 @@ Request.JSONP = new Class({
7272
} else if(script && this.options.timeout){
7373
script.destroy();
7474
this.cancel();
75+
this.fireEvent('failure');
7576
}
7677
}).delay(this.options.timeout, this);
7778
}).delay(Browser.Engine.trident ? 50 : 0, this);
@@ -93,34 +94,28 @@ Request.JSONP = new Class({
9394
case 'object': case 'hash': data = Hash.toQueryString(options.data);
9495
}
9596

96-
var script = new Element('script', {
97-
type: 'text/javascript',
98-
src: options.url +
99-
(options.url.test('\\?') ? '&' :'?') +
100-
(options.callBackKey || this.options.callBackKey) +
101-
"=Request.JSONP.requests["+ index +"]" +
102-
(data ? '&' + data : '')
103-
}).inject(this.options.injectScript);
97+
var src = options.url +
98+
(options.url.test('\\?') ? '&' :'?') +
99+
(options.callbackKey || this.options.callbackKey) +
100+
"=Request.JSONP.requests["+ index +"]" +
101+
(data ? '&' + data : '');
102+
103+
if (src.length > 2083) this.log('JSONP '+ src +' will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs');
104+
105+
var script = new Element('script', {type: 'text/javascript', src: src});
104106

105107
Request.JSONP.requests.push(function(data){ this.success(data, script); }.bind(this));
106108

107-
return script;
109+
return script.inject(this.options.injectScript);
108110
},
109111

110112
success: function(data, script){
111113
if (script) script.destroy();
112114
this.running = false;
113-
MooTools.log('JSONP successfully retrieved: ', data);
114-
this.fireEvent('complete', data).fireEvent('success', data).callChain();
115+
this.log('JSONP successfully retrieved: ', data);
116+
this.fireEvent('complete', [data]).fireEvent('success', [data]).callChain();
115117
}
116118

117119
});
118120

119-
Request.JSONP.requests = [];
120-
121-
$extend(MooTools, {
122-
logged: [],
123-
log: function(){
124-
MooTools.logged.push(arguments);
125-
}
126-
});
121+
Request.JSONP.requests = [];

0 commit comments

Comments
 (0)