From 5ed895962ed4b285184e6e00cd3f96d7d38f509a Mon Sep 17 00:00:00 2001 From: Pavel Janda Date: Mon, 7 Mar 2016 13:35:51 +0100 Subject: [PATCH] IE support for events dispatching --- dist/happy.js | 14 ++++++++++---- gulpfile.js | 4 ++-- src/coffee/happy.coffee | 11 +++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/dist/happy.js b/dist/happy.js index 602c819..ba93266 100644 --- a/dist/happy.js +++ b/dist/happy.js @@ -135,7 +135,7 @@ Happy = (function() { }; Happy.prototype.checkCheckboxStateOnClick = function(e) { - var event, happy_input, input, selector; + var event, happy_input, ie, input, selector; if (e.target.tagName === 'svg') { happy_input = e.target.parentNode; } else if (e.target.tagName === 'rect') { @@ -157,9 +157,15 @@ Happy = (function() { input.checked = true; happy_input.classList.add('active'); } - event = new Event('change', { - 'bubbles': true - }); + ie = window.navigator.userAgent.indexOf("MSIE "); + if (ie) { + event = document.createEvent('Event'); + event.initEvent('change', true, true); + } else { + event = new Event('change', { + 'bubbles': true + }); + } return input.dispatchEvent(event); } }; diff --git a/gulpfile.js b/gulpfile.js index de872d1..3e530de 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,8 +21,8 @@ var PATHS = { styles : 'src/sass/happy.scss', styles_all : 'src/sass/**/*.scss', scripts : 'src/coffee/**/*.coffee', - styles_compiled : 'dist/css', - scripts_compiled : 'dist/js' + styles_compiled : 'dist', + scripts_compiled : 'dist' }; diff --git a/src/coffee/happy.coffee b/src/coffee/happy.coffee index 284f343..ed33c80 100644 --- a/src/coffee/happy.coffee +++ b/src/coffee/happy.coffee @@ -145,8 +145,15 @@ class Happy input.checked = true happy_input.classList.add('active') - event = new Event('change', {'bubbles': true}) - input.dispatchEvent(event) + ie = window.navigator.userAgent.indexOf("MSIE ") + + if ie + event = document.createEvent('Event') + event.initEvent('change', true, true); + else + event = new Event('change', {'bubbles': true}) + + input.dispatchEvent(event); checkCheckboxStateOnChange: (e) => if e.target.classList.contains('happy')