Skip to content

Commit

Permalink
Merge branch 'timob-5859' of git://github.com/cb1kenobi/titanium_mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindelusions committed Dec 1, 2011
2 parents a989488 + 29fcdfa commit 40dd6e0
Show file tree
Hide file tree
Showing 3 changed files with 288 additions and 235 deletions.
32 changes: 0 additions & 32 deletions mobileweb/src/Ti/ti.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,10 @@
};

api.include = function(files){
/* coming soon!
var i = 0;
typeof files === "array" || (files = [].concat(Array.prototype.slice.call(arguments, 0)));
for (; i < files.length; i++) {
require("include!" + files[i]);
}
*/

var head = document.getElementsByTagName('head')[0];
if(head == null){
head = document;
}

for (var i = 0; i < arguments.length; i++){
var location = arguments[i];

var script = Ti._5.getLoadedScript(location);
if ('undefined' != typeof script) {
return Ti._5.execLoadedScript(location);
}

var absLocation = Ti._5.getAbsolutePath(location);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
Ti._5.addLoadedScript(location, xhr.responseText);
return Ti._5.execLoadedScript(location);
}
}
};
xhr.open("GET", absLocation, false);
xhr.setRequestHeader("Access-Control-Allow-Origin","*");
xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xhr.send(null);
xhr = null;
}
};
})(Ti);
37 changes: 37 additions & 0 deletions mobileweb/src/include.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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];
return (/^\./.test(url) ? normalize(url) : url) + (parts[1] ? "!" + parts[1] : "");
},

load: function (name, require, onLoad, config) {
var url = require.toUrl(name, stack.length ? { name: stack[stack.length-1] } : null),
c = cache[url] || require.cache(url),
x;

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);
require.evaluate(cache[url] = c, 0, true);
stack.pop();

onLoad(c);
}
};
});

0 comments on commit 40dd6e0

Please sign in to comment.