replace ejs-utils with ejs-render-remote
This commit is contained in:
@@ -16,15 +16,15 @@
|
||||
MyApp.renderShell = function() {
|
||||
document.title = i18next.t('vanillaJS');
|
||||
|
||||
$('.js-main-content').html(ejs.rtfe('/templates/main.ejs'));
|
||||
$('.js-main-content').html(ejs.rr('/templates/main.ejs'));
|
||||
};
|
||||
|
||||
MyApp.renderHomePage = function() {
|
||||
$('.js-page-container').html(ejs.rtfe('/templates/home.ejs'));
|
||||
$('.js-page-container').html(ejs.rr('/templates/home.ejs'));
|
||||
};
|
||||
|
||||
MyApp.renderTextPage = function() {
|
||||
$('.js-page-container').html(ejs.rtfe('/templates/sometext.ejs', {
|
||||
$('.js-page-container').html(ejs.rr('/templates/sometext.ejs', {
|
||||
texts: [
|
||||
{
|
||||
id: 100,
|
||||
@@ -39,7 +39,7 @@
|
||||
};
|
||||
|
||||
MyApp.renderAboutPage = function() {
|
||||
$('.js-page-container').html(ejs.rtfe('/templates/about.ejs'));
|
||||
$('.js-page-container').html(ejs.rr('/templates/about.ejs'));
|
||||
};
|
||||
|
||||
// events
|
||||
|
77
js/thirdparty/ejs-utils.js
vendored
77
js/thirdparty/ejs-utils.js
vendored
@@ -1,77 +0,0 @@
|
||||
//if this does not work, call Simon. https://github.com/S2-
|
||||
|
||||
//this uses jQuery for now because ie11 support is needed
|
||||
|
||||
(function($) {
|
||||
var uuidv4 = function() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0;
|
||||
var v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
};
|
||||
|
||||
ejs.rtfe = function(templateUrl, data) {
|
||||
var templateFn = ejs.cache.get(templateUrl);
|
||||
|
||||
//if the template is already cached, return it and we are done
|
||||
if (templateFn) {
|
||||
//but first check if there is still a getter function for this template in the cache
|
||||
//if yes, remove it so we clean up a bit
|
||||
if (ejs.cache.remove && ejs.cache.get('getFnFor' + templateUrl)) {
|
||||
ejs.cache.remove('getFnFor' + templateUrl);
|
||||
}
|
||||
|
||||
return templateFn(data);
|
||||
|
||||
} else { //if the template is not cached, we need to get it and render it later once we have it. remember: this happens only if the template is not already cached
|
||||
|
||||
//is there a getFn for this template?
|
||||
var getTemplateFn = ejs.cache.get('getFnFor' + templateUrl);
|
||||
if (!getTemplateFn) {
|
||||
getTemplateFn = $.get(templateUrl);
|
||||
ejs.cache.set('getFnFor' + templateUrl, getTemplateFn);
|
||||
}
|
||||
|
||||
var r = uuidv4();
|
||||
getTemplateFn.then(function(template) {
|
||||
$('#' + r).replaceWith(
|
||||
ejs.render(
|
||||
template,
|
||||
data,
|
||||
{
|
||||
cache: true,
|
||||
filename: templateUrl
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return '<span class="ejs-templateplaceholder" style="display: none;" id="' + r + '"></span>';
|
||||
}
|
||||
};
|
||||
|
||||
ejs.preloadTft = function(templateUrl) {
|
||||
var d = $.Deferred();
|
||||
|
||||
//if the template is already cached, just return.
|
||||
if (ejs.cache.get(templateUrl)) {
|
||||
d.resolve();
|
||||
} else {
|
||||
$.get(templateUrl)
|
||||
.then(function(template) {
|
||||
var templateFn = ejs.compile(template,
|
||||
{
|
||||
cache: true,
|
||||
filename: templateUrl
|
||||
});
|
||||
|
||||
ejs.cache.set(templateUrl, templateFn);
|
||||
|
||||
d.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
})(jQuery);
|
Reference in New Issue
Block a user