msn0 / mdn-polyfills

MDN polyfills - from, forEach, filter, find, findIndex, assign, includes, create, entries, of, repeat, startsWith, endsWith, toggleAttribute, bind, MouseEvent, CustomEvent, padEnd, padStart
https://msn0.github.io/mdn-polyfills
175 stars 25 forks source link

MouseEvent doesn't take params #60

Closed Yohandah closed 5 years ago

Yohandah commented 5 years ago

Hello,

The implementation of MouseEvent doesn't match the one currently at : https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent

So ScreenX, ClientX, etc doesn't work ...

(function (window) {
  try {
    new MouseEvent('test');
    return false; // No need to polyfill
  } catch (e) {
        // Need to polyfill - fall through
  }

    // Polyfills DOM4 MouseEvent
    var MouseEventPolyfill = function (eventType, params) {
        params = params || { bubbles: false, cancelable: false };
        var mouseEvent = document.createEvent('MouseEvent');
        mouseEvent.initMouseEvent(eventType, 
            params.bubbles,
            params.cancelable,
            window,
            0,
            params.screenX || 0,
            params.screenY || 0,
            params.clientX || 0,
            params.clientY || 0,
            params.ctrlKey || false,
            params.altKey || false,
            params.shiftKey || false,
            params.metaKey || false,
            params.button || 0,
            params.relatedTarget || null
        );

        return mouseEvent;
    }

    MouseEventPolyfill.prototype = Event.prototype;

    window.MouseEvent = MouseEventPolyfill;
})(window);
msn0 commented 5 years ago

Thank you @meepou. Please use 📦 mdn-polyfills@5.17.1