diff --git a/cocos2d/core/load-pipeline/binary-downloader.js b/cocos2d/core/load-pipeline/binary-downloader.js index 131948cf63..de4097f4ea 100644 --- a/cocos2d/core/load-pipeline/binary-downloader.js +++ b/cocos2d/core/load-pipeline/binary-downloader.js @@ -24,23 +24,8 @@ THE SOFTWARE. ****************************************************************************/ -if (CC_JSB) { - module.exports = function (item, callback) { - var url = item.url; - - var result = jsb.fileUtils.getDataFromFile(url); - if (result) { - return result; - } - else { - return new Error('Download binary file failed: ' + url); - } - }; -} -else { function downloadBinary (item, callback) { var url = item.url; - var self = this; var xhr = cc.loader.getXMLHttpRequest(), errInfo = 'Load binary data failed: ' + url + ''; xhr.open('GET', url, true); @@ -64,5 +49,4 @@ function downloadBinary (item, callback) { xhr.send(null); } -module.exports = downloadBinary; -} \ No newline at end of file +module.exports = downloadBinary; \ No newline at end of file diff --git a/cocos2d/core/load-pipeline/text-downloader.js b/cocos2d/core/load-pipeline/text-downloader.js index deb9970f35..a64ca7f740 100644 --- a/cocos2d/core/load-pipeline/text-downloader.js +++ b/cocos2d/core/load-pipeline/text-downloader.js @@ -23,49 +23,34 @@ THE SOFTWARE. ****************************************************************************/ -if (CC_JSB) { - module.exports = function (item) { - var url = item.url; +var urlAppendTimestamp = require('./utils').urlAppendTimestamp; - var result = jsb.fileUtils.getStringFromFile(url); - if (typeof result === 'string' && result) { - return result; - } - else { - return new Error('Download text failed: ' + url); - } - }; -} -else { - var urlAppendTimestamp = require('./utils').urlAppendTimestamp; +module.exports = function (item, callback) { + var url = item.url; + url = urlAppendTimestamp(url); - module.exports = function (item, callback) { - var url = item.url; - url = urlAppendTimestamp(url); - - var xhr = cc.loader.getXMLHttpRequest(), - errInfo = 'Load text file failed: ' + url; - xhr.open('GET', url, true); - 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 + '(wrong status)'}); - } + var xhr = cc.loader.getXMLHttpRequest(), + errInfo = 'Load text file failed: ' + url; + xhr.open('GET', url, true); + 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 + '(wrong readyState)'}); + callback({status:xhr.status, errorMessage:errInfo + '(wrong status)'}); } - }; - xhr.onerror = function(){ - callback({status:xhr.status, errorMessage:errInfo + '(error)'}); - }; - xhr.ontimeout = function(){ - callback({status:xhr.status, errorMessage:errInfo + '(time out)'}); - }; - xhr.send(null); + } + else { + callback({status:xhr.status, errorMessage:errInfo + '(wrong readyState)'}); + } }; -} + xhr.onerror = function(){ + callback({status:xhr.status, errorMessage:errInfo + '(error)'}); + }; + xhr.ontimeout = function(){ + callback({status:xhr.status, errorMessage:errInfo + '(time out)'}); + }; + xhr.send(null); +}; \ No newline at end of file