mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Tidy code.
This commit is contained in:
parent
6e1b864663
commit
aaaae70504
3 changed files with 34 additions and 24 deletions
|
@ -38,6 +38,7 @@ var isIElt11 = /Trident\/[456]\./.test( ua );
|
||||||
var isPresto = !!win.opera;
|
var isPresto = !!win.opera;
|
||||||
var isEdge = /Edge\//.test( ua );
|
var isEdge = /Edge\//.test( ua );
|
||||||
var isWebKit = !isEdge && /WebKit\//.test( ua );
|
var isWebKit = !isEdge && /WebKit\//.test( ua );
|
||||||
|
var isIE = /Trident\/[4567]\./.test( ua );
|
||||||
|
|
||||||
var ctrlKey = isMac ? 'meta-' : 'ctrl-';
|
var ctrlKey = isMac ? 'meta-' : 'ctrl-';
|
||||||
|
|
||||||
|
@ -2482,6 +2483,7 @@ proto.setConfig = function ( config ) {
|
||||||
li: null,
|
li: null,
|
||||||
a: null
|
a: null
|
||||||
},
|
},
|
||||||
|
leafNodeNames: leafNodeNames,
|
||||||
undo: {
|
undo: {
|
||||||
documentSizeThreshold: -1, // -1 means no threshold
|
documentSizeThreshold: -1, // -1 means no threshold
|
||||||
undoLimit: -1 // -1 means no limit
|
undoLimit: -1 // -1 means no limit
|
||||||
|
@ -2856,18 +2858,18 @@ proto.getPath = function () {
|
||||||
|
|
||||||
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=15256
|
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=15256
|
||||||
|
|
||||||
// Walk down the tree starting at the root and remove any ZWS. If the node only contained
|
// Walk down the tree starting at the root and remove any ZWS. If the node only
|
||||||
// ZWS space then remove it too.
|
// contained ZWS space then remove it too. We may want to keep one ZWS node at
|
||||||
//
|
// the bottom of the tree so the block can be selected. Define that node as the
|
||||||
// We may want to keep one ZWS node at the bottom of the tree so the block can be selected. Define that
|
// keepNode.
|
||||||
// node as the keepNode.
|
|
||||||
var removeZWS = function ( root, keepNode ) {
|
var removeZWS = function ( root, keepNode ) {
|
||||||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||||
return true;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
parent, node, index;
|
parent, node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 && node.parentNode !== keepNode ) {
|
while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
|
||||||
|
( !keepNode || node.parentNode !== keepNode ) ) {
|
||||||
if ( node.length === 1 ) {
|
if ( node.length === 1 ) {
|
||||||
do {
|
do {
|
||||||
parent = node.parentNode;
|
parent = node.parentNode;
|
||||||
|
@ -2934,11 +2936,21 @@ proto._updatePathOnEvent = function () {
|
||||||
|
|
||||||
proto.focus = function () {
|
proto.focus = function () {
|
||||||
this._root.focus();
|
this._root.focus();
|
||||||
|
|
||||||
|
if ( isIE ) {
|
||||||
|
this.fireEvent( 'focus' );
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.blur = function () {
|
proto.blur = function () {
|
||||||
this._root.blur();
|
this._root.blur();
|
||||||
|
|
||||||
|
if ( isIE ) {
|
||||||
|
this.fireEvent( 'blur' );
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3265,7 +3277,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
// it round the range and focus it.
|
// it round the range and focus it.
|
||||||
var root = this._root;
|
var root = this._root;
|
||||||
var el, walker, startContainer, endContainer, startOffset, endOffset,
|
var el, walker, startContainer, endContainer, startOffset, endOffset,
|
||||||
node, needsFormat;
|
node, needsFormat, block;
|
||||||
|
|
||||||
if ( range.collapsed ) {
|
if ( range.collapsed ) {
|
||||||
el = fixCursor( this.createElement( tag, attributes ), root );
|
el = fixCursor( this.createElement( tag, attributes ), root );
|
||||||
|
@ -3275,11 +3287,10 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
|
|
||||||
// Clean up any previous formats that may have been set on this block
|
// Clean up any previous formats that may have been set on this block
|
||||||
// that are unused.
|
// that are unused.
|
||||||
var block = el;
|
block = el;
|
||||||
while ( isInline( block ) ) {
|
while ( isInline( block ) ) {
|
||||||
block = block.parentNode;
|
block = block.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeZWS( block, el );
|
removeZWS( block, el );
|
||||||
}
|
}
|
||||||
// Otherwise we find all the textnodes in the range (splitting
|
// Otherwise we find all the textnodes in the range (splitting
|
||||||
|
@ -3295,8 +3306,8 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
// to apply when the user types something in the block, which is
|
// to apply when the user types something in the block, which is
|
||||||
// presumably what was intended.
|
// presumably what was intended.
|
||||||
//
|
//
|
||||||
// IMG tags are included because we may want to create a link around them,
|
// IMG tags are included because we may want to create a link around
|
||||||
// and adding other styles is harmless.
|
// them, and adding other styles is harmless.
|
||||||
walker = new TreeWalker(
|
walker = new TreeWalker(
|
||||||
range.commonAncestorContainer,
|
range.commonAncestorContainer,
|
||||||
SHOW_TEXT|SHOW_ELEMENT,
|
SHOW_TEXT|SHOW_ELEMENT,
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -547,18 +547,18 @@ proto.getPath = function () {
|
||||||
|
|
||||||
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=15256
|
// WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=15256
|
||||||
|
|
||||||
// Walk down the tree starting at the root and remove any ZWS. If the node only contained
|
// Walk down the tree starting at the root and remove any ZWS. If the node only
|
||||||
// ZWS space then remove it too.
|
// contained ZWS space then remove it too. We may want to keep one ZWS node at
|
||||||
//
|
// the bottom of the tree so the block can be selected. Define that node as the
|
||||||
// We may want to keep one ZWS node at the bottom of the tree so the block can be selected. Define that
|
// keepNode.
|
||||||
// node as the keepNode.
|
|
||||||
var removeZWS = function ( root, keepNode ) {
|
var removeZWS = function ( root, keepNode ) {
|
||||||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||||
return true;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
parent, node, index;
|
parent, node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 && node.parentNode !== keepNode ) {
|
while ( ( index = node.data.indexOf( ZWS ) ) > -1 &&
|
||||||
|
( !keepNode || node.parentNode !== keepNode ) ) {
|
||||||
if ( node.length === 1 ) {
|
if ( node.length === 1 ) {
|
||||||
do {
|
do {
|
||||||
parent = node.parentNode;
|
parent = node.parentNode;
|
||||||
|
@ -966,7 +966,7 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
// it round the range and focus it.
|
// it round the range and focus it.
|
||||||
var root = this._root;
|
var root = this._root;
|
||||||
var el, walker, startContainer, endContainer, startOffset, endOffset,
|
var el, walker, startContainer, endContainer, startOffset, endOffset,
|
||||||
node, needsFormat;
|
node, needsFormat, block;
|
||||||
|
|
||||||
if ( range.collapsed ) {
|
if ( range.collapsed ) {
|
||||||
el = fixCursor( this.createElement( tag, attributes ), root );
|
el = fixCursor( this.createElement( tag, attributes ), root );
|
||||||
|
@ -976,11 +976,10 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
|
|
||||||
// Clean up any previous formats that may have been set on this block
|
// Clean up any previous formats that may have been set on this block
|
||||||
// that are unused.
|
// that are unused.
|
||||||
var block = el;
|
block = el;
|
||||||
while ( isInline( block ) ) {
|
while ( isInline( block ) ) {
|
||||||
block = block.parentNode;
|
block = block.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeZWS( block, el );
|
removeZWS( block, el );
|
||||||
}
|
}
|
||||||
// Otherwise we find all the textnodes in the range (splitting
|
// Otherwise we find all the textnodes in the range (splitting
|
||||||
|
@ -996,8 +995,8 @@ proto._addFormat = function ( tag, attributes, range ) {
|
||||||
// to apply when the user types something in the block, which is
|
// to apply when the user types something in the block, which is
|
||||||
// presumably what was intended.
|
// presumably what was intended.
|
||||||
//
|
//
|
||||||
// IMG tags are included because we may want to create a link around them,
|
// IMG tags are included because we may want to create a link around
|
||||||
// and adding other styles is harmless.
|
// them, and adding other styles is harmless.
|
||||||
walker = new TreeWalker(
|
walker = new TreeWalker(
|
||||||
range.commonAncestorContainer,
|
range.commonAncestorContainer,
|
||||||
SHOW_TEXT|SHOW_ELEMENT,
|
SHOW_TEXT|SHOW_ELEMENT,
|
||||||
|
|
Loading…
Reference in a new issue