Difficulties in correctly adding external JavaScript

Evidently my search skills failed me. There was already a thread that existed asking about RefTagger, with an answer there that works.

I was indeed correct in thinking that decorateCooked() would be used. All credit to @david who posted the solution on the thread linked above! (Also credit to @thwright for finding this older solution and letting me know about it).

Here’s the code I’m putting in </head> via the theme customization, with some of the specific RefTagger settings:

<script type="text/discourse-plugin" version="0.2">
window.refTagger = {
	settings: {
		bibleVersion: "NKJV",
		convertHyperlinks: false,		
		roundCorners: true,
		socialSharing: [],
		tagChapters: true
	}
};

let loadScript = require('discourse/lib/load-script').default;

api.decorateCooked($elem => {
    loadScript("//api.reftagger.com/v2/RefTagger.js").then(()=>{
        window.refTagger.tag($elem[0]);    
    })
});
</script>
3 Likes