Use Benchpress (#5901)

* Use Benchpress

* Use Benchpress.compileParse

* Error for template load failure

* Use benchpressjs package

* Compile templates on demand

* Fix user settings page

* Fix admin search to exclude `.jst` files

* Fix 500-embed

So ajaxify can still show an error if the server goes down
This commit is contained in:
Peter Jaszkowiak
2017-08-24 17:26:50 -06:00
committed by Barış Soner Uşaklı
parent 864321f727
commit abffc29128
16 changed files with 128 additions and 55 deletions

View File

@@ -328,20 +328,10 @@ $(document).ready(function () {
};
ajaxify.loadTemplate = function (template, callback) {
if (templates.cache[template]) {
callback(templates.cache[template]);
} else {
$.ajax({
url: config.relative_path + '/assets/templates/' + template + '.tpl?' + config['cache-buster'],
type: 'GET',
success: function (data) {
callback(data.toString());
},
error: function (error) {
throw new Error('Unable to load template: ' + template + ' (' + error.statusText + ')');
},
});
}
require([config.relative_path + '/assets/templates/' + template + '.jst'], callback, function (err) {
console.error('Unable to load template: ' + template);
throw err;
});
};
function ajaxifyAnchors() {
@@ -424,7 +414,9 @@ $(document).ready(function () {
});
}
templates.registerLoader(ajaxify.loadTemplate);
require(['benchpress'], function (Benchpress) {
Benchpress.registerLoader(ajaxify.loadTemplate);
});
if (window.history && window.history.pushState) {
// Progressive Enhancement, ajaxify available only to modern browsers
@@ -432,9 +424,4 @@ $(document).ready(function () {
}
app.load();
$('[type="text/tpl"][data-template]').each(function () {
templates.cache[$(this).attr('data-template')] = $('<div/>').html($(this).html()).text();
$(this).parent().remove();
});
});