CreativeIT / getmdl-select

Select for material-design-lite
http://creativeit.github.io/getmdl-select/
MIT License
301 stars 87 forks source link

IE 11 Compatibility #74

Open jtitley opened 6 years ago

jtitley commented 6 years ago

May I suggest some changes to support IE 11? I was finally able to achieve it and have all functionality working with the following changes. Since you know the code I think you can avoid this complex fix by avoiding some incompatible functions like ForEach and new Event.

In getmdl-select.js add the following function to replace new Event() // For IE Compatibility // source: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent function CustomEvent(event, params) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createEvent('CustomEvent'); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); return evt; }

Where you use new Event, do the following:

var event; try { event = new Event('closeSelect');} catch(err) {} if (event == undefined) { event = window.CustomEvent('closeSelect'); }

To support NodeList ForEach I added this in whenLoaded() // source: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = function (callback, thisArg) { thisArg = thisArg || window; for (var i = 0; i < this.length; i++) { callback.call(thisArg, this[i], i, this); } }; }

munavvard2 commented 6 years ago

@jtitley , can you instruct me where the code to put? or can you give me changed file so that i can use into my project, btw thanks for your work.

jtitley commented 6 years ago

I've forked a copy here: Just copy getdtl-select.js

I'll leave it up to the owner to determine if this gets folded into this version.

I don't quite understand how the author generated the .min versions so I've left them alone.

munavvard2 commented 6 years ago

@jtitley Thanks , i used that working fine.

alexbananabob commented 6 years ago

@jtitley, great work! Many thanks We will try to include you code in the next release

jagadeeshagm commented 5 years ago

I've forked a copy here: Just copy getdtl-select.js

I'll leave it up to the owner to determine if this gets folded into this version.

I don't quite understand how the author generated the .min versions so I've left them alone.

@jtitley - I am facing the foreach issue when i used the getdtl-select.js in IE11(EDGE). What is the alternate solutions