Skip to content

Commit

Permalink
refactor: remove old hack
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Dec 2, 2020
1 parent 6f68f4d commit 73746bb
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions public/src/ajaxify.js
Expand Up @@ -7,19 +7,9 @@ ajaxify = window.ajaxify || {};
var apiXHR = null;
var ajaxifyTimer;

var translator;
var Benchpress;
var retry = true;
var previousBodyClass = '';

// Dumb hack to fool ajaxify into thinking translator is still a global
// When ajaxify is migrated to a require.js module, then this can be merged into the "define" call
require(['translator', 'benchpress'], function (_translator, _Benchpress) {
translator = _translator;
translator.translate('[[error:no-connection]]');
Benchpress = _Benchpress;
});

ajaxify.count = 0;
ajaxify.currentPage = null;

Expand Down Expand Up @@ -170,26 +160,27 @@ ajaxify = window.ajaxify || {};

function renderTemplate(url, tpl_url, data, callback) {
$(window).trigger('action:ajaxify.loadingTemplates', {});
require(['translator', 'benchpress'], function (translator, Benchpress) {
Benchpress.render(tpl_url, data)
.then(rendered => translator.translate(rendered))
.then(function (translated) {
translated = translator.unescape(translated);
$('body').removeClass(previousBodyClass).addClass(data.bodyClass);
$('#content').html(translated);

ajaxify.end(url, tpl_url);

if (typeof callback === 'function') {
callback();
}

Benchpress.render(tpl_url, data)
.then(rendered => translator.translate(rendered))
.then(function (translated) {
translated = translator.unescape(translated);
$('body').removeClass(previousBodyClass).addClass(data.bodyClass);
$('#content').html(translated);

ajaxify.end(url, tpl_url);

if (typeof callback === 'function') {
callback();
}

$('#content, #footer').removeClass('ajaxifying');
$('#content, #footer').removeClass('ajaxifying');

// Only executed on ajaxify. Otherwise these'd be in ajaxify.end()
updateTitle(data.title);
updateTags();
});
// Only executed on ajaxify. Otherwise these'd be in ajaxify.end()
updateTitle(data.title);
updateTags();
});
});
}

function updateTitle(title) {
Expand Down

0 comments on commit 73746bb

Please sign in to comment.