Sha256: 12bdd82dac218531a48a2dee8cfb4b958f49d1bb82c2670869a7f724a7e9a6b5
Contents?: true
Size: 994 Bytes
Versions: 10
Compression:
Stored size: 994 Bytes
Contents
// @ts-check import { raiseEvent } from './events.js'; var resizeEventName = 'resize'; var resizedEventName = 'resized'; var width = window.innerWidth; var height = window.innerHeight; /** * Adds a de-bounced "resized" event, so you can listen to: * document.addEventListener('resized', <handler>); * * @returns {string} */ function addResizedEvent() { var debounce = null; function resizeEnd(e) { window.clearTimeout(debounce); debounce = window.setTimeout(raiseResizeEvent, 500); } function raiseResizeEvent() { var change = { width: window.innerWidth - width, height: window.innerHeight - height }; width = window.innerWidth; height = window.innerHeight; raiseEvent(resizedEventName, { change: change }); } window.addEventListener(resizeEventName, resizeEnd); return resizedEventName; } export { addResizedEvent };
Version data entries
10 entries across 10 versions & 1 rubygems