Code Monkey home page Code Monkey logo

ie9-oninput-polyfill's People

Contributors

buzinas avatar dkamorin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ie9-oninput-polyfill's Issues

Add a license

Hi, I am interested in using this in a project, but there doesn't appear to be a license for this code. Could you add one? If you need help deciding, this is a good guide: http://choosealicense.com/

Infinite event loop

Because the polyfill listen to any selectionChange event to trigger a synthetic input event, if one is to call setSelectionRange() from within a input event handler, then an infinite event loop occurs (setSelectionRange() does trigger a selectionChange).

My take, cause I'm aware that this project is not really alive, and also too lazy to do a proper PR

(function ($nav, $doc) {
    "use strict";

    var $targetInput;

    function isTextField($elem) {
        return $elem.tagName === "TEXTAREA" || ($elem.tagName === "INPUT" && $elem.type === "text");
    }

    // using bitwise NOT to compare against -1 as  ~(-1) returns 0
    // (~indexOf) is similar to (indexOf != -1)
    if (~$nav.userAgent.indexOf("MSIE 9")) {
        $doc.addEventListener("keydown", function (e) {
            // 8    backspace
            // 46   delete
            if (isTextField(e.target) && ~[8, 46].indexOf(e.which)) {
                $targetInput = e.target;
            }
        });

        $doc.addEventListener("cut", function (e) {
            // Note: cut is triggered before the action
            if (isTextField(e.target)) {
                $targetInput = e.target;
            }
        });

        $doc.addEventListener("selectionchange", function () {
            var event;

            if ($targetInput && $targetInput === $doc.activeElement) {
                event = $doc.createEvent("CustomEvent");
                event.initCustomEvent("input", true, false, {});
                $targetInput.dispatchEvent(event);
                $targetInput = null;
            }
        });
    }
})(navigator, document);

Please publish to npm

Very useful utility - would be great if you could please publish to npm?

Thanks much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.