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

Version Path
fenton-jekyll-boilerplate-0.0.11 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.10 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.9 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.8 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.7 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.6 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.4 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.3 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.2 assets/js/modules/resizing.js
fenton-jekyll-boilerplate-0.0.1 assets/js/modules/resizing.js