debian-mirror-gitlab/app/assets/javascripts/lib/utils/is_navigating_away.js

24 lines
555 B
JavaScript
Raw Normal View History

2021-11-18 22:05:49 +05:30
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;