Sha256: 77fe034066438cb39ff91c295d234d6b5cc3762adace6e52ee3272b811138853

Contents?: true

Size: 971 Bytes

Versions: 66

Compression:

Stored size: 971 Bytes

Contents

// see https://github.com/alphagov/govuk_publishing_components/blob/main/docs/lib/trigger_event.md
(function (root) {
  'use strict'
  window.GOVUK = window.GOVUK || {}

  window.GOVUK.triggerEvent = function (element, eventName, parameters) {
    var params = parameters || {}
    var event
    var keyCode = params.keyCode

    if (!Object.prototype.hasOwnProperty.call(params, 'bubbles')) {
      params.bubbles = true
    }

    if (!Object.prototype.hasOwnProperty.call(params, 'cancelable')) {
      params.cancelable = true
    }

    if (typeof window.CustomEvent === 'function') {
      event = new window.CustomEvent(eventName, params)
    } else {
      event = document.createEvent('CustomEvent')
      event.initCustomEvent(eventName, params.bubbles, params.cancelable, params.detail)
    }

    if (keyCode) {
      event.keyCode = keyCode
    }

    if (params.shiftKey) {
      event.shiftKey = true
    }

    element.dispatchEvent(event)
  }
}(window))

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
govuk_publishing_components-45.9.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.8.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.7.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.6.1 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.6.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.5.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.4.1 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.4.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.3.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.2.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.1.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-45.0.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.11.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.10.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.9.1 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.9.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.8.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.7.1 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.7.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
govuk_publishing_components-44.6.0 app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js