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

Tidy code.

This commit is contained in:
Neil Jenkins 2016-08-05 20:47:02 +10:00
parent 6e1b864663
commit aaaae70504
3 changed files with 34 additions and 24 deletions

View file

@ -38,6 +38,7 @@ var isIElt11 = /Trident\/[456]\./.test( ua );
var isPresto = !!win.opera;
var isEdge = /Edge\//.test( ua );
var isWebKit = !isEdge && /WebKit\//.test( ua );
var isIE = /Trident\/[4567]\./.test( ua );
var ctrlKey = isMac ? 'meta-' : 'ctrl-';
@ -2482,6 +2483,7 @@ proto.setConfig = function ( config ) {
li: null,
a: null
},
leafNodeNames: leafNodeNames,
undo: {
documentSizeThreshold: -1, // -1 means no threshold
undoLimit: -1 // -1 means no limit
@ -2856,18 +2858,18 @@ proto.getPath = function () {
// 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
// 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 keepNode.
// Walk down the tree starting at the root and remove any ZWS. If the node only
// 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
// keepNode.
var removeZWS = function ( root, keepNode ) {
var walker = new TreeWalker( root, SHOW_TEXT, function () {
return true;
}, false ),
parent, node, index;
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 ) {
do {
parent = node.parentNode;
@ -2934,11 +2936,21 @@ proto._updatePathOnEvent = function () {
proto.focus = function () {
this._root.focus();
if ( isIE ) {
this.fireEvent( 'focus' );
}
return this;
};
proto.blur = function () {
this._root.blur();
if ( isIE ) {
this.fireEvent( 'blur' );
}
return this;
};
@ -3265,7 +3277,7 @@ proto._addFormat = function ( tag, attributes, range ) {
// it round the range and focus it.
var root = this._root;
var el, walker, startContainer, endContainer, startOffset, endOffset,
node, needsFormat;
node, needsFormat, block;
if ( range.collapsed ) {
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
// that are unused.
var block = el;
block = el;
while ( isInline( block ) ) {
block = block.parentNode;
}
removeZWS( block, el );
}
// 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
// presumably what was intended.
//
// IMG tags are included because we may want to create a link around them,
// and adding other styles is harmless.
// IMG tags are included because we may want to create a link around
// them, and adding other styles is harmless.
walker = new TreeWalker(
range.commonAncestorContainer,
SHOW_TEXT|SHOW_ELEMENT,

File diff suppressed because one or more lines are too long

View file

@ -547,18 +547,18 @@ proto.getPath = function () {
// 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
// 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 keepNode.
// Walk down the tree starting at the root and remove any ZWS. If the node only
// 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
// keepNode.
var removeZWS = function ( root, keepNode ) {
var walker = new TreeWalker( root, SHOW_TEXT, function () {
return true;
}, false ),
parent, node, index;
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 ) {
do {
parent = node.parentNode;
@ -966,7 +966,7 @@ proto._addFormat = function ( tag, attributes, range ) {
// it round the range and focus it.
var root = this._root;
var el, walker, startContainer, endContainer, startOffset, endOffset,
node, needsFormat;
node, needsFormat, block;
if ( range.collapsed ) {
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
// that are unused.
var block = el;
block = el;
while ( isInline( block ) ) {
block = block.parentNode;
}
removeZWS( block, el );
}
// 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
// presumably what was intended.
//
// IMG tags are included because we may want to create a link around them,
// and adding other styles is harmless.
// IMG tags are included because we may want to create a link around
// them, and adding other styles is harmless.
walker = new TreeWalker(
range.commonAncestorContainer,
SHOW_TEXT|SHOW_ELEMENT,