Skip to content

Commit

Permalink
revert ti.include for mobile web
Browse files Browse the repository at this point in the history
  • Loading branch information
cheekiatng committed Nov 1, 2016
1 parent 1f3a7e0 commit e1e3474
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mobileweb/titanium/Ti.js
Expand Up @@ -13,7 +13,7 @@
*/

define(
["Ti/_", "Ti/API", "Ti/_/analytics", "Ti/App", "Ti/_/Evented", "Ti/_/has", "Ti/_/lang", "Ti/_/ready", "Ti/_/style", "Ti/Buffer", "Ti/Platform", "Ti/UI", "Ti/Locale"],
["Ti/_", "Ti/API", "Ti/_/analytics", "Ti/App", "Ti/_/Evented", "Ti/_/has", "Ti/_/lang", "Ti/_/ready", "Ti/_/style", "Ti/Buffer", "Ti/Platform", "Ti/UI", "Ti/Locale", "Ti/_/include"],
function(_, API, analytics, App, Evented, has, lang, ready, style, Buffer, Platform, UI) {

var global = window,
Expand Down Expand Up @@ -43,7 +43,12 @@ define(
createBuffer: function(args) {
return new Buffer(args);
},

include: function(files) {
typeof files === "array" || (files = [].concat(Array.prototype.slice.call(arguments, 0)));
files.forEach(function(f) {
require("Ti/_/include!" + f);
});
},
deferStart: function() {
if (loaded) {
API.warn("app.js already loaded!");
Expand Down
54 changes: 54 additions & 0 deletions mobileweb/titanium/Ti/_/include.js
@@ -0,0 +1,54 @@
define(function() {
var cache = {},
stack = [];

return {
dynamic: true, // prevent the loader from caching the result

normalize: function(name, normalize) {
var parts = name.split("!"),
url = parts[0];
parts.shift();
return (/^\./.test(url) ? normalize(url) : url) + (parts.length ? "!" + parts.join("!") : "");
},

load: function(name, require, onLoad, config) {
var c,
x,
parts = name.split("!"),
len = parts.length,
url,
sandbox;

if (sandbox = len > 1 && parts[0] === "sandbox") {
parts.shift();
name = parts.join("!");
}

url = require.toUrl(/^\//.test(name) ? name : "./" + name, stack.length ? { name: stack[stack.length-1] } : null);
c = cache[url] || require.cache(url);

if (!c) {
x = new XMLHttpRequest;
x.open("GET", url, false);
x.send(null);
if (x.status === 200) {
c = x.responseText;
} else {
throw new Error("Failed to load include \"" + url + "\": " + x.status);
}
}

stack.push(url);
try {
require.evaluate(cache[url] = c, 0, !sandbox);
} catch (e) {
throw e;
} finally {
stack.pop();
}

onLoad(c);
}
};
});

0 comments on commit e1e3474

Please sign in to comment.