Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ontoggle event handler support #1

Open
aristov opened this issue Oct 26, 2016 · 1 comment
Open

ontoggle event handler support #1

aristov opened this issue Oct 26, 2016 · 1 comment

Comments

@aristov
Copy link

aristov commented Oct 26, 2016

Hello!

This code adds a support of the ontoggle event handler in Safari, which lacks this feature:

{
    const { HTMLElement : { prototype } } = window;
    if(!('ontoggle' in prototype)) {
        Object.defineProperties(prototype, {
            ontoggle : {
                configurable : true,
                enumerable : true,
                set(handler) {
                    this.__handler_ontoggle__ = typeof handler === 'function'?
                        handler.bind(this) :
                        null;
                },
                get() {
                    return this.__handler_ontoggle__;
                }
            },
            __handler_ontoggle__ : { writable : true, value : null }
        });
        document.addEventListener('toggle', event => {
            const target = event.target;
            if(typeof target.ontoggle) target.ontoggle(event);
        }, true);
    }
}

Usage:

const details = document.createElement('details');
details.ontoggle(handler);

I don't know CoffeeScript, sorry.
And thanks for this stuff!

@Flimm
Copy link

Flimm commented May 25, 2017

According to caniuse, the latest version of Safari 10.1 does not have this issue any more. I haven't tested it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants