mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Switch to async rendering.
This commit is contained in:
parent
e01794a07f
commit
5efc43260e
19
js/module.js
19
js/module.js
@ -81,23 +81,26 @@ var Module = Class.extend({
|
|||||||
* return domobject - The dom to display.
|
* return domobject - The dom to display.
|
||||||
*/
|
*/
|
||||||
getDom: function () {
|
getDom: function () {
|
||||||
|
var div = document.createElement("div");
|
||||||
var template = this.getTemplate();
|
var template = this.getTemplate();
|
||||||
var templateData = this.getTemplateData();
|
var templateData = this.getTemplateData();
|
||||||
|
|
||||||
// Check to see if we need to render a template string or a file.
|
// Check to see if we need to render a template string or a file.
|
||||||
if (/^.*(\.html)$/.test(template)) {
|
if (/^.*(\.html)$/.test(template)) {
|
||||||
// the template is a filename
|
// the template is a filename
|
||||||
var filename = this.file(template);
|
this.nunjucksEnvironment().render(template, templateData, function (err, res) {
|
||||||
var content = this.nunjucksEnvironment().render(filename, templateData);
|
// The inner content of the div will be set after the template is received.
|
||||||
|
// This isn't the most optimal way, but since it's near instant
|
||||||
|
// it probably won't be an issue.
|
||||||
|
// If it gives problems, we can always add a way to pre fetch the templates.
|
||||||
|
// Let's not over optimise this ... KISS! :)
|
||||||
|
div.innerHTML = res;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// the template is a template string.
|
// the template is a template string.
|
||||||
var content = this.nunjucksEnvironment().renderString(template, templateData);
|
div.innerHTML = this.nunjucksEnvironment().renderString(template, templateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
var div = document.createElement("div");
|
|
||||||
|
|
||||||
div.innerHTML = content;
|
|
||||||
|
|
||||||
return div;
|
return div;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -163,7 +166,7 @@ var Module = Class.extend({
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader());
|
this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), {async: true}));
|
||||||
this._nunjucksEnvironment.addFilter("translate", function(str) {
|
this._nunjucksEnvironment.addFilter("translate", function(str) {
|
||||||
return self.translate(str)
|
return self.translate(str)
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user