Caret/js/util/text.js

33 lines
780 B
JavaScript
Raw Normal View History

2013-12-16 19:29:41 +00:00
define(function() {
var cache = {};
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]);
}
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
}
};
});