0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

Replace feature test w/ UA sniff for buggy splitText. *sigh*

The feature test is sometimes passing in IE9, but then the buggy behaviour
still appears later. FFS IE.
This commit is contained in:
Neil Jenkins 2014-12-26 14:25:29 +07:00
parent 805f3cffff
commit 4a264a52c7
4 changed files with 14 additions and 20 deletions

View file

@ -35,13 +35,6 @@ var ctrlKey = isMac ? 'meta-' : 'ctrl-';
var useTextFixer = isIElt11 || isPresto;
var cantFocusEmptyTextNodes = isIElt11 || isWebKit;
var losesSelectionOnBlur = isIElt11;
var hasBuggySplit = function ( doc ) {
var div = doc.createElement( 'DIV' ),
text = doc.createTextNode( '12' );
div.appendChild( text );
text.splitText( 2 );
return div.childNodes.length !== 2;
};
// Use [^ \t\r\n] instead of \S so that nbsp does not count as white-space
var notWS = /[^ \t\r\n]/;
@ -1136,13 +1129,17 @@ function Squire ( doc ) {
// Opera does not fire keydown repeatedly.
this.addEventListener( isPresto ? 'keypress' : 'keydown', this._onKey );
// Fix IE8/9's buggy implementation of Text#splitText.
// Fix IE<10's buggy implementation of Text#splitText.
// If the split is at the end of the node, it doesn't insert the newly split
// node into the document, and sets its value to undefined rather than ''.
// And even if the split is not at the end, the original node is removed
// from the document and replaced by another, rather than just having its
// data shortened.
if ( hasBuggySplit( doc ) ) {
// We used to feature test for this, but then found the feature test would
// sometimes pass, but later on the buggy behaviour would still appear.
// I think IE10 does not have the same bug, but it doesn't hurt to replace
// its native fn too and then we don't need yet another UA category.
if ( isIElt11 ) {
win.Text.prototype.splitText = function ( offset ) {
var afterSplit = this.ownerDocument.createTextNode(
this.data.slice( offset ) ),

File diff suppressed because one or more lines are too long

View file

@ -30,13 +30,6 @@ var ctrlKey = isMac ? 'meta-' : 'ctrl-';
var useTextFixer = isIElt11 || isPresto;
var cantFocusEmptyTextNodes = isIElt11 || isWebKit;
var losesSelectionOnBlur = isIElt11;
var hasBuggySplit = function ( doc ) {
var div = doc.createElement( 'DIV' ),
text = doc.createTextNode( '12' );
div.appendChild( text );
text.splitText( 2 );
return div.childNodes.length !== 2;
};
// Use [^ \t\r\n] instead of \S so that nbsp does not count as white-space
var notWS = /[^ \t\r\n]/;

View file

@ -50,13 +50,17 @@ function Squire ( doc ) {
// Opera does not fire keydown repeatedly.
this.addEventListener( isPresto ? 'keypress' : 'keydown', this._onKey );
// Fix IE8/9's buggy implementation of Text#splitText.
// Fix IE<10's buggy implementation of Text#splitText.
// If the split is at the end of the node, it doesn't insert the newly split
// node into the document, and sets its value to undefined rather than ''.
// And even if the split is not at the end, the original node is removed
// from the document and replaced by another, rather than just having its
// data shortened.
if ( hasBuggySplit( doc ) ) {
// We used to feature test for this, but then found the feature test would
// sometimes pass, but later on the buggy behaviour would still appear.
// I think IE10 does not have the same bug, but it doesn't hurt to replace
// its native fn too and then we don't need yet another UA category.
if ( isIElt11 ) {
win.Text.prototype.splitText = function ( offset ) {
var afterSplit = this.ownerDocument.createTextNode(
this.data.slice( offset ) ),