-
Notifications
You must be signed in to change notification settings - Fork 35
Remove IE-Version-Switches #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
5d915f9
7f56282
636cbdb
900166d
aa4b5ef
c7de704
91e4ff6
b73c4eb
f229599
7b56798
b90dd4e
d787e3b
bd1af6b
a74a03e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||
| import { ieVersion, safeSetTimeout, options, arrayForEach, domData, registerEventHandler } from '@tko/utils' | ||||||||||||||||||||||||||||||||||||||
| import { safeSetTimeout, options, arrayForEach, domData, registerEventHandler } from '@tko/utils' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import { unwrap } from '@tko/observable' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import { BindingHandler } from '@tko/bind' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| let operaVersion, safariVersion, firefoxVersion | ||||||||||||||||||||||||||||||||||||||
| let operaVersion, safariVersion, firefoxVersion, ieVersion | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * TextInput binding handler for modern browsers (legacy below). | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -100,95 +100,11 @@ class TextInput extends BindingHandler { | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Legacy Input Classes, below | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| class TextInputIE extends TextInput { | ||||||||||||||||||||||||||||||||||||||
| activeElement: any | ||||||||||||||||||||||||||||||||||||||
| constructor(...args: [any]) { | ||||||||||||||||||||||||||||||||||||||
| super(...args) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| let version: number | ||||||||||||||||||||||||||||||||||||||
| if (ieVersion instanceof Array) { | ||||||||||||||||||||||||||||||||||||||
| version = parseInt(ieVersion[1], 10) | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| version = ieVersion ?? 0 | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (version < 11) { | ||||||||||||||||||||||||||||||||||||||
| // Internet Explorer <= 8 doesn't support the 'input' event, but does include 'propertychange' that fires whenever | ||||||||||||||||||||||||||||||||||||||
| // any property of an element changes. Unlike 'input', it also fires if a property is changed from JavaScript code, | ||||||||||||||||||||||||||||||||||||||
| // but that's an acceptable compromise for this binding. IE 9 and 10 support 'input', but since they don't always | ||||||||||||||||||||||||||||||||||||||
| // fire it when using autocomplete, we'll use 'propertychange' for them also. | ||||||||||||||||||||||||||||||||||||||
| this.addEventListener('propertychange', event => event.propertyName === 'value' && this.updateModel(event)) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (version >= 8 && version < 10) { | ||||||||||||||||||||||||||||||||||||||
| //this.watchForSelectionChangeEvent() //FIXME: Cannot work without element => EXCEPTION | ||||||||||||||||||||||||||||||||||||||
| this.addEventListener('dragend', 'deferUpdateModel') | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| override eventsIndicatingSyncValueChange() { | ||||||||||||||||||||||||||||||||||||||
| //keypress: All versions (including 11) of Internet Explorer have a bug that they don't generate an input or propertychange event when ESC is pressed | ||||||||||||||||||||||||||||||||||||||
| return [...super.eventsIndicatingSyncValueChange(), 'keypress'] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // IE 8 and 9 have bugs that prevent the normal events from firing when the value changes. | ||||||||||||||||||||||||||||||||||||||
| // But it does fire the 'selectionchange' event on many of those, presumably because the | ||||||||||||||||||||||||||||||||||||||
| // cursor is moving and that counts as the selection changing. The 'selectionchange' event is | ||||||||||||||||||||||||||||||||||||||
| // fired at the document level only and doesn't directly indicate which element changed. We | ||||||||||||||||||||||||||||||||||||||
| // set up just one event handler for the document and use 'activeElement' to determine which | ||||||||||||||||||||||||||||||||||||||
| // element was changed. | ||||||||||||||||||||||||||||||||||||||
| selectionChangeHandler(event) { | ||||||||||||||||||||||||||||||||||||||
| const target = this.activeElement | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const handler = target && domData.get(target, 'selectionChangeHandlerName') | ||||||||||||||||||||||||||||||||||||||
| if (handler) { | ||||||||||||||||||||||||||||||||||||||
| handler(event) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // All variables are not found! | ||||||||||||||||||||||||||||||||||||||
| watchForSelectionChangeEvent(element?) { | ||||||||||||||||||||||||||||||||||||||
| if (!element) throw new Error('Broken IE-Support: 8 to 9') | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const ownerDoc = element.ownerDocument | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (!domData.get(ownerDoc, 'selectionChangeRegisteredName')) { | ||||||||||||||||||||||||||||||||||||||
| domData.set(ownerDoc, 'selectionChangeRegisteredName', true) | ||||||||||||||||||||||||||||||||||||||
| registerEventHandler(ownerDoc, 'selectionchange', this.selectionChangeHandler.bind(ownerDoc)) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| //domData.set(ownerDoc, 'selectionChangeRegisteredName', handler) //FIXME: handler not defined | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // IE 8 and 9 have bugs that prevent the normal events from firing when the value changes. | ||||||||||||||||||||||||||||||||||||||
| // But it does fire the 'selectionchange' event on many of those, presumably because the | ||||||||||||||||||||||||||||||||||||||
| // cursor is moving and that counts as the selection changing. The 'selectionchange' event is | ||||||||||||||||||||||||||||||||||||||
| // fired at the document level only and doesn't directly indicate which element changed. We | ||||||||||||||||||||||||||||||||||||||
| // set up just one event handler for the document and use 'activeElement' to determine which | ||||||||||||||||||||||||||||||||||||||
| // element was changed. | ||||||||||||||||||||||||||||||||||||||
| class TextInputIE9 extends TextInputIE { | ||||||||||||||||||||||||||||||||||||||
| override updateModel(...args: [any]) { | ||||||||||||||||||||||||||||||||||||||
| // IE9 will mess up the DOM if you handle events synchronously which results in DOM changes (such as other bindings); | ||||||||||||||||||||||||||||||||||||||
| // so we'll make sure all updates are asynchronous | ||||||||||||||||||||||||||||||||||||||
| this.deferUpdateModel(...args) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| class TextInputIE8 extends TextInputIE { | ||||||||||||||||||||||||||||||||||||||
| eventsIndicatingValueChange() { | ||||||||||||||||||||||||||||||||||||||
| // IE 8 has a bug where it fails to fire 'propertychange' on the first update following a value change from | ||||||||||||||||||||||||||||||||||||||
| // JavaScript code. It also doesn't fire if you clear the entire value. To fix this, we bind to the following | ||||||||||||||||||||||||||||||||||||||
| // events too. | ||||||||||||||||||||||||||||||||||||||
| // keypress: All versions (including 11) of Internet Explorer have a bug that they don't generate an input or propertychange event when ESC is pressed | ||||||||||||||||||||||||||||||||||||||
| // keyup: A single keystoke | ||||||||||||||||||||||||||||||||||||||
| // keydown: First character when a key is held down | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return [...super.eventsIndicatingSyncValueChange(), 'keyup', 'keydown'] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Safari <5 doesn't fire the 'input' event for <textarea> elements (it does fire 'textInput' | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -225,23 +141,23 @@ if (w.navigator) { | |||||||||||||||||||||||||||||||||||||
| const parseVersion = matches => matches && parseFloat(matches[1]) | ||||||||||||||||||||||||||||||||||||||
| const userAgent = w.navigator.userAgent | ||||||||||||||||||||||||||||||||||||||
| const isChrome = userAgent.match(/Chrome\/([^ ]+)/) | ||||||||||||||||||||||||||||||||||||||
| // Detect various browser versions because some old versions don't fully support the 'input' event | ||||||||||||||||||||||||||||||||||||||
| operaVersion = w.opera && w.opera.version && parseInt(w.opera.version()) | ||||||||||||||||||||||||||||||||||||||
| safariVersion = parseVersion(userAgent.match(/Version\/([^ ]+) Safari/)) | ||||||||||||||||||||||||||||||||||||||
| firefoxVersion = parseVersion(userAgent.match(/Firefox\/([^ ]*)/)) | ||||||||||||||||||||||||||||||||||||||
| if (!isChrome) { | ||||||||||||||||||||||||||||||||||||||
| // Detect various browser versions because some old versions don't fully support the 'input' event | ||||||||||||||||||||||||||||||||||||||
| operaVersion = w.opera && w.opera.version && parseInt(w.opera.version()) | ||||||||||||||||||||||||||||||||||||||
| safariVersion = parseVersion(userAgent.match(/Version\/([^ ]+) Safari/)) | ||||||||||||||||||||||||||||||||||||||
| firefoxVersion = parseVersion(userAgent.match(/Firefox\/([^ ]*)/)) | ||||||||||||||||||||||||||||||||||||||
| const ieMatch = userAgent.match(/MSIE ([^ ;]+)|rv:([^ )]+)/) | ||||||||||||||||||||||||||||||||||||||
| ieVersion = ieMatch && (parseFloat(ieMatch[1]) || parseFloat(ieMatch[2])) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export const textInput = | ||||||||||||||||||||||||||||||||||||||
| ieVersion === 8 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputIE8 | ||||||||||||||||||||||||||||||||||||||
| : ieVersion === 9 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputIE9 | ||||||||||||||||||||||||||||||||||||||
| : ieVersion | ||||||||||||||||||||||||||||||||||||||
| ? TextInputIE | ||||||||||||||||||||||||||||||||||||||
| : safariVersion && safariVersion < 5 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputLegacySafari | ||||||||||||||||||||||||||||||||||||||
| : operaVersion < 11 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputLegacyOpera | ||||||||||||||||||||||||||||||||||||||
| : firefoxVersion && firefoxVersion < 4 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputLegacyFirefox | ||||||||||||||||||||||||||||||||||||||
| : TextInput | ||||||||||||||||||||||||||||||||||||||
| ieVersion && ieVersion <= 11 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputIE | ||||||||||||||||||||||||||||||||||||||
| : safariVersion && safariVersion < 5 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputLegacySafari | ||||||||||||||||||||||||||||||||||||||
| : operaVersion && operaVersion < 11 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputLegacyOpera | ||||||||||||||||||||||||||||||||||||||
| : firefoxVersion && firefoxVersion < 4 | ||||||||||||||||||||||||||||||||||||||
| ? TextInputLegacyFirefox | ||||||||||||||||||||||||||||||||||||||
| : TextInput | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+157
to
+165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: IE9 inadvertently included in version check. The condition 🐛 Proposed fix to exclude IE9 export const textInput =
- ieVersion && ieVersion <= 11
+ ieVersion && ieVersion >= 10 && ieVersion <= 11
? TextInputIE
: safariVersion && safariVersion < 5
? TextInputLegacySafariBased on learnings, IE9 support was intentionally removed while IE10/11 support is retained. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, it is correct that this condition also applied to smaller versions of IE. The official support for IE9 and explicit IE9 switches are removed with this pr. Such partial support may remain.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @phillipc, thank you for the clarification! I understand now — you've removed the explicit IE9-specific handlers and switches (like I appreciate you explaining the distinction between removing official support versus allowing partial compatibility. This makes sense for a gradual deprecation strategy. ✏️ Learnings added
🧠 Learnings used |
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.