Skip to content

Commit

Permalink
Merge pull request cocos#859 from jareguo/v1.1
Browse files Browse the repository at this point in the history
fix pack loader on JSB
  • Loading branch information
pandamicro authored Jul 1, 2016
2 parents 7615b9c + 5dcff33 commit c3d1b30
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 69 deletions.
2 changes: 1 addition & 1 deletion cocos2d/core/load-pipeline/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ JS.mixin(Downloader.prototype, {
* @param {Object} extMap Custom supported types with corresponded handler
*/
addHandlers: function (extMap) {
this.extMap = JS.mixin(this.extMap, extMap);
JS.mixin(this.extMap, extMap);
},

handle: function (item, callback) {
Expand Down
91 changes: 53 additions & 38 deletions cocos2d/core/load-pipeline/text-downloader.js
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);
};
}
30 changes: 0 additions & 30 deletions jsb/jsb-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ function downloadScript (item, callback) {
callback(null, url);
}

function downloadText (item, callback) {
var url = item.url;

var result = jsb.fileUtils.getStringFromFile(url);
if (typeof result === 'string' && result) {
callback(null, result);
}
else {
callback(new Error('Download text failed: ' + url));
}
}

function downloadAudio (item, callback) {
callback(null, item.url);
}
Expand Down Expand Up @@ -75,31 +63,13 @@ cc.loader.addDownloadHandlers({
'mp4' : downloadAudio,
'm4a' : downloadAudio,

// Txt
'txt' : downloadText,
'xml' : downloadText,
'vsh' : downloadText,
'fsh' : downloadText,
'atlas' : downloadText,

'tmx' : downloadText,
'tsx' : downloadText,

'json' : downloadText,
'ExportJson' : downloadText,
'plist' : downloadText,

'fnt' : downloadText,

// Font
'font' : empty,
'eot' : empty,
'ttf' : empty,
'woff' : empty,
'svg' : empty,
'ttc' : empty,

'default' : downloadText
});


Expand Down

0 comments on commit c3d1b30

Please sign in to comment.