Sha256: 9fa23e6a96b3568709f7aa2881dad127ed5803e98bb2637be3e524b81d6d6204

Contents?: true

Size: 996 Bytes

Versions: 4

Compression:

Stored size: 996 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() {
    let debounce = null;

    function resizeEnd(e) {
        window.clearTimeout(debounce);
        debounce = window.setTimeout(raiseResizeEvent, 500);
    }

    function raiseResizeEvent() {
        const 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

4 entries across 4 versions & 1 rubygems

Version Path
fenton-jekyll-boilerplate-0.0.15 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.14 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.13 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.12 assets/js/modules/resizing.js