742f96f644
Fixes #127 Turns out this isn't actually any faster, but it is cleaner and doesn't clutter the console. We'll keep it for now.
33 lines
No EOL
780 B
JavaScript
33 lines
No EOL
780 B
JavaScript
define(function() {
|
|
|
|
var cache = {};
|
|
var directory = null;
|
|
|
|
return {
|
|
load: function(name, parentRequire, onLoad, config) {
|
|
if (name in cache) {
|
|
return onLoad(cache[name]);
|
|
}
|
|
|
|
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();
|
|
});
|
|
}
|
|
};
|
|
|
|
}); |