Skip to content

Commit 8dbe6e3

Browse files
author
Andrew Start
committed
Changed how regular JSON is loaded.
Now we should be able to safely use javascript comments (by using eval() - don’t do anything dangerous!).
1 parent db23790 commit 8dbe6e3

File tree

8 files changed

+18
-80
lines changed

8 files changed

+18
-80
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "preloadjs",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"main": "lib/preloadjs.min.js",
55
"ignore": [
66
"**/.*",

build/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"../src/preloadjs/AbstractLoader.js",
99
"../src/preloadjs/LoadQueue.js",
1010
"../src/preloadjs/TagLoader.js",
11-
"../src/preloadjs/XHRLoader.js",
12-
"../src/preloadjs/minify.json.js"
11+
"../src/preloadjs/XHRLoader.js"
1312
],
1413

1514
"docs_out_path":"./output/PreloadJSDocs/"

build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "PreloadJS",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "PreloadJS Docs",
55
"url": "http://www.createjs.com/#!/PreloadJS",
66
"logo": "assets/docs-icon-PreloadJS.png",

docs/PreloadJS_docs.zip

109 Bytes
Binary file not shown.

lib/preloadjs.combined.js

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ this.createjs = this.createjs||{};
1919
* @type String
2020
* @static
2121
**/
22-
s.version = /*version*/"0.4.1"; // injected by build process
22+
s.version = /*version*/"0.4.2"; // injected by build process
2323

2424
/**
2525
* The build date for this release in UTC format.
2626
* @property buildDate
2727
* @type String
2828
* @static
2929
**/
30-
s.buildDate = /*date*/"Tue, 29 Apr 2014 15:42:26 GMT"; // injected by build process
30+
s.buildDate = /*date*/"Thu, 12 Jun 2014 14:31:43 GMT"; // injected by build process
3131

3232
})();
3333
/*
@@ -4182,13 +4182,15 @@ this.createjs = this.createjs || {};
41824182

41834183
case createjs.LoadQueue.JSON:
41844184
case createjs.LoadQueue.MANIFEST:
4185-
var json = {};
4185+
var json;
41864186
try {
4187-
if(JSON.minify && (this._item.data && this._item.data.minify))
4187+
/*if(JSON.minify && (this._item.data && this._item.data.minify))
41884188
{
41894189
this._response = JSON.minify(this._response);
41904190
}
4191-
json = JSON.parse(this._response);
4191+
json = JSON.parse(this._response);*/
4192+
//use eval to allow javascript comments in the JSON
4193+
eval("json = " + this._response + ";");//thankfully, uglify won't mangle 'var json' because we use it in eval()
41924194
} catch (error) {
41934195
json = error;
41944196
}
@@ -4597,64 +4599,3 @@ if (typeof JSON !== 'object') {
45974599
};
45984600
}
45994601
}());
4600-
/*! JSON.minify()
4601-
v0.1 (c) Kyle Simpson
4602-
MIT License
4603-
*/
4604-
4605-
(function(global){
4606-
if (typeof global.JSON == "undefined" || !global.JSON) {
4607-
global.JSON = {};
4608-
}
4609-
4610-
global.JSON.minify = function(json) {
4611-
4612-
var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g,
4613-
in_string = false,
4614-
in_multiline_comment = false,
4615-
in_singleline_comment = false,
4616-
tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc
4617-
;
4618-
4619-
tokenizer.lastIndex = 0;
4620-
4621-
while (tmp = tokenizer.exec(json)) {
4622-
lc = RegExp.leftContext;
4623-
rc = RegExp.rightContext;
4624-
if (!in_multiline_comment && !in_singleline_comment) {
4625-
tmp2 = lc.substring(from);
4626-
if (!in_string) {
4627-
tmp2 = tmp2.replace(/(\n|\r|\s)*/g,"");
4628-
}
4629-
new_str[ns++] = tmp2;
4630-
}
4631-
from = tokenizer.lastIndex;
4632-
4633-
if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) {
4634-
tmp2 = lc.match(/(\\)*$/);
4635-
if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) { // start of string with ", or unescaped " character found to end string
4636-
in_string = !in_string;
4637-
}
4638-
from--; // include " character in next catch
4639-
rc = json.substring(from);
4640-
}
4641-
else if (tmp[0] == "/*" && !in_string && !in_multiline_comment && !in_singleline_comment) {
4642-
in_multiline_comment = true;
4643-
}
4644-
else if (tmp[0] == "*/" && !in_string && in_multiline_comment && !in_singleline_comment) {
4645-
in_multiline_comment = false;
4646-
}
4647-
else if (tmp[0] == "//" && !in_string && !in_multiline_comment && !in_singleline_comment) {
4648-
in_singleline_comment = true;
4649-
}
4650-
else if ((tmp[0] == "\n" || tmp[0] == "\r") && !in_string && !in_multiline_comment && in_singleline_comment) {
4651-
in_singleline_comment = false;
4652-
}
4653-
else if (!in_multiline_comment && !in_singleline_comment && !(/\n|\r|\s/.test(tmp[0]))) {
4654-
new_str[ns++] = tmp[0];
4655-
}
4656-
}
4657-
new_str[ns++] = rc;
4658-
return new_str.join("");
4659-
};
4660-
})(this);

lib/preloadjs.min.js

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/preloadjs/XHRLoader.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,15 @@ this.createjs = this.createjs || {};
589589

590590
case createjs.LoadQueue.JSON:
591591
case createjs.LoadQueue.MANIFEST:
592-
var json = {};
592+
var json;
593593
try {
594-
if(JSON.minify && (this._item.data && this._item.data.minify))
594+
/*if(JSON.minify && (this._item.data && this._item.data.minify))
595595
{
596596
this._response = JSON.minify(this._response);
597597
}
598-
json = JSON.parse(this._response);
598+
json = JSON.parse(this._response);*/
599+
//use eval to allow javascript comments in the JSON
600+
eval("json = " + this._response + ";");//thankfully, uglify won't mangle 'var json' because we use it in eval()
599601
} catch (error) {
600602
json = error;
601603
}

src/preloadjs/version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ this.createjs = this.createjs||{};
1919
* @type String
2020
* @static
2121
**/
22-
s.version = /*version*/"0.4.1"; // injected by build process
22+
s.version = /*version*/"0.4.2"; // injected by build process
2323

2424
/**
2525
* The build date for this release in UTC format.
2626
* @property buildDate
2727
* @type String
2828
* @static
2929
**/
30-
s.buildDate = /*date*/"Tue, 29 Apr 2014 15:42:26 GMT"; // injected by build process
30+
s.buildDate = /*date*/"Thu, 12 Jun 2014 14:31:43 GMT"; // injected by build process
3131

3232
})();

0 commit comments

Comments
 (0)