Created
August 24, 2019 19:30
-
-
Save tomtheisen/a77a3257bc3b87f78f1d000e278ca258 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare var $: any; | |
function select2EventDispatch(el: HTMLElement, events: string[]) { | |
let dispatching = false; | |
$.fn.select2 && $.fn.select2.amd.require( | |
["select2/utils"], function (Utils: any) { | |
const instance = Utils.GetData(el, "select2"); | |
instance && events.forEach(ev => { | |
instance.on(ev, () => { | |
if (dispatching) return; else dispatching = true; | |
try { el.dispatchEvent(new Event(ev)); } | |
finally { dispatching = false; } | |
}); | |
}); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment