Skip to main content
MindTouch Success Center

Touchpoint Factory Events

Applies to:
MindTouch (current)
Role required:
Admin

Events

mindtouch-web-widget:factory:loaded

Fired when the widget factory is loaded. The event data contains the following parameters:

  • widget <Object> - The object interface to the widget that contains the properties and/or functions listed below
document.addEventListener('mindtouch-web-widget:factory:loaded', ({ data }) => {
    const factory = data.widget;
});

Functions

load(embedId)

Loads a created widget that has not been autoloaded. This function accepts the following parameters:

  • embedId <String> - The ID string of the widget to load
<script async="async" src="https://foo.example.com/@embed/f21e8d489c198a5e64bf073c8e65c2405e0c0f0241a8b9b78fbc59abe5856b2f.js"></script>

<!-- data-autoload="false" instructs the factory not to autoload this widget -->
<script type="mindtouch/embed" id="mindtouch-embed-f21e8d489c198a5e64bf073c8e65c2405e0c0f0241a8b9b78fbc59abe5856b2f" data-autoload="false"></script>
document.addEventListener('mindtouch-web-widget:factory:loaded', ({ data }) => {

    // assign the factory and wait for the widget to be created
    const factory = data.widget;
    document.addEventListener('mindtouch-web-widget:search:ready', ({ data }) => {
    
        // NOTE: widget loaded by ID must be in a "ready" state and not already loaded
        factory.load(data.embedId);
    });
});

The widget on-demand loading pattern can be used to control the order in which widgets are loaded in an integration. In this example, the Factory, Search-in-place, and Sign-in Touchpoints all work together in order to ensure search functionality is only available to an authenticated MindTouch user.

document.addEventListener('mindtouch-web-widget:factory:loaded', ({ data }) => {
  const factory = data.widget;
  document.addEventListener('mindtouch-web-widget:search:ready', ({ data }) => {
    
    // get unloaded search touchpoint id
    const searchEmbedId = data.embedId;
    document.addEventListener('mindtouch-web-widget:login:loaded', ({ data }) => {
      if(!data.user.anonymous) {
        
        // user is already signed in, load search touchpoint by id
        factory.load(searchEmbedId);
        return;
      }
      document.addEventListener('mindtouch-web-widget:login:auth-changed', ({ data }) => {
        
        // wait for user to sign in before loading search touchpoint by id
        if(!data.user.anonymous) {
          factory.load(searchEmbedId);
        }
      });
    });
  });
});
  • Was this article helpful?