wet-boew / wet-boew

Web Experience Toolkit (WET): Open source code library for building innovative websites that are accessible, usable, interoperable, mobile-friendly and multilingual. This collaborative open source project is led by the Government of Canada.

Home Page:https://wet-boew.github.io/wet-boew/index-en.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Determine if wb-ready.wb event has already fired.

sgdowney opened this issue · comments

Describe the purpose of this issue

Is there a way to determine if the event wb-ready.wb has already fired?

I have a JS file that uses the code below to run some code after WET has finished.

$(document).on("wb-ready.wb", function () {

The script is added to the page via the DotNetTemplates code:

WebTemplateModel.HTMLBodyElements.Add(scriptTag)

Occasionally the script code contained in the function isn't executed, It would appear the script executing after the wb-ready.wb event has fired, resulting in the function not being executed.

Note: If your request is related to security, please do not open a publicly visible "issue"; refer to SECURITY.md.

After some trial and error I believe I have a working solution to this problem.

function SetOverride() {
    // code to execute after wb-ready.wb event
}
if (wb.isReady) {
    SetOverride();
}
else {
    $(document).on("wb-ready.wb", function () {
        SetOverride();
    });
}