Commit 06b3ac6c authored by Eloy Lafuente (stronk7)'s avatar Eloy Lafuente (stronk7)

Merge branch 'MDL-70802-310' of git://github.com/andrewnicols/moodle into MOODLE_310_STABLE

parents 4c8c9a4c 06c9de6b
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
......@@ -68,6 +68,22 @@ define([
/** @var {Array} disallowedNestedHelpers - List of helpers that can't be called within other helpers */
var disallowedNestedHelpers = ['js'];
/**
* Normalise the provided component such that '', 'moodle', and 'core' are treated consistently.
*
* @param {String} component
* @returns {String}
*/
var getNormalisedComponent = function(component) {
if (component) {
if (component !== 'moodle' && component !== 'core') {
return component;
}
}
return 'core';
};
/**
* Search the various caches for a template promise for the given search key.
* The search key should be in the format <theme>/<component>/<template> e.g. boost/core/modal.
......@@ -133,7 +149,7 @@ define([
var requests = [];
// Get a list of promises for each of the templates we need to load.
var templatePromises = templatesToLoad.map(function(templateData) {
var component = templateData.component;
var component = getNormalisedComponent(templateData.component);
var name = templateData.name;
var searchKey = templateData.searchKey;
var theme = templateData.theme;
......@@ -177,6 +193,7 @@ define([
// Process all of the template dependencies for this template and add
// them to the caches so that we don't request them again later.
response.templates.forEach(function(data) {
data.component = getNormalisedComponent(data.component);
// Generate the search key for this template in the response so that we
// can add it to the caches.
var tempSearchKey = [theme, data.component, data.name].join('/');
......@@ -200,7 +217,7 @@ define([
// with them now so that we don't need to re-fetch them.
str.cache_strings(response.strings.map(function(data) {
return {
component: data.component,
component: getNormalisedComponent(data.component),
key: data.name,
value: data.value
};
......@@ -315,7 +332,7 @@ define([
// This is the first time this has been requested so let's add it to the buffer
// to be loaded.
var parts = templateName.split('/');
var component = parts.shift();
var component = getNormalisedComponent(parts.shift());
var name = parts.join('/');
var deferred = $.Deferred();
......@@ -361,7 +378,7 @@ define([
// This is the first time this has been requested so let's add it to the buffer to be loaded.
var parts = templateName.split('/');
var component = parts.shift();
var component = getNormalisedComponent(parts.shift());
var name = parts.join('/');
// Add this template to the buffer to be loaded.
......@@ -409,6 +426,7 @@ define([
Renderer.prototype.renderIcon = function(key, component, title) {
// Preload the module to do the icon rendering based on the theme iconsystem.
var modulename = config.iconsystemmodule;
component = getNormalisedComponent(component);
// RequireJS does not return a promise.
var ready = $.Deferred();
......@@ -425,7 +443,12 @@ define([
return ready.then(function(iconSystem) {
return this.getTemplate(iconSystem.getTemplateName());
}.bind(this)).then(function(template) {
return iconSystem.renderIcon(key, component, title, template);
return iconSystem.renderIcon(
key,
component,
title,
template
);
});
};
......@@ -456,15 +479,21 @@ define([
}
var templateName = iconSystem.getTemplateName();
var searchKey = this.currentThemeName + '/' + templateName;
var template = templateCache[searchKey];
component = getNormalisedComponent(component);
// The key might have been escaped by the JS Mustache engine which
// converts forward slashes to HTML entities. Let us undo that here.
key = key.replace(/&#x2F;/gi, '/');
return iconSystem.renderIcon(key, component, text, template);
return iconSystem.renderIcon(
key,
component,
text,
template
);
};
/**
......@@ -508,9 +537,7 @@ define([
param = parts.join(',').trim();
}
if (!component || component === 'moodle') {
component = 'core';
}
component = getNormalisedComponent(component);
if (param !== '') {
// Allow variable expansion in the param part only.
......@@ -522,7 +549,11 @@ define([
}
var index = this.requiredStrings.length;
this.requiredStrings.push({key: key, component: component, param: param});
this.requiredStrings.push({
key: key,
component: component,
param: param
});
// The placeholder must not use {{}} as those can be misinterpreted by the engine.
return '[[_s' + index + ']]';
......@@ -545,7 +576,7 @@ define([
// This involves wrapping {{, and }} in change delimeter tags.
content = content
.replace(/"/g, '\\"')
.replace(/([\{\}]{2,3})/g, '{{=<% %>=}}$1<%={{ }}=%>')
.replace(/([{}]{2,3})/g, '{{=<% %>=}}$1<%={{ }}=%>')
.replace(/(\r\n|\r|\n)/g, '&#x0a;')
;
return '"' + content + '"';
......@@ -1173,7 +1204,11 @@ define([
*/
renderPix: function(key, component, title) {
var renderer = new Renderer();
return renderer.renderIcon(key, component, title);
return renderer.renderIcon(
key,
getNormalisedComponent(component),
title
);
},
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment