2013-12-16 19:29:41 +00:00
|
|
|
define(function() {
|
|
|
|
|
|
|
|
var cache = {};
|
2014-01-13 05:09:44 +00:00
|
|
|
var directory = null;
|
2013-12-16 19:29:41 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
load: function(name, parentRequire, onLoad, config) {
|
|
|
|
if (name in cache) {
|
|
|
|
return onLoad(cache[name]);
|
|
|
|
}
|
|
|
|
|
2014-01-13 05:09:44 +00:00
|
|
|
var getFile = function() {
|
|
|
|
directory.getFile(name, {create: false}, function(entry) {
|
|
|
|
entry.file(function(file) {
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onloadend = function() {
|
|
|
|
cache[name] = reader.result;
|
|
|
|
onLoad(reader.result);
|
|
|
|
};
|
|
|
|
reader.readAsText(file);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (directory) return getFile();
|
|
|
|
chrome.runtime.getPackageDirectoryEntry(function(dir) {
|
|
|
|
directory = dir;
|
|
|
|
getFile();
|
|
|
|
});
|
2013-12-16 19:29:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|