Skip to content

Commit a224766

Browse files
author
Andrew Start
committed
JSONLoader should now do x-domain stuff properly.
There was an issue on IE9 that I think this fixes - loading non cross-domain stuff with cross-domain set to true. Also fixed the 4 load attempts not working.
1 parent b49a136 commit a224766

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

bin/pixi.dev.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* @license
3-
* pixi.js - v2.1.5
3+
* pixi.js - v2.1.6
44
* Copyright (c) 2012-2014, Mat Groves
55
* http://goodboydigital.com/
66
*
7-
* Compiled: 2015-01-22
7+
* Compiled: 2015-02-04
88
*
99
* pixi.js is licensed under the MIT License.
1010
* http://www.opensource.org/licenses/mit-license.php
@@ -17227,19 +17227,7 @@ PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype);
1722717227
*/
1722817228
PIXI.JsonLoader.prototype.load = function()
1722917229
{
17230-
if(window.XDomainRequest && this.crossorigin)
17231-
this.ajaxRequest = new window.XDomainRequest();
17232-
else
17233-
this.ajaxRequest = new PIXI.AjaxRequest();
17234-
this.ajaxRequest.onload = this.ajaxRequest.onreadystatechange = this.onJSONLoaded.bind(this);
17235-
17236-
var src = PIXI.buildPath(this.url, this.baseUrl);
17237-
// XDomainRequest has a few quirks. Occasionally it will abort requests
17238-
this.ajaxRequest.open('GET', src, true);
17239-
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/json');
17240-
// Determine the XHR level
17241-
var xhrLevel = (typeof this.ajaxRequest.responseType === 'string') ? 2 : 1;
17242-
//attempt to only use cross domain requests if needed, because IE9 - code borrowed from PreloadJS
17230+
//attempt to only use cross domain requests if needed, because IE9 - code borrowed from PreloadJS
1724317231
var crossDomain = false;
1724417232
if(this.crossorigin)
1724517233
{
@@ -17252,6 +17240,19 @@ PIXI.JsonLoader.prototype.load = function()
1725217240
target.protocol !== host.protocol ||
1725317241
target.hostname !== host.hostname);
1725417242
}
17243+
if(window.XDomainRequest && crossDomain)
17244+
this.ajaxRequest = new window.XDomainRequest();
17245+
else
17246+
this.ajaxRequest = new PIXI.AjaxRequest();
17247+
this.ajaxRequest.onload = this.ajaxRequest.onreadystatechange = this.onJSONLoaded.bind(this);
17248+
17249+
var src = PIXI.buildPath(this.url, this.baseUrl);
17250+
// XDomainRequest has a few quirks. Occasionally it will abort requests
17251+
this.ajaxRequest.open('GET', src, true);
17252+
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/json');
17253+
// Determine the XHR level
17254+
var xhrLevel = (typeof this.ajaxRequest.responseType === 'string') ? 2 : 1;
17255+
//make sure of the request header
1725517256
if (crossDomain && this.ajaxRequest instanceof XMLHttpRequest && xhrLevel === 1) {
1725617257
this.ajaxRequest.setRequestHeader('Origin', location.origin);
1725717258
}
@@ -17261,6 +17262,7 @@ PIXI.JsonLoader.prototype.load = function()
1726117262
clearTimeout(this._loadTimeout);
1726217263
this._loadTimeout = 0;
1726317264
}
17265+
this._loadFails = 0;
1726417266
var scope = this;
1726517267
this.ajaxRequest.onloadstart = function(){};
1726617268
this.ajaxRequest.onprogress = function(){};

bin/pixi.js

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

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pixi.js",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44

55
"main": "bin/pixi.dev.js",
66

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pixi.js",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "Pixi.js is a fast lightweight 2D library that works across all devices.",
55

66
"author": "Mat Groves",

src/pixi/loaders/JsonLoader.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,7 @@ PIXI.EventTarget.mixin(PIXI.JsonLoader.prototype);
6666
*/
6767
PIXI.JsonLoader.prototype.load = function()
6868
{
69-
if(window.XDomainRequest && this.crossorigin)
70-
this.ajaxRequest = new window.XDomainRequest();
71-
else
72-
this.ajaxRequest = new PIXI.AjaxRequest();
73-
this.ajaxRequest.onload = this.ajaxRequest.onreadystatechange = this.onJSONLoaded.bind(this);
74-
75-
var src = PIXI.buildPath(this.url, this.baseUrl);
76-
// XDomainRequest has a few quirks. Occasionally it will abort requests
77-
this.ajaxRequest.open('GET', src, true);
78-
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/json');
79-
// Determine the XHR level
80-
var xhrLevel = (typeof this.ajaxRequest.responseType === 'string') ? 2 : 1;
81-
//attempt to only use cross domain requests if needed, because IE9 - code borrowed from PreloadJS
69+
//attempt to only use cross domain requests if needed, because IE9 - code borrowed from PreloadJS
8270
var crossDomain = false;
8371
if(this.crossorigin)
8472
{
@@ -91,6 +79,19 @@ PIXI.JsonLoader.prototype.load = function()
9179
target.protocol !== host.protocol ||
9280
target.hostname !== host.hostname);
9381
}
82+
if(window.XDomainRequest && crossDomain)
83+
this.ajaxRequest = new window.XDomainRequest();
84+
else
85+
this.ajaxRequest = new PIXI.AjaxRequest();
86+
this.ajaxRequest.onload = this.ajaxRequest.onreadystatechange = this.onJSONLoaded.bind(this);
87+
88+
var src = PIXI.buildPath(this.url, this.baseUrl);
89+
// XDomainRequest has a few quirks. Occasionally it will abort requests
90+
this.ajaxRequest.open('GET', src, true);
91+
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/json');
92+
// Determine the XHR level
93+
var xhrLevel = (typeof this.ajaxRequest.responseType === 'string') ? 2 : 1;
94+
//make sure of the request header
9495
if (crossDomain && this.ajaxRequest instanceof XMLHttpRequest && xhrLevel === 1) {
9596
this.ajaxRequest.setRequestHeader('Origin', location.origin);
9697
}
@@ -100,6 +101,7 @@ PIXI.JsonLoader.prototype.load = function()
100101
clearTimeout(this._loadTimeout);
101102
this._loadTimeout = 0;
102103
}
104+
this._loadFails = 0;
103105
var scope = this;
104106
this.ajaxRequest.onloadstart = function(){};
105107
this.ajaxRequest.onprogress = function(){};

0 commit comments

Comments
 (0)