XF 2.3 Include JavaScript that depends on other JavaScript being included

Kirby

Well-known member
Sometimes I must include additional JS files that depend on other (stock XF) JS files being included, for example I would like to include js/vendor/product/message.js after xf/message.js but only if message.js is included.

So far I'me doing this by looping through getIncludedJs() but it feels complicated as I have to check several possibilities (minimized vs. not mininized, production / rollup vs. dev).

Does anybody know a more elegant / efficient way to accomplish this?
 
Hook into \XF\Template\Templater::includeJs()?
Yeah, but I need this in several Add-ons and I don't really want to hook the Templater every single time just for this or create another Add-on (that implements some convenience functionality for this) as requirement :(

The (current) code in StandardLib wouldn't work for my usecase either.

Ideally XenForo itself could probably support smth. like
<xf:js addon="Vendor/AddOnId" src="vendor/addonid/whatever.js" depends="xf/editor-compiled.js|xf/editor.js" />

Eg. vendor/addonid/whatever.js should only be included if either xf/editor-compiled.js or xf/editor.js is already included - vendor/addonid/whatever.js should not be included if neither of them isn't already included.
 
Back
Top Bottom