Skip to content

Commit

Permalink
feat(hooks): update action:ajaxify.end to use new hooks module
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jan 27, 2021
1 parent 412d285 commit 1d77572
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
12 changes: 7 additions & 5 deletions public/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
}, 3600000);
}

$(window).on('action:ajaxify.end', function () {
showCorrectNavTab();
startLogoutTimer();
require(['hooks'], (hooks) => {
hooks.on('action:ajaxify.end', () => {
showCorrectNavTab();
startLogoutTimer();
});
});

function showCorrectNavTab() {
Expand Down Expand Up @@ -66,12 +68,12 @@
});

function setupNProgress() {
require(['nprogress'], function (NProgress) {
require(['nprogress', 'hooks'], function (NProgress, hooks) {
$(window).on('action:ajaxify.start', function () {
NProgress.set(0.7);
});

$(window).on('action:ajaxify.end', function () {
hooks.on('action:ajaxify.end', function () {
NProgress.done();
});
});
Expand Down
8 changes: 6 additions & 2 deletions public/src/ajaxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ ajaxify = window.ajaxify || {};

// If any listeners alter url and set it to an empty string, abort the ajaxification
if (url === null) {
$(window).trigger('action:ajaxify.end', { url: url, tpl_url: ajaxify.data.template.name, title: ajaxify.data.title });
require(['hooks'], function (hooks) {
hooks.fire('action:ajaxify.end', { url: url, tpl_url: ajaxify.data.template.name, title: ajaxify.data.title });
});
return false;
}

Expand Down Expand Up @@ -281,7 +283,9 @@ ajaxify = window.ajaxify || {};
window.scrollTo(0, 0);
}
ajaxify.loadScript(tpl_url, function done() {
$(window).trigger('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
require(['hooks'], function (hooks) {
hooks.fire('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
});
});
ajaxify.widgets.render(tpl_url);

Expand Down
12 changes: 7 additions & 5 deletions public/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ app.cacheBuster = null;
}
};
document.body.addEventListener('click', earlyClick);
$(window).on('action:ajaxify.end', function () {
document.body.removeEventListener('click', earlyClick);
earlyQueue.forEach(function (el) {
el.click();
require(['hooks'], function (hooks) {
hooks.on('action:ajaxify.end', function () {
document.body.removeEventListener('click', earlyClick);
earlyQueue.forEach(function (el) {
el.click();
});
earlyQueue = [];
});
earlyQueue = [];
});
} else {
setTimeout(app.handleEarlyClicks, 50);
Expand Down
4 changes: 2 additions & 2 deletions public/src/modules/navigator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

define('navigator', ['forum/pagination', 'components'], function (pagination, components) {
define('navigator', ['forum/pagination', 'components', 'hooks'], function (pagination, components, hooks) {
var navigator = {};
var index = 0;
var count = 0;
Expand Down Expand Up @@ -142,7 +142,7 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
}

var mouseDragging = false;
$(window).on('action:ajaxify.end', function () {
hooks.on('action:ajaxify.end', function () {
renderPostIndex = null;
});
$('.pagination-block .dropdown-menu').parent().on('shown.bs.dropdown', function () {
Expand Down

0 comments on commit 1d77572

Please sign in to comment.