mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-63667 javascript: fix failed to pre-fetch the template error
This commit is contained in:
parent
c2f1dbcf49
commit
0015f5b8f1
2 changed files with 18 additions and 13 deletions
2
lib/amd/build/templates.min.js
vendored
2
lib/amd/build/templates.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -50,6 +50,9 @@ define(['core/mustache',
|
|||
/** @var {Promise[]} templatePromises - Cache of already loaded template promises */
|
||||
var templatePromises = {};
|
||||
|
||||
/** @var {Promise[]} cachePartialPromises - Cache of already loaded template partial promises */
|
||||
var cachePartialPromises = {};
|
||||
|
||||
/** @var {Object} iconSystem - Object extending core/iconsystem */
|
||||
var iconSystem = {};
|
||||
|
||||
|
@ -648,24 +651,26 @@ define(['core/mustache',
|
|||
* @return {Promise} JQuery promise object resolved when all partials are in the cache.
|
||||
*/
|
||||
Renderer.prototype.cachePartials = function(templateName) {
|
||||
return this.getTemplate(templateName).then(function(templateSource) {
|
||||
var i;
|
||||
var partials = this.scanForPartials(templateSource);
|
||||
var fetchThemAll = [];
|
||||
var searchKey = this.currentThemeName + '/' + templateName;
|
||||
|
||||
for (i = 0; i < partials.length; i++) {
|
||||
var searchKey = this.currentThemeName + '/' + partials[i];
|
||||
if (searchKey in templatePromises) {
|
||||
fetchThemAll.push(templatePromises[searchKey]);
|
||||
} else {
|
||||
fetchThemAll.push(this.cachePartials(partials[i]));
|
||||
}
|
||||
}
|
||||
if (searchKey in cachePartialPromises) {
|
||||
return cachePartialPromises[searchKey];
|
||||
}
|
||||
|
||||
var cachePartialPromise = this.getTemplate(templateName).then(function(templateSource) {
|
||||
var partials = this.scanForPartials(templateSource);
|
||||
var fetchThemAll = partials.map(function(partialName) {
|
||||
return this.cachePartials(partialName);
|
||||
}.bind(this));
|
||||
|
||||
return $.when.apply($, fetchThemAll).then(function() {
|
||||
return templateSource;
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
cachePartialPromises[searchKey] = cachePartialPromise;
|
||||
|
||||
return cachePartialPromise;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue