Your IP : 3.16.75.169


Current Path : /var/www/axolotl/data/www/rostov.axolotls.ru/bitrix/js/main/core/src/lib/event/
Upload File :
Current File : /var/www/axolotl/data/www/rostov.axolotls.ru/bitrix/js/main/core/src/lib/event/ready.js

import Type from '../type';

let stack: Array<Function> = [];
/**
 * For compatibility only
 * @type {boolean}
 */
// eslint-disable-next-line
export let isReady = false;

export default function ready(handler: () => void)
{
	switch (document.readyState)
	{
		case 'loading':
			stack.push(handler);
			break;
		case 'interactive':
		case 'complete':
			if (Type.isFunction(handler))
			{
				handler();
			}

			isReady = true;
			break;
		default:
			break;
	}
}

document.addEventListener('readystatechange', () => {
	if (!isReady)
	{
		stack.forEach(ready);
		stack = [];
	}
});