Skip to content

Commit

Permalink
fix: pass module name to static:script.init, +comments
Browse files Browse the repository at this point in the history
I feel it is difficult to know exactly what the original use-cases were for these hooks, so some comments may be helpful.
  • Loading branch information
julianlam committed Jan 28, 2021
1 parent 4bb3b03 commit f8bf9e9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions public/src/ajaxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ ajaxify = window.ajaxify || {};
scripts: [location + tpl_url],
};

// Hint: useful if you want to load a module on a specific page (append module name to `scripts`)
$(window).trigger('action:script.load', data);

// Require and parse modules
Expand All @@ -338,12 +339,14 @@ ajaxify = window.ajaxify || {};
}
if (typeof script === 'string') {
return function (next) {
require([script], function (script) {
$(window).trigger('static:script.init', { tpl_url, module: script });
if (script && script.init) {
script.init();
}
next();
require(['hooks', script], function (hooks, module) {
// Hint: useful if you want to override a loaded library (e.g. replace core client-side logic), or call a method other than .init()
hooks.fire('static:script.init', { tpl_url, name: script, module }).then(() => {
if (module && module.init) {
module.init();
}
next();
});
}, function () {
// ignore 404 error
next();
Expand Down

0 comments on commit f8bf9e9

Please sign in to comment.