From 049a3374aa85f33091f0e7cba8635edd4b4786bd Mon Sep 17 00:00:00 2001 From: Yuri S Date: Wed, 27 Dec 2017 18:39:44 +0500 Subject: [PATCH] Fix IE 10 and IE 11's broken `preventDefault` https://github.com/turbolinks/turbolinks/issues/233 https://stackoverflow.com/questions/23349191/event-preventdefault-is-not-working-in-ie-11-for-custom-events --- .../app/assets/javascripts/rails-ujs/utils/event.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee index a2135c98518a2..c8fbc64b51125 100644 --- a/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee @@ -10,6 +10,11 @@ if typeof CustomEvent isnt 'function' CustomEvent = (event, params) -> evt = document.createEvent('CustomEvent') evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail) + # IE does not set `defaultPrevented` when `preventDefault()` is called on CustomEvents + # http://stackoverflow.com/questions/23349191/event-preventdefault-is-not-working-in-ie-11-for-custom-events + evt.preventDefault = -> + Object.defineProperty this, 'defaultPrevented', get: -> + true evt CustomEvent.prototype = window.Event.prototype