forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cocos#859 from jareguo/v1.1
fix pack loader on JSB
- Loading branch information
Showing
3 changed files
with
54 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
var Pipeline = require('./pipeline'); | ||
var urlAppendTimestamp = require('./utils').urlAppendTimestamp; | ||
if (CC_JSB) { | ||
module.exports = function (item, callback) { | ||
var url = item.url; | ||
|
||
module.exports = function (item, callback) { | ||
var url = item.url, | ||
xhr = Pipeline.getXMLHttpRequest(), | ||
errInfo = 'Load ' + url + ' failed!', | ||
navigator = window.navigator; | ||
var result = jsb.fileUtils.getStringFromFile(url); | ||
if (typeof result === 'string' && result) { | ||
callback(null, result); | ||
} | ||
else { | ||
callback(new Error('Download text failed: ' + url)); | ||
} | ||
} | ||
} | ||
else { | ||
var Pipeline = require('./pipeline'); | ||
var urlAppendTimestamp = require('./utils').urlAppendTimestamp; | ||
|
||
url = urlAppendTimestamp(url); | ||
module.exports = function (item, callback) { | ||
var url = item.url, | ||
xhr = Pipeline.getXMLHttpRequest(), | ||
errInfo = 'Load ' + url + ' failed!', | ||
navigator = window.navigator; | ||
|
||
xhr.open('GET', url, true); | ||
if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { | ||
// IE-specific logic here | ||
xhr.setRequestHeader('Accept-Charset', 'utf-8'); | ||
xhr.onreadystatechange = function () { | ||
if(xhr.readyState === 4) { | ||
if (xhr.status === 200 || xhr.status === 0) { | ||
callback(null, xhr.responseText); | ||
} | ||
else { | ||
callback({status:xhr.status, errorMessage:errInfo}); | ||
} | ||
} | ||
}; | ||
} else { | ||
if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8'); | ||
xhr.onload = function () { | ||
if(xhr.readyState === 4) { | ||
if (xhr.status === 200 || xhr.status === 0) { | ||
callback(null, xhr.responseText); | ||
url = urlAppendTimestamp(url); | ||
|
||
xhr.open('GET', url, true); | ||
if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { | ||
// IE-specific logic here | ||
xhr.setRequestHeader('Accept-Charset', 'utf-8'); | ||
xhr.onreadystatechange = function () { | ||
if(xhr.readyState === 4) { | ||
if (xhr.status === 200 || xhr.status === 0) { | ||
callback(null, xhr.responseText); | ||
} | ||
else { | ||
callback({status:xhr.status, errorMessage:errInfo}); | ||
} | ||
} | ||
else { | ||
callback({status:xhr.status, errorMessage:errInfo}); | ||
}; | ||
} else { | ||
if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8'); | ||
xhr.onload = function () { | ||
if(xhr.readyState === 4) { | ||
if (xhr.status === 200 || xhr.status === 0) { | ||
callback(null, xhr.responseText); | ||
} | ||
else { | ||
callback({status:xhr.status, errorMessage:errInfo}); | ||
} | ||
} | ||
} | ||
}; | ||
xhr.onerror = function(){ | ||
callback({status:xhr.status, errorMessage:errInfo}); | ||
}; | ||
} | ||
xhr.send(null); | ||
}; | ||
}; | ||
xhr.onerror = function(){ | ||
callback({status:xhr.status, errorMessage:errInfo}); | ||
}; | ||
} | ||
xhr.send(null); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters