mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-14 11:55:56 +00:00
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
This commit is contained in:
@@ -5,50 +5,123 @@
|
||||
*/
|
||||
|
||||
|
||||
if(!dojo._hasResource["dojo.cache"]){
|
||||
dojo._hasResource["dojo.cache"]=true;
|
||||
if(!dojo._hasResource["dojo.cache"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
||||
dojo._hasResource["dojo.cache"] = true;
|
||||
dojo.provide("dojo.cache");
|
||||
|
||||
/*=====
|
||||
dojo.cache = {
|
||||
// summary:
|
||||
// A way to cache string content that is fetchable via `dojo.moduleUrl`.
|
||||
};
|
||||
=====*/
|
||||
|
||||
(function(){
|
||||
var _1={};
|
||||
dojo.cache=function(_2,_3,_4){
|
||||
if(typeof _2=="string"){
|
||||
var _5=dojo.moduleUrl(_2,_3);
|
||||
}else{
|
||||
_5=_2;
|
||||
_4=_3;
|
||||
}
|
||||
var _6=_5.toString();
|
||||
var _7=_4;
|
||||
if(_4!=undefined&&!dojo.isString(_4)){
|
||||
_7=("value" in _4?_4.value:undefined);
|
||||
}
|
||||
var _8=_4&&_4.sanitize?true:false;
|
||||
if(typeof _7=="string"){
|
||||
_7=_1[_6]=_8?dojo.cache._sanitize(_7):_7;
|
||||
}else{
|
||||
if(_7===null){
|
||||
delete _1[_6];
|
||||
}else{
|
||||
if(!(_6 in _1)){
|
||||
_7=dojo._getText(_6);
|
||||
_1[_6]=_8?dojo.cache._sanitize(_7):_7;
|
||||
}
|
||||
_7=_1[_6];
|
||||
}
|
||||
}
|
||||
return _7;
|
||||
};
|
||||
dojo.cache._sanitize=function(_9){
|
||||
if(_9){
|
||||
_9=_9.replace(/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,"");
|
||||
var _a=_9.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
|
||||
if(_a){
|
||||
_9=_a[1];
|
||||
}
|
||||
}else{
|
||||
_9="";
|
||||
}
|
||||
return _9;
|
||||
};
|
||||
var cache = {};
|
||||
dojo.cache = function(/*String||Object*/module, /*String*/url, /*String||Object?*/value){
|
||||
// summary:
|
||||
// A getter and setter for storing the string content associated with the
|
||||
// module and url arguments.
|
||||
// description:
|
||||
// module and url are used to call `dojo.moduleUrl()` to generate a module URL.
|
||||
// If value is specified, the cache value for the moduleUrl will be set to
|
||||
// that value. Otherwise, dojo.cache will fetch the moduleUrl and store it
|
||||
// in its internal cache and return that cached value for the URL. To clear
|
||||
// a cache value pass null for value. Since XMLHttpRequest (XHR) is used to fetch the
|
||||
// the URL contents, only modules on the same domain of the page can use this capability.
|
||||
// The build system can inline the cache values though, to allow for xdomain hosting.
|
||||
// module: String||Object
|
||||
// If a String, the module name to use for the base part of the URL, similar to module argument
|
||||
// to `dojo.moduleUrl`. If an Object, something that has a .toString() method that
|
||||
// generates a valid path for the cache item. For example, a dojo._Url object.
|
||||
// url: String
|
||||
// The rest of the path to append to the path derived from the module argument. If
|
||||
// module is an object, then this second argument should be the "value" argument instead.
|
||||
// value: String||Object?
|
||||
// If a String, the value to use in the cache for the module/url combination.
|
||||
// If an Object, it can have two properties: value and sanitize. The value property
|
||||
// should be the value to use in the cache, and sanitize can be set to true or false,
|
||||
// to indicate if XML declarations should be removed from the value and if the HTML
|
||||
// inside a body tag in the value should be extracted as the real value. The value argument
|
||||
// or the value property on the value argument are usually only used by the build system
|
||||
// as it inlines cache content.
|
||||
// example:
|
||||
// To ask dojo.cache to fetch content and store it in the cache (the dojo["cache"] style
|
||||
// of call is used to avoid an issue with the build system erroneously trying to intern
|
||||
// this example. To get the build system to intern your dojo.cache calls, use the
|
||||
// "dojo.cache" style of call):
|
||||
// | //If template.html contains "<h1>Hello</h1>" that will be
|
||||
// | //the value for the text variable.
|
||||
// | var text = dojo["cache"]("my.module", "template.html");
|
||||
// example:
|
||||
// To ask dojo.cache to fetch content and store it in the cache, and sanitize the input
|
||||
// (the dojo["cache"] style of call is used to avoid an issue with the build system
|
||||
// erroneously trying to intern this example. To get the build system to intern your
|
||||
// dojo.cache calls, use the "dojo.cache" style of call):
|
||||
// | //If template.html contains "<html><body><h1>Hello</h1></body></html>", the
|
||||
// | //text variable will contain just "<h1>Hello</h1>".
|
||||
// | var text = dojo["cache"]("my.module", "template.html", {sanitize: true});
|
||||
// example:
|
||||
// Same example as previous, but demostrates how an object can be passed in as
|
||||
// the first argument, then the value argument can then be the second argument.
|
||||
// | //If template.html contains "<html><body><h1>Hello</h1></body></html>", the
|
||||
// | //text variable will contain just "<h1>Hello</h1>".
|
||||
// | var text = dojo["cache"](new dojo._Url("my/module/template.html"), {sanitize: true});
|
||||
|
||||
//Module could be a string, or an object that has a toString() method
|
||||
//that will return a useful path. If it is an object, then the "url" argument
|
||||
//will actually be the value argument.
|
||||
if(typeof module == "string"){
|
||||
var pathObj = dojo.moduleUrl(module, url);
|
||||
}else{
|
||||
pathObj = module;
|
||||
value = url;
|
||||
}
|
||||
var key = pathObj.toString();
|
||||
|
||||
var val = value;
|
||||
if(value != undefined && !dojo.isString(value)){
|
||||
val = ("value" in value ? value.value : undefined);
|
||||
}
|
||||
|
||||
var sanitize = value && value.sanitize ? true : false;
|
||||
|
||||
if(typeof val == "string"){
|
||||
//We have a string, set cache value
|
||||
val = cache[key] = sanitize ? dojo.cache._sanitize(val) : val;
|
||||
}else if(val === null){
|
||||
//Remove cached value
|
||||
delete cache[key];
|
||||
}else{
|
||||
//Allow cache values to be empty strings. If key property does
|
||||
//not exist, fetch it.
|
||||
if(!(key in cache)){
|
||||
val = dojo._getText(key);
|
||||
cache[key] = sanitize ? dojo.cache._sanitize(val) : val;
|
||||
}
|
||||
val = cache[key];
|
||||
}
|
||||
return val; //String
|
||||
};
|
||||
|
||||
dojo.cache._sanitize = function(/*String*/val){
|
||||
// summary:
|
||||
// Strips <?xml ...?> declarations so that external SVG and XML
|
||||
// documents can be added to a document without worry. Also, if the string
|
||||
// is an HTML document, only the part inside the body tag is returned.
|
||||
// description:
|
||||
// Copied from dijit._Templated._sanitizeTemplateString.
|
||||
if(val){
|
||||
val = val.replace(/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, "");
|
||||
var matches = val.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
|
||||
if(matches){
|
||||
val = matches[1];
|
||||
}
|
||||
}else{
|
||||
val = "";
|
||||
}
|
||||
return val; //String
|
||||
};
|
||||
})();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user