mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Whitespace cleanup.
This commit is contained in:
parent
78e8955be1
commit
e3ee4dad12
8 changed files with 251 additions and 251 deletions
|
@ -58,8 +58,8 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span id="setTextColour" class="prompt">Text colour</span>
|
<span id="setTextColour" class="prompt">Text colour</span>
|
||||||
<span id="setTextHighlight" class="prompt">Text highlight</span>
|
<span id="setHighlightColour" class="prompt">Text highlight</span>
|
||||||
<span id="link" class="prompt">Link</span>
|
<span id="makeLink" class="prompt">Link</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span id="incQuoteLevel">Quote</span>
|
<span id="incQuoteLevel">Quote</span>
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
}
|
}
|
||||||
h4,h5,h6 {
|
h4,h5,h6 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
ul, ol {
|
ul, ol {
|
||||||
margin: 0 1em;
|
margin: 0 1em;
|
||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockquote {
|
blockquote {
|
||||||
border-left: 2px solid blue;
|
border-left: 2px solid blue;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
File diff suppressed because one or more lines are too long
380
source/Editor.js
380
source/Editor.js
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
||||||
/* Copyright © 2011 by Neil Jenkins. Licensed under the MIT license. */
|
/* Copyright © 2011 by Neil Jenkins. Licensed under the MIT license. */
|
||||||
|
|
||||||
( function () {
|
( function () {
|
||||||
|
|
||||||
/*global Node, Text, Element, window, document */
|
/*global Node, Text, Element, window, document */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -145,7 +145,7 @@ implement( Element, {
|
||||||
var path = this.parentNode.getPath(),
|
var path = this.parentNode.getPath(),
|
||||||
id = this.id,
|
id = this.id,
|
||||||
className = this.className.trim();
|
className = this.className.trim();
|
||||||
|
|
||||||
path += '>' + tag;
|
path += '>' + tag;
|
||||||
if ( id ) {
|
if ( id ) {
|
||||||
path += '#' + id;
|
path += '#' + id;
|
||||||
|
@ -259,30 +259,30 @@ implement( Element, {
|
||||||
container = container.parentNode;
|
container = container.parentNode;
|
||||||
}
|
}
|
||||||
container.detach();
|
container.detach();
|
||||||
|
|
||||||
offset = block.childNodes.length;
|
offset = block.childNodes.length;
|
||||||
|
|
||||||
// Remove extra <BR> fixer if present.
|
// Remove extra <BR> fixer if present.
|
||||||
last = block.lastChild;
|
last = block.lastChild;
|
||||||
if ( last && last.nodeName === 'BR' ) {
|
if ( last && last.nodeName === 'BR' ) {
|
||||||
block.removeChild( last );
|
block.removeChild( last );
|
||||||
offset -= 1;
|
offset -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_range = {
|
_range = {
|
||||||
startContainer: block,
|
startContainer: block,
|
||||||
startOffset: offset,
|
startOffset: offset,
|
||||||
endContainer: block,
|
endContainer: block,
|
||||||
endOffset: offset
|
endOffset: offset
|
||||||
};
|
};
|
||||||
|
|
||||||
block.appendChild( next.empty() );
|
block.appendChild( next.empty() );
|
||||||
block.mergeInlines( _range );
|
block.mergeInlines( _range );
|
||||||
|
|
||||||
range.setStart(
|
range.setStart(
|
||||||
_range.startContainer, _range.startOffset );
|
_range.startContainer, _range.startOffset );
|
||||||
range.collapse( true );
|
range.collapse( true );
|
||||||
|
|
||||||
// Opera inserts a BR if you delete the last piece of text
|
// Opera inserts a BR if you delete the last piece of text
|
||||||
// in a block-level element. Unfortunately, it then gets
|
// in a block-level element. Unfortunately, it then gets
|
||||||
// confused when setting the selection subsequently and
|
// confused when setting the selection subsequently and
|
||||||
|
@ -308,43 +308,43 @@ implement( Element, {
|
||||||
},
|
},
|
||||||
split: function ( childNodeToSplitBefore, stopNode ) {
|
split: function ( childNodeToSplitBefore, stopNode ) {
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
if ( typeof( childNodeToSplitBefore ) === 'number' ) {
|
if ( typeof( childNodeToSplitBefore ) === 'number' ) {
|
||||||
childNodeToSplitBefore =
|
childNodeToSplitBefore =
|
||||||
childNodeToSplitBefore < node.childNodes.length ?
|
childNodeToSplitBefore < node.childNodes.length ?
|
||||||
node.childNodes[ childNodeToSplitBefore ] : null;
|
node.childNodes[ childNodeToSplitBefore ] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node === stopNode ) {
|
if ( node === stopNode ) {
|
||||||
return childNodeToSplitBefore;
|
return childNodeToSplitBefore;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone node without children
|
// Clone node without children
|
||||||
var parent = node.parentNode,
|
var parent = node.parentNode,
|
||||||
clone = node.cloneNode( false ),
|
clone = node.cloneNode( false ),
|
||||||
next;
|
next;
|
||||||
|
|
||||||
// Add right-hand siblings to the clone
|
// Add right-hand siblings to the clone
|
||||||
while ( childNodeToSplitBefore ) {
|
while ( childNodeToSplitBefore ) {
|
||||||
next = childNodeToSplitBefore.nextSibling;
|
next = childNodeToSplitBefore.nextSibling;
|
||||||
clone.appendChild( childNodeToSplitBefore );
|
clone.appendChild( childNodeToSplitBefore );
|
||||||
childNodeToSplitBefore = next;
|
childNodeToSplitBefore = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DO NOT NORMALISE. This may undo the fixCursor() call
|
// DO NOT NORMALISE. This may undo the fixCursor() call
|
||||||
// of a node lower down the tree!
|
// of a node lower down the tree!
|
||||||
|
|
||||||
// We need something in the element in order for the cursor to appear.
|
// We need something in the element in order for the cursor to appear.
|
||||||
node.fixCursor();
|
node.fixCursor();
|
||||||
clone.fixCursor();
|
clone.fixCursor();
|
||||||
|
|
||||||
// Inject clone after original node
|
// Inject clone after original node
|
||||||
if ( next = node.nextSibling ) {
|
if ( next = node.nextSibling ) {
|
||||||
parent.insertBefore( clone, next );
|
parent.insertBefore( clone, next );
|
||||||
} else {
|
} else {
|
||||||
parent.appendChild( clone );
|
parent.appendChild( clone );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep on splitting up the tree
|
// Keep on splitting up the tree
|
||||||
return parent.split( clone, stopNode );
|
return parent.split( clone, stopNode );
|
||||||
},
|
},
|
||||||
|
@ -356,7 +356,7 @@ implement( Element, {
|
||||||
var el = this,
|
var el = this,
|
||||||
doc = el.ownerDocument,
|
doc = el.ownerDocument,
|
||||||
fixer, child;
|
fixer, child;
|
||||||
|
|
||||||
if ( el.nodeName === 'BODY' ) {
|
if ( el.nodeName === 'BODY' ) {
|
||||||
if ( !( child = el.firstChild ) || child.nodeName === 'BR' ) {
|
if ( !( child = el.firstChild ) || child.nodeName === 'BR' ) {
|
||||||
fixer = doc.createElement( 'DIV' );
|
fixer = doc.createElement( 'DIV' );
|
||||||
|
@ -370,7 +370,7 @@ implement( Element, {
|
||||||
fixer = null;
|
fixer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( el.isInline() ) {
|
if ( el.isInline() ) {
|
||||||
if ( !el.firstChild ) {
|
if ( !el.firstChild ) {
|
||||||
fixer = doc.createTextNode( /* isWebkit ? '\u200B' :*/ '' );
|
fixer = doc.createTextNode( /* isWebkit ? '\u200B' :*/ '' );
|
||||||
|
@ -407,7 +407,7 @@ implement( Element, {
|
||||||
if ( fixer ) {
|
if ( fixer ) {
|
||||||
el.appendChild( fixer );
|
el.appendChild( fixer );
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,11 +51,11 @@ var getNodeAfter = function ( node, offset ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
implement( Range, {
|
implement( Range, {
|
||||||
|
|
||||||
forEachTextNode: function ( fn ) {
|
forEachTextNode: function ( fn ) {
|
||||||
var range = this.cloneRange();
|
var range = this.cloneRange();
|
||||||
range.moveBoundariesDownTree();
|
range.moveBoundariesDownTree();
|
||||||
|
|
||||||
var startContainer = range.startContainer,
|
var startContainer = range.startContainer,
|
||||||
endContainer = range.endContainer,
|
endContainer = range.endContainer,
|
||||||
root = range.commonAncestorContainer,
|
root = range.commonAncestorContainer,
|
||||||
|
@ -64,12 +64,12 @@ implement( Range, {
|
||||||
return FILTER_ACCEPT;
|
return FILTER_ACCEPT;
|
||||||
}, false ),
|
}, false ),
|
||||||
textnode = walker.currentNode = startContainer;
|
textnode = walker.currentNode = startContainer;
|
||||||
|
|
||||||
while ( !fn( textnode, range ) &&
|
while ( !fn( textnode, range ) &&
|
||||||
textnode !== endContainer &&
|
textnode !== endContainer &&
|
||||||
( textnode = walker.nextNode() ) ) {}
|
( textnode = walker.nextNode() ) ) {}
|
||||||
},
|
},
|
||||||
|
|
||||||
getTextContent: function () {
|
getTextContent: function () {
|
||||||
var textContent = '';
|
var textContent = '';
|
||||||
this.forEachTextNode( function ( textnode, range ) {
|
this.forEachTextNode( function ( textnode, range ) {
|
||||||
|
@ -86,9 +86,9 @@ implement( Range, {
|
||||||
});
|
});
|
||||||
return textContent;
|
return textContent;
|
||||||
},
|
},
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
_insertNode: function ( node ) {
|
_insertNode: function ( node ) {
|
||||||
// Insert at start.
|
// Insert at start.
|
||||||
var startContainer = this.startContainer,
|
var startContainer = this.startContainer,
|
||||||
|
@ -169,26 +169,26 @@ implement( Range, {
|
||||||
|
|
||||||
return frag;
|
return frag;
|
||||||
},
|
},
|
||||||
|
|
||||||
_deleteContents: function () {
|
_deleteContents: function () {
|
||||||
// Move boundaries up as much as possible to reduce need to split.
|
// Move boundaries up as much as possible to reduce need to split.
|
||||||
this.moveBoundariesUpTree();
|
this.moveBoundariesUpTree();
|
||||||
|
|
||||||
// Remove selected range
|
// Remove selected range
|
||||||
this._extractContents();
|
this._extractContents();
|
||||||
|
|
||||||
// If we split into two different blocks, merge the blocks.
|
// If we split into two different blocks, merge the blocks.
|
||||||
var startBlock = this.getStartBlock(),
|
var startBlock = this.getStartBlock(),
|
||||||
endBlock = this.getEndBlock();
|
endBlock = this.getEndBlock();
|
||||||
if ( startBlock && endBlock && startBlock !== endBlock ) {
|
if ( startBlock && endBlock && startBlock !== endBlock ) {
|
||||||
startBlock.mergeWithBlock( endBlock, this );
|
startBlock.mergeWithBlock( endBlock, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure block has necessary children
|
// Ensure block has necessary children
|
||||||
if ( startBlock ) {
|
if ( startBlock ) {
|
||||||
startBlock.fixCursor();
|
startBlock.fixCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure body has a block-level element in it.
|
// Ensure body has a block-level element in it.
|
||||||
var body = this.endContainer.ownerDocument.body,
|
var body = this.endContainer.ownerDocument.body,
|
||||||
child = body.firstChild;
|
child = body.firstChild;
|
||||||
|
@ -196,7 +196,7 @@ implement( Range, {
|
||||||
body.fixCursor();
|
body.fixCursor();
|
||||||
this.selectNodeContents( body.firstChild );
|
this.selectNodeContents( body.firstChild );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure valid range (must have only block or inline containers)
|
// Ensure valid range (must have only block or inline containers)
|
||||||
var isCollapsed = this.collapsed;
|
var isCollapsed = this.collapsed;
|
||||||
this.moveBoundariesDownTree();
|
this.moveBoundariesDownTree();
|
||||||
|
@ -205,12 +205,12 @@ implement( Range, {
|
||||||
// Make that the focus point.
|
// Make that the focus point.
|
||||||
this.collapse( this.startContainer.nodeType === TEXT_NODE );
|
this.collapse( this.startContainer.nodeType === TEXT_NODE );
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
insertTreeFragment: function ( frag ) {
|
insertTreeFragment: function ( frag ) {
|
||||||
// Check if it's all inline content
|
// Check if it's all inline content
|
||||||
var isInline = true,
|
var isInline = true,
|
||||||
|
@ -222,7 +222,7 @@ implement( Range, {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete any selected content
|
// Delete any selected content
|
||||||
if ( !this.collapsed ) {
|
if ( !this.collapsed ) {
|
||||||
this._deleteContents();
|
this._deleteContents();
|
||||||
|
@ -230,7 +230,7 @@ implement( Range, {
|
||||||
|
|
||||||
// Move range down into text ndoes
|
// Move range down into text ndoes
|
||||||
this.moveBoundariesDownTree();
|
this.moveBoundariesDownTree();
|
||||||
|
|
||||||
// If inline, just insert at the current position.
|
// If inline, just insert at the current position.
|
||||||
if ( isInline ) {
|
if ( isInline ) {
|
||||||
this._insertNode( frag );
|
this._insertNode( frag );
|
||||||
|
@ -248,7 +248,7 @@ implement( Range, {
|
||||||
endOffset = 0,
|
endOffset = 0,
|
||||||
parent = nodeAfterSplit.parentNode,
|
parent = nodeAfterSplit.parentNode,
|
||||||
child, node;
|
child, node;
|
||||||
|
|
||||||
while ( ( child = startContainer.lastChild ) &&
|
while ( ( child = startContainer.lastChild ) &&
|
||||||
child.nodeType === ELEMENT_NODE &&
|
child.nodeType === ELEMENT_NODE &&
|
||||||
child.nodeName !== 'BR' ) {
|
child.nodeName !== 'BR' ) {
|
||||||
|
@ -267,19 +267,19 @@ implement( Range, {
|
||||||
endContainer.insertBefore( child, endContainer.firstChild );
|
endContainer.insertBefore( child, endContainer.firstChild );
|
||||||
endOffset += 1;
|
endOffset += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix cursor before inserting block:
|
// Fix cursor before inserting block:
|
||||||
node = frag;
|
node = frag;
|
||||||
while ( node = node.getNextBlock() ) {
|
while ( node = node.getNextBlock() ) {
|
||||||
node.fixCursor();
|
node.fixCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.insertBefore( frag, nodeAfterSplit );
|
parent.insertBefore( frag, nodeAfterSplit );
|
||||||
|
|
||||||
// Merge containers at edges
|
// Merge containers at edges
|
||||||
nodeAfterSplit.mergeContainers();
|
nodeAfterSplit.mergeContainers();
|
||||||
nodeBeforeSplit.nextSibling.mergeContainers();
|
nodeBeforeSplit.nextSibling.mergeContainers();
|
||||||
|
|
||||||
// Remove empty nodes created by split.
|
// Remove empty nodes created by split.
|
||||||
if ( nodeAfterSplit === endContainer &&
|
if ( nodeAfterSplit === endContainer &&
|
||||||
!endContainer.textContent ) {
|
!endContainer.textContent ) {
|
||||||
|
@ -293,7 +293,7 @@ implement( Range, {
|
||||||
startOffset = 0;
|
startOffset = 0;
|
||||||
parent.removeChild( nodeBeforeSplit );
|
parent.removeChild( nodeBeforeSplit );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setStart( startContainer, startOffset );
|
this.setStart( startContainer, startOffset );
|
||||||
this.setEnd( endContainer, endOffset );
|
this.setEnd( endContainer, endOffset );
|
||||||
this.moveBoundariesDownTree();
|
this.moveBoundariesDownTree();
|
||||||
|
@ -301,7 +301,7 @@ implement( Range, {
|
||||||
},
|
},
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
containsNode: function ( node, partial ) {
|
containsNode: function ( node, partial ) {
|
||||||
var range = this,
|
var range = this,
|
||||||
nodeRange = node.ownerDocument.createRange();
|
nodeRange = node.ownerDocument.createRange();
|
||||||
|
@ -327,7 +327,7 @@ implement( Range, {
|
||||||
return ( nodeStartAfterStart && nodeEndBeforeEnd );
|
return ( nodeStartAfterStart && nodeEndBeforeEnd );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
moveBoundariesDownTree: function () {
|
moveBoundariesDownTree: function () {
|
||||||
var startContainer = this.startContainer,
|
var startContainer = this.startContainer,
|
||||||
startOffset = this.startOffset,
|
startOffset = this.startOffset,
|
||||||
|
@ -361,7 +361,7 @@ implement( Range, {
|
||||||
endContainer = child;
|
endContainer = child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If collapsed, this algorithm finds the nearest text node positions
|
// If collapsed, this algorithm finds the nearest text node positions
|
||||||
// *outside* the range rather than inside, but also it flips which is
|
// *outside* the range rather than inside, but also it flips which is
|
||||||
// assigned to which.
|
// assigned to which.
|
||||||
|
@ -372,7 +372,7 @@ implement( Range, {
|
||||||
this.setStart( startContainer, startOffset );
|
this.setStart( startContainer, startOffset );
|
||||||
this.setEnd( endContainer, endOffset );
|
this.setEnd( endContainer, endOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ implement( Range, {
|
||||||
getStartBlock: function () {
|
getStartBlock: function () {
|
||||||
var container = this.startContainer,
|
var container = this.startContainer,
|
||||||
block;
|
block;
|
||||||
|
|
||||||
// If inline, get the containing block.
|
// If inline, get the containing block.
|
||||||
if ( container.isInline() ) {
|
if ( container.isInline() ) {
|
||||||
block = container.getPreviousBlock();
|
block = container.getPreviousBlock();
|
||||||
|
@ -424,13 +424,13 @@ implement( Range, {
|
||||||
// Check the block actually intersects the range
|
// Check the block actually intersects the range
|
||||||
return block && this.containsNode( block, true ) ? block : null;
|
return block && this.containsNode( block, true ) ? block : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns the last block at least partially contained by the range,
|
// Returns the last block at least partially contained by the range,
|
||||||
// or null if no block is contained by the range.
|
// or null if no block is contained by the range.
|
||||||
getEndBlock: function () {
|
getEndBlock: function () {
|
||||||
var container = this.endContainer,
|
var container = this.endContainer,
|
||||||
block, child;
|
block, child;
|
||||||
|
|
||||||
// If inline, get the containing block.
|
// If inline, get the containing block.
|
||||||
if ( container.isInline() ) {
|
if ( container.isInline() ) {
|
||||||
block = container.getPreviousBlock();
|
block = container.getPreviousBlock();
|
||||||
|
@ -445,7 +445,7 @@ implement( Range, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
block = block.getPreviousBlock();
|
block = block.getPreviousBlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
// Check the block actually intersects the range
|
// Check the block actually intersects the range
|
||||||
return block && this.containsNode( block, true ) ? block : null;
|
return block && this.containsNode( block, true ) ? block : null;
|
||||||
|
@ -501,14 +501,14 @@ implement( Range, {
|
||||||
var start = this.getStartBlock(),
|
var start = this.getStartBlock(),
|
||||||
end = this.getEndBlock(),
|
end = this.getEndBlock(),
|
||||||
parent;
|
parent;
|
||||||
|
|
||||||
if ( start && end ) {
|
if ( start && end ) {
|
||||||
parent = start.parentNode;
|
parent = start.parentNode;
|
||||||
this.setStart( parent, indexOf.call( parent.childNodes, start ) );
|
this.setStart( parent, indexOf.call( parent.childNodes, start ) );
|
||||||
parent = end.parentNode;
|
parent = end.parentNode;
|
||||||
this.setEnd( parent, indexOf.call( parent.childNodes, end ) + 1 );
|
this.setEnd( parent, indexOf.call( parent.childNodes, end ) + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,9 +21,9 @@ if ( !needsReplacement ) {
|
||||||
( function () {
|
( function () {
|
||||||
var div = doc.createElement( 'div' ),
|
var div = doc.createElement( 'div' ),
|
||||||
text = doc.createTextNode( '' );
|
text = doc.createTextNode( '' );
|
||||||
|
|
||||||
div.appendChild( text );
|
div.appendChild( text );
|
||||||
|
|
||||||
var div1 = div.cloneNode( true ),
|
var div1 = div.cloneNode( true ),
|
||||||
div2 = div.cloneNode( true ),
|
div2 = div.cloneNode( true ),
|
||||||
div3 = div.cloneNode( true ),
|
div3 = div.cloneNode( true ),
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
}
|
}
|
||||||
h4,h5,h6 {
|
h4,h5,h6 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
ul, ol {
|
ul, ol {
|
||||||
margin: 0 1em;
|
margin: 0 1em;
|
||||||
padding: 0 1em;
|
padding: 0 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockquote {
|
blockquote {
|
||||||
border-left: 2px solid blue;
|
border-left: 2px solid blue;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
Loading…
Reference in a new issue