Skip to content

Revert "Remove _loadTxtSync, Because chrome(40) deprecated this API" #2715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions CCBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,26 @@ cc.loader = /** @lends cc.loader# */{
});
}
},
_loadTxtSync: function (url) {
if (!cc._isNodeJs) {
var xhr = this.getXMLHttpRequest();
xhr.open("GET", url, false);
if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
// IE-specific logic here
xhr.setRequestHeader("Accept-Charset", "utf-8");
} else {
if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8");
}
xhr.send(null);
if (!xhr.readyState == 4 || xhr.status != 200) {
return null;
}
return xhr.responseText;
} else {
var fs = require("fs");
return fs.readFileSync(url).toString();
}
},

loadCsb: function(url, cb){
var xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -1944,7 +1964,6 @@ cc.game = /** @lends cc.game# */{
DEBUG_MODE_INFO_FOR_WEB_PAGE: 4,
DEBUG_MODE_WARN_FOR_WEB_PAGE: 5,
DEBUG_MODE_ERROR_FOR_WEB_PAGE: 6,
_ready: false,

EVENT_HIDE: "game_on_hide",
EVENT_SHOW: "game_on_show",
Expand Down Expand Up @@ -2082,12 +2101,6 @@ cc.game = /** @lends cc.game# */{
* Run game.
*/
run: function (id) {
if(this._ready === false){
this._ready = id === undefined ? true : id;
return;
}else if(typeof this._ready !== "boolean"){
id = this._ready;
}
var self = this;
var _run = function () {
if (id) {
Expand Down Expand Up @@ -2130,13 +2143,7 @@ cc.game = /** @lends cc.game# */{
cfg[CONFIG_KEY.frameRate] = cfg[CONFIG_KEY.frameRate] || 60;
if(cfg[CONFIG_KEY.renderMode] == null)
cfg[CONFIG_KEY.renderMode] = 1;
//init debug move to CCDebugger
cc._initSys(cfg, CONFIG_KEY);
self.config = cfg;
if(cc.game._ready !== false){
self._ready = true;
cc.game.run();
}
return cfg;
};
if (document["ccConfig"]) {
self.config = _init(document["ccConfig"]);
Expand All @@ -2147,31 +2154,28 @@ cc.game = /** @lends cc.game# */{
var _t = cocos_script[i].getAttribute('cocos');
if(_t == '' || _t){break;}
}
var _src, _resPath;
var _src, txt, _resPath;
if(i < cocos_script.length){
_src = cocos_script[i].src;
if(_src){
_resPath = /(.*)\//.exec(_src)[0];
cc.loader.resPath = _resPath;
_src = cc.path.join(_resPath, 'project.json');
}
cc.loader.loadTxt(_src, function(err, txt){
if(err)
return cc.error(err);
_init(JSON.parse(txt) || {});
});
}else{
cc.loader.loadTxt("project.json", function(err, txt){
if(err)
return cc.error(err);
_init(JSON.parse(txt) || {});
});
txt = cc.loader._loadTxtSync(_src);
}
if(!txt){
txt = cc.loader._loadTxtSync("project.json");
}
var data = JSON.parse(txt);
self.config = _init(data || {});
} catch (e) {
cc.log("Failed to read or parse project.json");
_init({});
self.config = _init({});
}
}
//init debug move to CCDebugger
cc._initSys(self.config, CONFIG_KEY);
},

//cache for js and module that has added into jsList to be loaded.
Expand Down