Sha256: 1cc1e2a84c89e7b8e5f90cb11a8e25d54ac8a0bcda29367407eb7bbbb0610539

Contents?: true

Size: 1.03 KB

Versions: 33

Compression:

Stored size: 1.03 KB

Contents

/**
 * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
 * This seems to fail in IE8, requires more investigation.
 * See: https://github.com/imagitama/nodelist-foreach-polyfill
 */
export function nodeListForEach (nodes, callback) {
  if (window.NodeList.prototype.forEach) {
    return nodes.forEach(callback)
  }
  for (var i = 0; i < nodes.length; i++) {
    callback.call(window, nodes[i], i, nodes)
  }
}

// Used to generate a unique string, allows multiple instances of the component without
// Them conflicting with each other.
// https://stackoverflow.com/a/8809472
export function generateUniqueID () {
  var d = new Date().getTime()
  if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
    d += window.performance.now() // use high-precision timer if available
  }
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    var r = (d + Math.random() * 16) % 16 | 0
    d = Math.floor(d / 16)
    return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
  })
}

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
govuk_publishing_components-32.1.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-32.0.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-31.2.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-31.1.2 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-31.1.1 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-31.1.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-31.0.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.7.3 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.7.2 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.7.1 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.7.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.6.1 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.6.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.5.2 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.5.1 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.5.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.4.1 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.4.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.3.0 node_modules/govuk-frontend/govuk-esm/common.mjs
govuk_publishing_components-30.2.1 node_modules/govuk-frontend/govuk-esm/common.mjs