debian-mirror-gitlab/app/assets/javascripts/lib/utils/is_navigating_away.js
2021-11-18 22:05:49 +05:30

23 lines
555 B
JavaScript

let navigating = false;
window.addEventListener('beforeunload', () => {
navigating = true;
});
/**
* To only be used for testing purposes. Allows the navigating state to be set
* to a given value.
*
* @param {boolean} value The value to set the navigating flag to.
*/
export const setNavigatingForTestsOnly = (value) => {
navigating = value;
};
/**
* Returns a boolean indicating whether the browser is in the process of
* navigating away from the current page.
*
* @returns {boolean}
*/
export const isNavigatingAway = () => navigating;