Skip to content

Commit 6f64c54

Browse files
committed
Using JSON.parse if available.
1 parent f020cf2 commit 6f64c54

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* https://opensource.org/licenses/MIT
1010
*/
1111

12-
/* global define, require, window, document */
12+
/* global define, require, window, document, JSON */
1313

1414
;(function (factory) {
1515
'use strict';
@@ -27,7 +27,14 @@
2727
'use strict';
2828

2929
// Helper variable to create unique names for the transport iframes:
30-
var counter = 0;
30+
var counter = 0,
31+
jsonAPI = $,
32+
jsonParse = 'parseJSON';
33+
34+
if ('JSON' in window && 'parse' in JSON) {
35+
jsonAPI = JSON;
36+
jsonParse = 'parse';
37+
}
3138

3239
// The iframe transport accepts four additional options:
3340
// options.fileInput: a jQuery collection of file input fields
@@ -197,7 +204,7 @@
197204
return iframe && $(iframe[0].body).text();
198205
},
199206
'iframe json': function (iframe) {
200-
return iframe && $.parseJSON($(iframe[0].body).text());
207+
return iframe && jsonAPI[jsonParse]($(iframe[0].body).text());
201208
},
202209
'iframe html': function (iframe) {
203210
return iframe && $(iframe[0].body).html();

0 commit comments

Comments
 (0)