Sha256: b1671f70d2c5dff717cad463ef6c232a25d3c4f780564aa43e9ec9c4d50a4f61

Contents?: true

Size: 1021 Bytes

Versions: 44

Compression:

Stored size: 1021 Bytes

Contents

/* eslint-disable require-jsdoc */
/* eslint-disable no-prototype-builtins, no-restricted-syntax, no-param-reassign */

let callbacks = {};

export default function registerCallback(callbackId, callback) {
  callbacks[callbackId] = callback;
}

const unregisterCallback = (callbackId) => {
  callbacks[callbackId] = null;
}

const pushState = (url, state = null) => {
  if (window.history) {
    window.history.pushState(state, null, url);
  }
};

const replaceState = (url, state = null) => {
  if (window.history) {
    window.history.replaceState(state, null,  url);
  }
};

const state = () => {
  if (window.history) {
    return window.history.state;
  }
  return null;
};

window.onpopstate = (event) => {
  // Ensure the event is caused by user action
  if (event.isTrusted) {
    for (let callbackId in callbacks) {
      if (callbacks.hasOwnProperty(callbackId)) {
        callbacks[callbackId](event.state);
      }
    }
  }
}

export { registerCallback, unregisterCallback, pushState, replaceState, state };

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/packs/src/decidim/history.js
decidim-core-0.28.4 app/packs/src/decidim/history.js
decidim-core-0.27.9 app/packs/src/decidim/history.js
decidim-core-0.29.0 app/packs/src/decidim/history.js
decidim-core-0.28.3 app/packs/src/decidim/history.js
decidim-core-0.27.8 app/packs/src/decidim/history.js
decidim-core-0.29.0.rc4 app/packs/src/decidim/history.js
decidim-core-0.29.0.rc3 app/packs/src/decidim/history.js
decidim-core-0.29.0.rc2 app/packs/src/decidim/history.js
decidim-core-0.29.0.rc1 app/packs/src/decidim/history.js
decidim-core-0.28.2 app/packs/src/decidim/history.js
decidim-core-0.27.7 app/packs/src/decidim/history.js
decidim-core-0.28.1 app/packs/src/decidim/history.js
decidim-core-0.27.6 app/packs/src/decidim/history.js
decidim-core-0.26.10 app/packs/src/decidim/history.js
decidim-core-0.26.9 app/packs/src/decidim/history.js
decidim-core-0.28.0 app/packs/src/decidim/history.js
decidim-core-0.27.5 app/packs/src/decidim/history.js
decidim-core-0.28.0.rc5 app/packs/src/decidim/history.js
decidim-core-0.28.0.rc4 app/packs/src/decidim/history.js