From 3d36a69d16e18b6303f146accd64a0ab1fd27b92 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 26 May 2016 11:25:33 +1000 Subject: [PATCH] Update to latest --- build/squire-raw.js | 1023 ++++++++++++++++++++++++++----------------- build/squire.js | 4 +- 2 files changed, 618 insertions(+), 409 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 4b52f29..62dbbd8 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -7,6 +7,7 @@ var DOCUMENT_POSITION_PRECEDING = 2; // Node.DOCUMENT_POSITION_PRECEDING var ELEMENT_NODE = 1; // Node.ELEMENT_NODE; var TEXT_NODE = 3; // Node.TEXT_NODE; +var DOCUMENT_NODE = 9; // Node.DOCUMENT_NODE; var DOCUMENT_FRAGMENT_NODE = 11; // Node.DOCUMENT_FRAGMENT_NODE; var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT; var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT; @@ -28,7 +29,8 @@ var isMac = /Mac OS X/.test( ua ); var isGecko = /Gecko\//.test( ua ); var isIElt11 = /Trident\/[456]\./.test( ua ); var isPresto = !!win.opera; -var isWebKit = /WebKit\//.test( ua ); +var isEdge = /Edge\//.test( ua ); +var isWebKit = !isEdge && /WebKit\//.test( ua ); var ctrlKey = isMac ? 'meta-' : 'ctrl-'; @@ -169,10 +171,12 @@ TreeWalker.prototype.previousPONode = function () { } }; -var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/; +var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/; var leafNodeNames = { BR: 1, + HR: 1, + IFRAME: 1, IMG: 1, INPUT: 1 }; @@ -189,27 +193,6 @@ function every ( nodeList, fn ) { // --- -function hasTagAttributes ( node, tag, attributes ) { - if ( node.nodeName !== tag ) { - return false; - } - for ( var attr in attributes ) { - if ( node.getAttribute( attr ) !== attributes[ attr ] ) { - return false; - } - } - return true; -} -function areAlike ( node, node2 ) { - return !isLeaf( node ) && ( - node.nodeType === node2.nodeType && - node.nodeName === node2.nodeName && - node.className === node2.className && - ( ( !node.style && !node2.style ) || - node.style.cssText === node2.style.cssText ) - ); -} - function isLeaf ( node ) { return node.nodeType === ELEMENT_NODE && !!leafNodeNames[ node.nodeName ]; @@ -228,48 +211,79 @@ function isContainer ( node ) { !isInline( node ) && !isBlock( node ); } -function getBlockWalker ( node ) { - var doc = node.ownerDocument, - walker = new TreeWalker( - doc.body, SHOW_ELEMENT, isBlock, false ); +function getBlockWalker ( node, root ) { + var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock ); walker.currentNode = node; return walker; } +function getPreviousBlock ( node, root ) { + node = getBlockWalker( node, root ).previousNode(); + return node !== root ? node : null; +} +function getNextBlock ( node, root ) { + node = getBlockWalker( node, root ).nextNode(); + return node !== root ? node : null; +} -function getPreviousBlock ( node ) { - return getBlockWalker( node ).previousNode(); +function areAlike ( node, node2 ) { + return !isLeaf( node ) && ( + node.nodeType === node2.nodeType && + node.nodeName === node2.nodeName && + node.nodeName !== 'A' && + node.className === node2.className && + ( ( !node.style && !node2.style ) || + node.style.cssText === node2.style.cssText ) + ); } -function getNextBlock ( node ) { - return getBlockWalker( node ).nextNode(); +function hasTagAttributes ( node, tag, attributes ) { + if ( node.nodeName !== tag ) { + return false; + } + for ( var attr in attributes ) { + if ( node.getAttribute( attr ) !== attributes[ attr ] ) { + return false; + } + } + return true; } -function getNearest ( node, tag, attributes ) { - do { +function getNearest ( node, root, tag, attributes ) { + while ( node && node !== root ) { if ( hasTagAttributes( node, tag, attributes ) ) { return node; } - } while ( node = node.parentNode ); + node = node.parentNode; + } return null; } +function isOrContains ( parent, node ) { + while ( node ) { + if ( node === parent ) { + return true; + } + node = node.parentNode; + } + return false; +} -function getPath ( node ) { - var parent = node.parentNode, - path, id, className, classNames, dir; - if ( !parent || node.nodeType !== ELEMENT_NODE ) { - path = parent ? getPath( parent ) : ''; - } else { - path = getPath( parent ); - path += ( path ? '>' : '' ) + node.nodeName; - if ( id = node.id ) { - path += '#' + id; - } - if ( className = node.className.trim() ) { - classNames = className.split( /\s\s*/ ); - classNames.sort(); - path += '.'; - path += classNames.join( '.' ); - } - if ( dir = node.dir ) { - path += '[dir=' + dir + ']'; +function getPath ( node, root ) { + var path = ''; + var id, className, classNames, dir; + if ( node && node !== root ) { + path = getPath( node.parentNode, root ); + if ( node.nodeType === ELEMENT_NODE ) { + path += ( path ? '>' : '' ) + node.nodeName; + if ( id = node.id ) { + path += '#' + id; + } + if ( className = node.className.trim() ) { + classNames = className.split( /\s\s*/ ); + classNames.sort(); + path += '.'; + path += classNames.join( '.' ); + } + if ( dir = node.dir ) { + path += '[dir=' + dir + ']'; + } } } return path; @@ -327,16 +341,16 @@ function createElement ( doc, tag, props, children ) { return el; } -function fixCursor ( node ) { +function fixCursor ( node, root ) { // In Webkit and Gecko, block level elements are collapsed and // unfocussable if they have no content. To remedy this, a
must be // inserted. In Opera and IE, we just need a textnode in order for the // cursor to appear. var doc = node.ownerDocument, - root = node, + originalNode = node, fixer, child; - if ( node.nodeName === 'BODY' ) { + if ( node === root ) { if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) { fixer = getSquireInstance( doc ).createDefaultBlock(); if ( child ) { @@ -350,6 +364,10 @@ function fixCursor ( node ) { } } + if ( node.nodeType === TEXT_NODE ) { + return originalNode; + } + if ( isInline( node ) ) { child = node.firstChild; while ( cantFocusEmptyTextNodes && child && @@ -393,14 +411,22 @@ function fixCursor ( node ) { } } if ( fixer ) { - node.appendChild( fixer ); + try { + node.appendChild( fixer ); + } catch ( error ) { + getSquireInstance( doc ).didError({ + name: 'Squire: fixCursor – ' + error, + message: 'Parent: ' + node.nodeName + '/' + node.innerHTML + + ' appendChild: ' + fixer.nodeName + }); + } } - return root; + return originalNode; } // Recursively examine container nodes and wrap any inline children. -function fixContainer ( container ) { +function fixContainer ( container, root ) { var children = container.childNodes, doc = container.ownerDocument, wrapper = null, @@ -423,7 +449,7 @@ function fixContainer ( container ) { wrapper = createElement( doc, config.blockTag, config.blockAttributes ); } - fixCursor( wrapper ); + fixCursor( wrapper, root ); if ( isBR ) { container.replaceChild( wrapper, child ); } else { @@ -434,20 +460,21 @@ function fixContainer ( container ) { wrapper = null; } if ( isContainer( child ) ) { - fixContainer( child ); + fixContainer( child, root ); } } if ( wrapper ) { - container.appendChild( fixCursor( wrapper ) ); + container.appendChild( fixCursor( wrapper, root ) ); } return container; } -function split ( node, offset, stopNode ) { +function split ( node, offset, stopNode, root ) { var nodeType = node.nodeType, parent, clone, next; if ( nodeType === TEXT_NODE && node !== stopNode ) { - return split( node.parentNode, node.splitText( offset ), stopNode ); + return split( + node.parentNode, node.splitText( offset ), stopNode, root ); } if ( nodeType === ELEMENT_NODE ) { if ( typeof( offset ) === 'number' ) { @@ -470,7 +497,8 @@ function split ( node, offset, stopNode ) { } // Maintain li numbering if inside a quote. - if ( node.nodeName === 'OL' && getNearest( node, 'BLOCKQUOTE' ) ) { + if ( node.nodeName === 'OL' && + getNearest( node, root, 'BLOCKQUOTE' ) ) { clone.start = ( +node.start || 1 ) + node.childNodes.length - 1; } @@ -478,8 +506,8 @@ function split ( node, offset, stopNode ) { // of a node lower down the tree! // We need something in the element in order for the cursor to appear. - fixCursor( node ); - fixCursor( clone ); + fixCursor( node, root ); + fixCursor( clone, root ); // Inject clone after original node if ( next = node.nextSibling ) { @@ -489,7 +517,7 @@ function split ( node, offset, stopNode ) { } // Keep on splitting up the tree - return split( parent, clone, stopNode ); + return split( parent, clone, stopNode, root ); } return offset; } @@ -594,7 +622,7 @@ function mergeWithBlock ( block, next, range ) { } } -function mergeContainers ( node ) { +function mergeContainers ( node, root ) { var prev = node.previousSibling, first = node.firstChild, doc = node.ownerDocument, @@ -620,15 +648,15 @@ function mergeContainers ( node ) { needsFix = !isContainer( node ); prev.appendChild( empty( node ) ); if ( needsFix ) { - fixContainer( prev ); + fixContainer( prev, root ); } if ( first ) { - mergeContainers( first ); + mergeContainers( first, root ); } } else if ( isListItem ) { prev = createElement( doc, 'DIV' ); node.insertBefore( prev, first ); - fixCursor( prev ); + fixCursor( prev, root ); } } @@ -712,7 +740,7 @@ var insertNodeInRange = function ( range, node ) { range.setEnd( endContainer, endOffset ); }; -var extractContentsOfRange = function ( range, common ) { +var extractContentsOfRange = function ( range, common, root ) { var startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, @@ -726,8 +754,8 @@ var extractContentsOfRange = function ( range, common ) { common = common.parentNode; } - var endNode = split( endContainer, endOffset, common ), - startNode = split( startContainer, startOffset, common ), + var endNode = split( endContainer, endOffset, common, root ), + startNode = split( startContainer, startOffset, common, root ), frag = common.ownerDocument.createDocumentFragment(), next, before, after; @@ -759,12 +787,12 @@ var extractContentsOfRange = function ( range, common ) { range.setStart( startContainer, startOffset ); range.collapse( true ); - fixCursor( common ); + fixCursor( common, root ); return frag; }; -var deleteContentsOfRange = function ( range ) { +var deleteContentsOfRange = function ( range, root ) { // Move boundaries up as much as possible to reduce need to split. // But we need to check whether we've moved the boundary outside of a // block. If so, the entire block will be removed, so we shouldn't merge @@ -777,7 +805,7 @@ var deleteContentsOfRange = function ( range ) { ( isInline( endBlock ) || isBlock( endBlock ) ); // Remove selected range - extractContentsOfRange( range ); + var frag = extractContentsOfRange( range, null, root ); // Move boundaries back down tree so that they are inside the blocks. // If we don't do this, the range may be collapsed to a point between @@ -785,9 +813,9 @@ var deleteContentsOfRange = function ( range ) { moveRangeBoundariesDownTree( range ); // If we split into two different blocks, merge the blocks. + startBlock = getStartBlockOfRange( range, root ); if ( needsMerge ) { - startBlock = getStartBlockOfRange( range ); - endBlock = getEndBlockOfRange( range ); + endBlock = getEndBlockOfRange( range, root ); if ( startBlock && endBlock && startBlock !== endBlock ) { mergeWithBlock( startBlock, endBlock, range ); } @@ -795,23 +823,23 @@ var deleteContentsOfRange = function ( range ) { // Ensure block has necessary children if ( startBlock ) { - fixCursor( startBlock ); + fixCursor( startBlock, root ); } - // Ensure body has a block-level element in it. - var body = range.endContainer.ownerDocument.body, - child = body.firstChild; + // Ensure root has a block-level element in it. + var child = root.firstChild; if ( !child || child.nodeName === 'BR' ) { - fixCursor( body ); - range.selectNodeContents( body.firstChild ); + fixCursor( root, root ); + range.selectNodeContents( root.firstChild ); } else { range.collapse( false ); } + return frag; }; // --- -var insertTreeFragmentIntoRange = function ( range, frag ) { +var insertTreeFragmentIntoRange = function ( range, frag, root ) { // Check if it's all inline content var allInline = true, children = frag.childNodes, @@ -825,7 +853,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { // Delete any selected content if ( !range.collapsed ) { - deleteContentsOfRange( range ); + deleteContentsOfRange( range, root ); } // Move range down into text nodes @@ -837,11 +865,14 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { range.collapse( false ); } else { // Otherwise... - // 1. Split up to blockquote (if a parent) or body + // 1. Split up to blockquote (if a parent) or root var splitPoint = range.startContainer, - nodeAfterSplit = split( splitPoint, range.startOffset, - getNearest( splitPoint.parentNode, 'BLOCKQUOTE' ) || - splitPoint.ownerDocument.body ), + nodeAfterSplit = split( + splitPoint, + range.startOffset, + getNearest( splitPoint.parentNode, root, 'BLOCKQUOTE' ) || root, + root + ), nodeBeforeSplit = nodeAfterSplit.previousSibling, startContainer = nodeBeforeSplit, startOffset = startContainer.childNodes.length, @@ -877,22 +908,21 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { // 3. Fix cursor then insert block(s) in the fragment node = frag; - while ( node = getNextBlock( node ) ) { - fixCursor( node ); + while ( node = getNextBlock( node, root ) ) { + fixCursor( node, root ); } parent.insertBefore( frag, nodeAfterSplit ); // 4. Remove empty nodes created either side of split, then // merge containers at the edges. next = nodeBeforeSplit.nextSibling; - node = getPreviousBlock( next ); - if ( !/\S/.test( node.textContent ) ) { + node = getPreviousBlock( next, root ); + if ( node && !/\S/.test( node.textContent ) ) { do { parent = node.parentNode; parent.removeChild( node ); node = parent; - } while ( parent && !parent.lastChild && - parent.nodeName !== 'BODY' ); + } while ( node && !node.lastChild && node !== root ); } if ( !nodeBeforeSplit.parentNode ) { nodeBeforeSplit = next.previousSibling; @@ -904,19 +934,18 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { } // Merge inserted containers with edges of split if ( isContainer( next ) ) { - mergeContainers( next ); + mergeContainers( next, root ); } prev = nodeAfterSplit.previousSibling; node = isBlock( nodeAfterSplit ) ? - nodeAfterSplit : getNextBlock( nodeAfterSplit ); - if ( !/\S/.test( node.textContent ) ) { + nodeAfterSplit : getNextBlock( nodeAfterSplit, root ); + if ( node && !/\S/.test( node.textContent ) ) { do { parent = node.parentNode; parent.removeChild( node ); node = parent; - } while ( parent && !parent.lastChild && - parent.nodeName !== 'BODY' ); + } while ( node && !node.lastChild && node !== root ); } if ( !nodeAfterSplit.parentNode ) { nodeAfterSplit = prev.nextSibling; @@ -927,7 +956,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { } // Merge inserted containers with edges of split if ( nodeAfterSplit && isContainer( nodeAfterSplit ) ) { - mergeContainers( nodeAfterSplit ); + mergeContainers( nodeAfterSplit, root ); } range.setStart( startContainer, startOffset ); @@ -1039,18 +1068,18 @@ var moveRangeBoundariesUpTree = function ( range, common ) { // Returns the first block at least partially contained by the range, // or null if no block is contained by the range. -var getStartBlockOfRange = function ( range ) { +var getStartBlockOfRange = function ( range, root ) { var container = range.startContainer, block; // If inline, get the containing block. if ( isInline( container ) ) { - block = getPreviousBlock( container ); + block = getPreviousBlock( container, root ); } else if ( isBlock( container ) ) { block = container; } else { block = getNodeBefore( container, range.startOffset ); - block = getNextBlock( block ); + block = getNextBlock( block, root ); } // Check the block actually intersects the range return block && isNodeContainedInRange( range, block, true ) ? block : null; @@ -1058,25 +1087,24 @@ var getStartBlockOfRange = function ( range ) { // Returns the last block at least partially contained by the range, // or null if no block is contained by the range. -var getEndBlockOfRange = function ( range ) { +var getEndBlockOfRange = function ( range, root ) { var container = range.endContainer, block, child; // If inline, get the containing block. if ( isInline( container ) ) { - block = getPreviousBlock( container ); + block = getPreviousBlock( container, root ); } else if ( isBlock( container ) ) { block = container; } else { block = getNodeAfter( container, range.endOffset ); if ( !block ) { - block = container.ownerDocument.body; + block = root; while ( child = block.lastChild ) { block = child; } } - block = getPreviousBlock( block ); - + block = getPreviousBlock( block, root ); } // Check the block actually intersects the range return block && isNodeContainedInRange( range, block, true ) ? block : null; @@ -1091,7 +1119,7 @@ var contentWalker = new TreeWalker( null, } ); -var rangeDoesStartAtBlockBoundary = function ( range ) { +var rangeDoesStartAtBlockBoundary = function ( range, root ) { var startContainer = range.startContainer, startOffset = range.startOffset; @@ -1104,15 +1132,19 @@ var rangeDoesStartAtBlockBoundary = function ( range ) { contentWalker.currentNode = startContainer; } else { contentWalker.currentNode = getNodeAfter( startContainer, startOffset ); + + if ( !contentWalker.currentNode ) { + contentWalker.currentNode = startContainer; + } } // Otherwise, look for any previous content in the same block. - contentWalker.root = getStartBlockOfRange( range ); + contentWalker.root = getStartBlockOfRange( range, root ); return !contentWalker.previousNode(); }; -var rangeDoesEndAtBlockBoundary = function ( range ) { +var rangeDoesEndAtBlockBoundary = function ( range, root ) { var endContainer = range.endContainer, endOffset = range.endOffset, length; @@ -1131,14 +1163,14 @@ var rangeDoesEndAtBlockBoundary = function ( range ) { } // Otherwise, look for any further content in the same block. - contentWalker.root = getEndBlockOfRange( range ); + contentWalker.root = getEndBlockOfRange( range, root ); return !contentWalker.nextNode(); }; -var expandRangeToBlockBoundaries = function ( range ) { - var start = getStartBlockOfRange( range ), - end = getEndBlockOfRange( range ), +var expandRangeToBlockBoundaries = function ( range, root ) { + var start = getStartBlockOfRange( range, root ), + end = getEndBlockOfRange( range, root ), parent; if ( start && end ) { @@ -1210,10 +1242,9 @@ var onKey = function ( event ) { this._keyHandlers[ key ]( this, event, range ); } else if ( key.length === 1 && !range.collapsed ) { // Record undo checkpoint. - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); + this.saveUndoState( range ); // Delete the selection - deleteContentsOfRange( range ); + deleteContentsOfRange( range, this._root ); this._ensureBottomLine(); this.setSelection( range ); this._updatePath( range, true ); @@ -1270,17 +1301,17 @@ var afterDelete = function ( self, range ) { parent.removeChild( node ); // Fix cursor in block if ( !isBlock( parent ) ) { - parent = getPreviousBlock( parent ); + parent = getPreviousBlock( parent, self._root ); } - fixCursor( parent ); + fixCursor( parent, self._root ); // Move cursor into text node moveRangeBoundariesDownTree( range ); } // If you delete the last character in the sole
in Chrome, // it removes the div and replaces it with just a
inside the - // body. Detach the
; the _ensureBottomLine call will insert a new + // root. Detach the
; the _ensureBottomLine call will insert a new // block. - if ( node.nodeName === 'BODY' && + if ( node === self._root && ( node = node.firstChild ) && node.nodeName === 'BR' ) { detach( node ); } @@ -1294,6 +1325,7 @@ var afterDelete = function ( self, range ) { var keyHandlers = { enter: function ( self, event, range ) { + var root = self._root; var block, parent, nodeAfterSplit; // We handle this ourselves @@ -1303,17 +1335,17 @@ var keyHandlers = { // Remove any zws so we don't think there's content in an empty // block. self._recordUndoState( range ); - addLinks( range.startContainer ); + addLinks( range.startContainer, root, self ); self._removeZWS(); self._getRangeAndRemoveBookmark( range ); // Selected text is overwritten, therefore delete the contents // to collapse selection. if ( !range.collapsed ) { - deleteContentsOfRange( range ); + deleteContentsOfRange( range, root ); } - block = getStartBlockOfRange( range ); + block = getStartBlockOfRange( range, root ); // If this is a malformed bit of document or in a table; // just play it safe and insert a
. @@ -1326,17 +1358,18 @@ var keyHandlers = { } // If in a list, we'll split the LI instead. - if ( parent = getNearest( block, 'LI' ) ) { + if ( parent = getNearest( block, root, 'LI' ) ) { block = parent; } if ( !block.textContent ) { // Break list - if ( getNearest( block, 'UL' ) || getNearest( block, 'OL' ) ) { + if ( getNearest( block, root, 'UL' ) || + getNearest( block, root, 'OL' ) ) { return self.modifyBlocks( decreaseListLevel, range ); } // Break blockquote - else if ( getNearest( block, 'BLOCKQUOTE' ) ) { + else if ( getNearest( block, root, 'BLOCKQUOTE' ) ) { return self.modifyBlocks( removeBlockQuote, range ); } } @@ -1349,7 +1382,7 @@ var keyHandlers = { // block removeZWS( block ); removeEmptyInlines( block ); - fixCursor( block ); + fixCursor( block, root ); // Focus cursor // If there's a / etc. at the beginning of the split @@ -1392,21 +1425,28 @@ var keyHandlers = { self._updatePath( range, true ); }, backspace: function ( self, event, range ) { + var root = self._root; self._removeZWS(); // Record undo checkpoint. - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); + self.saveUndoState( range ); // If not collapsed, delete contents if ( !range.collapsed ) { event.preventDefault(); - deleteContentsOfRange( range ); + deleteContentsOfRange( range, root ); afterDelete( self, range ); } // If at beginning of block, merge with previous - else if ( rangeDoesStartAtBlockBoundary( range ) ) { + else if ( rangeDoesStartAtBlockBoundary( range, root ) ) { event.preventDefault(); - var current = getStartBlockOfRange( range ), - previous = current && getPreviousBlock( current ); + var current = getStartBlockOfRange( range, root ); + var previous; + if ( !current ) { + return; + } + // In case inline data has somehow got between blocks. + fixContainer( current.parentNode, root ); + // Now get previous block + previous = getPreviousBlock( current, root ); // Must not be at the very beginning of the text area. if ( previous ) { // If not editable, just delete whole block. @@ -1419,11 +1459,11 @@ var keyHandlers = { // If deleted line between containers, merge newly adjacent // containers. current = previous.parentNode; - while ( current && !current.nextSibling ) { + while ( current !== root && !current.nextSibling ) { current = current.parentNode; } - if ( current && ( current = current.nextSibling ) ) { - mergeContainers( current ); + if ( current !== root && ( current = current.nextSibling ) ) { + mergeContainers( current, root ); } self.setSelection( range ); } @@ -1431,12 +1471,12 @@ var keyHandlers = { // to break lists/blockquote. else if ( current ) { // Break list - if ( getNearest( current, 'UL' ) || - getNearest( current, 'OL' ) ) { + if ( getNearest( current, root, 'UL' ) || + getNearest( current, root, 'OL' ) ) { return self.modifyBlocks( decreaseListLevel, range ); } // Break blockquote - else if ( getNearest( current, 'BLOCKQUOTE' ) ) { + else if ( getNearest( current, root, 'BLOCKQUOTE' ) ) { return self.modifyBlocks( decreaseBlockQuoteLevel, range ); } self.setSelection( range ); @@ -1451,21 +1491,29 @@ var keyHandlers = { } }, 'delete': function ( self, event, range ) { + var root = self._root; + var current, next, originalRange, + cursorContainer, cursorOffset, nodeAfterCursor; self._removeZWS(); // Record undo checkpoint. - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); + self.saveUndoState( range ); // If not collapsed, delete contents if ( !range.collapsed ) { event.preventDefault(); - deleteContentsOfRange( range ); + deleteContentsOfRange( range, root ); afterDelete( self, range ); } // If at end of block, merge next into this block - else if ( rangeDoesEndAtBlockBoundary( range ) ) { + else if ( rangeDoesEndAtBlockBoundary( range, root ) ) { event.preventDefault(); - var current = getStartBlockOfRange( range ), - next = current && getNextBlock( current ); + current = getStartBlockOfRange( range, root ); + if ( !current ) { + return; + } + // In case inline data has somehow got between blocks. + fixContainer( current.parentNode, root ); + // Now get next block + next = getNextBlock( current, root ); // Must not be at the very end of the text area. if ( next ) { // If not editable, just delete whole block. @@ -1478,11 +1526,11 @@ var keyHandlers = { // If deleted line between containers, merge newly adjacent // containers. next = current.parentNode; - while ( next && !next.nextSibling ) { + while ( next !== root && !next.nextSibling ) { next = next.parentNode; } - if ( next && ( next = next.nextSibling ) ) { - mergeContainers( next ); + if ( next !== root && ( next = next.nextSibling ) ) { + mergeContainers( next, root ); } self.setSelection( range ); self._updatePath( range, true ); @@ -1494,9 +1542,8 @@ var keyHandlers = { // But first check if the cursor is just before an IMG tag. If so, // delete it ourselves, because the browser won't if it is not // inline. - var originalRange = range.cloneRange(), - cursorContainer, cursorOffset, nodeAfterCursor; - moveRangeBoundariesUpTree( range, self._body ); + originalRange = range.cloneRange(); + moveRangeBoundariesUpTree( range, self._root ); cursorContainer = range.endContainer; cursorOffset = range.endOffset; if ( cursorContainer.nodeType === ELEMENT_NODE ) { @@ -1514,11 +1561,12 @@ var keyHandlers = { } }, tab: function ( self, event, range ) { + var root = self._root; var node, parent; self._removeZWS(); // If no selection and at start of block - if ( range.collapsed && rangeDoesStartAtBlockBoundary( range ) ) { - node = getStartBlockOfRange( range ); + if ( range.collapsed && rangeDoesStartAtBlockBoundary( range, root ) ) { + node = getStartBlockOfRange( range, root ); // Iterate through the block's parents while ( parent = node.parentNode ) { // If we find a UL or OL (so are in a list, node must be an LI) @@ -1536,12 +1584,15 @@ var keyHandlers = { } }, 'shift-tab': function ( self, event, range ) { + var root = self._root; + var node; self._removeZWS(); // If no selection and at start of block - if ( range.collapsed && rangeDoesStartAtBlockBoundary( range ) ) { + if ( range.collapsed && rangeDoesStartAtBlockBoundary( range, root ) ) { // Break list - var node = range.startContainer; - if ( getNearest( node, 'UL' ) || getNearest( node, 'OL' ) ) { + node = range.startContainer; + if ( getNearest( node, root, 'UL' ) || + getNearest( node, root, 'OL' ) ) { event.preventDefault(); self.modifyBlocks( decreaseListLevel, range ); } @@ -1550,7 +1601,7 @@ var keyHandlers = { space: function ( self, _, range ) { var node, parent; self._recordUndoState( range ); - addLinks( range.startContainer ); + addLinks( range.startContainer, self._root, self ); self._getRangeAndRemoveBookmark( range ); // If the cursor is at the end of a link (foo|) then move it @@ -1573,18 +1624,24 @@ var keyHandlers = { } }; -// Firefox incorrectly handles Cmd-left/Cmd-right on Mac: +// Firefox pre v29 incorrectly handles Cmd-left/Cmd-right on Mac: // it goes back/forward in history! Override to do the right // thing. // https://bugzilla.mozilla.org/show_bug.cgi?id=289384 -if ( isMac && isGecko && win.getSelection().modify ) { +if ( isMac && isGecko ) { keyHandlers[ 'meta-left' ] = function ( self, event ) { event.preventDefault(); - self._sel.modify( 'move', 'backward', 'lineboundary' ); + var sel = getWindowSelection( self ); + if ( sel && sel.modify ) { + sel.modify( 'move', 'backward', 'lineboundary' ); + } }; keyHandlers[ 'meta-right' ] = function ( self, event ) { event.preventDefault(); - self._sel.modify( 'move', 'forward', 'lineboundary' ); + var sel = getWindowSelection( self ); + if ( sel && sel.modify ) { + sel.modify( 'move', 'forward', 'lineboundary' ); + } }; } @@ -1792,7 +1849,7 @@ var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () { and whitespace nodes. 2. Convert inline tags into our preferred format. */ -var cleanTree = function cleanTree ( node ) { +var cleanTree = function cleanTree ( node, preserveWS ) { var children = node.childNodes, nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength, startsWithWS, endsWithWS, data, sibling; @@ -1824,14 +1881,14 @@ var cleanTree = function cleanTree ( node ) { continue; } if ( childLength ) { - cleanTree( child ); + cleanTree( child, preserveWS || ( nodeName === 'PRE' ) ); } } else { if ( nodeType === TEXT_NODE ) { data = child.data; startsWithWS = !notWS.test( data.charAt( 0 ) ); endsWithWS = !notWS.test( data.charAt( data.length - 1 ) ); - if ( !startsWithWS && !endsWithWS ) { + if ( preserveWS || ( !startsWithWS && !endsWithWS ) ) { continue; } // Iterate through the nodes; if we hit some other content @@ -1850,9 +1907,7 @@ var cleanTree = function cleanTree ( node ) { break; } } - if ( !sibling ) { - data = data.replace( /^\s+/g, '' ); - } + data = data.replace( /^\s+/g, sibling ? ' ' : '' ); } if ( endsWithWS ) { walker.currentNode = child; @@ -1867,9 +1922,7 @@ var cleanTree = function cleanTree ( node ) { break; } } - if ( !sibling ) { - data = data.replace( /^\s+/g, '' ); - } + data = data.replace( /\s+$/g, sibling ? ' ' : '' ); } if ( data ) { child.data = data; @@ -1886,8 +1939,8 @@ var cleanTree = function cleanTree ( node ) { // --- -var removeEmptyInlines = function removeEmptyInlines ( root ) { - var children = root.childNodes, +var removeEmptyInlines = function removeEmptyInlines ( node ) { + var children = node.childNodes, l = children.length, child; while ( l-- ) { @@ -1895,10 +1948,10 @@ var removeEmptyInlines = function removeEmptyInlines ( root ) { if ( child.nodeType === ELEMENT_NODE && !isLeaf( child ) ) { removeEmptyInlines( child ); if ( isInline( child ) && !child.firstChild ) { - root.removeChild( child ); + node.removeChild( child ); } } else if ( child.nodeType === TEXT_NODE && !child.data ) { - root.removeChild( child ); + node.removeChild( child ); } } }; @@ -1928,8 +1981,8 @@ var isLineBreak = function ( br ) { // line breaks by wrapping the inline text in a
. Browsers that want
// elements at the end of each block will then have them added back in a later // fixCursor method call. -var cleanupBRs = function ( root ) { - var brs = root.querySelectorAll( 'BR' ), +var cleanupBRs = function ( node, root ) { + var brs = node.querySelectorAll( 'BR' ), brBreaksLine = [], l = brs.length, i, br, parent; @@ -1954,26 +2007,60 @@ var cleanupBRs = function ( root ) { if ( !brBreaksLine[l] ) { detach( br ); } else if ( !isInline( parent ) ) { - fixContainer( parent ); + fixContainer( parent, root ); } } }; -var onCut = function () { - // Save undo checkpoint +var onCut = function ( event ) { + var clipboardData = event.clipboardData; var range = this.getSelection(); + var node = this.createElement( 'div' ); + var root = this._root; var self = this; - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); + + // Save undo checkpoint + this.saveUndoState( range ); + + // Edge only seems to support setting plain text as of 2016-03-11. + // Mobile Safari flat out doesn't work: + // https://bugs.webkit.org/show_bug.cgi?id=143776 + if ( !isEdge && !isIOS && clipboardData ) { + moveRangeBoundariesUpTree( range, root ); + node.appendChild( deleteContentsOfRange( range, root ) ); + clipboardData.setData( 'text/html', node.innerHTML ); + clipboardData.setData( 'text/plain', + node.innerText || node.textContent ); + event.preventDefault(); + } else { + setTimeout( function () { + try { + // If all content removed, ensure div at start of root. + self._ensureBottomLine(); + } catch ( error ) { + self.didError( error ); + } + }, 0 ); + } + this.setSelection( range ); - setTimeout( function () { - try { - // If all content removed, ensure div at start of body. - self._ensureBottomLine(); - } catch ( error ) { - self.didError( error ); - } - }, 0 ); +}; + +var onCopy = function ( event ) { + var clipboardData = event.clipboardData; + var range = this.getSelection(); + var node = this.createElement( 'div' ); + + // Edge only seems to support setting plain text as of 2016-03-11. + // Mobile Safari flat out doesn't work: + // https://bugs.webkit.org/show_bug.cgi?id=143776 + if ( !isEdge && !isIOS && clipboardData ) { + node.appendChild( range.cloneContents() ); + clipboardData.setData( 'text/html', node.innerHTML ); + clipboardData.setData( 'text/plain', + node.innerText || node.textContent ); + event.preventDefault(); + } }; var onPaste = function ( event ) { @@ -1983,13 +2070,14 @@ var onPaste = function ( event ) { hasImage = false, plainItem = null, self = this, - l, item, type, data; + l, item, type, types, data; // Current HTML5 Clipboard interface // --------------------------------- // https://html.spec.whatwg.org/multipage/interaction.html - if ( items ) { + // Edge only provides access to plain text as of 2016-03-11. + if ( !isEdge && items ) { event.preventDefault(); l = items.length; while ( l-- ) { @@ -2040,42 +2128,51 @@ var onPaste = function ( event ) { // rather than text/html; even from a webpage in Safari. The only way // to get an HTML version is to fallback to letting the browser insert // the content. Same for getting image data. *Sigh*. - if ( clipboardData && ( - indexOf.call( clipboardData.types, 'text/html' ) > -1 || ( - indexOf.call( clipboardData.types, 'text/plain' ) > -1 && - indexOf.call( clipboardData.types, 'text/rtf' ) < 0 ) ) ) { + // + // Firefox is even worse: it doesn't even let you know that there might be + // an RTF version on the clipboard, but it will also convert to HTML if you + // let the browser insert the content. I've filed + // https://bugzilla.mozilla.org/show_bug.cgi?id=1254028 + types = clipboardData && clipboardData.types; + if ( !isEdge && types && ( + indexOf.call( types, 'text/html' ) > -1 || ( + !isGecko && + indexOf.call( types, 'text/plain' ) > -1 && + indexOf.call( types, 'text/rtf' ) < 0 ) + )) { event.preventDefault(); // Abiword on Linux copies a plain text and html version, but the HTML // version is the empty string! So always try to get HTML, but if none, - // insert plain text instead. + // insert plain text instead. On iOS, Facebook (and possibly other + // apps?) copy links as type text/uri-list, but also insert a **blank** + // text/plain item onto the clipboard. Why? Who knows. if (( data = clipboardData.getData( 'text/html' ) )) { this.insertHTML( data, true ); - } else if (( data = clipboardData.getData( 'text/plain' ) )) { + } else if ( + ( data = clipboardData.getData( 'text/plain' ) ) || + ( data = clipboardData.getData( 'text/uri-list' ) ) ) { this.insertPlainText( data, true ); } return; } - // No interface :( - // --------------- + // No interface. Includes all versions of IE :( + // -------------------------------------------- this._awaitingPaste = true; - var body = this._body, + var body = this._doc.body, range = this.getSelection(), startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, - endOffset = range.endOffset, - startBlock = getStartBlockOfRange( range ); + endOffset = range.endOffset; // We need to position the pasteArea in the visible portion of the screen // to stop the browser auto-scrolling. var pasteArea = this.createElement( 'DIV', { - style: 'position: absolute; overflow: hidden; top:' + - ( body.scrollTop + - ( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) + - 'px; right: 150%; width: 1px; height: 1px;' + contenteditable: 'true', + style: 'position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;' }); body.appendChild( pasteArea ); range.selectNodeContents( pasteArea ); @@ -2150,14 +2247,17 @@ function mergeObjects ( base, extras ) { return base; } -function Squire ( doc, config ) { +function Squire ( root, config ) { + if ( root.nodeType === DOCUMENT_NODE ) { + root = root.body; + } + var doc = root.ownerDocument; var win = doc.defaultView; - var body = doc.body; var mutation; this._win = win; this._doc = doc; - this._body = body; + this._root = root; this._events = {}; @@ -2175,21 +2275,23 @@ function Squire ( doc, config ) { this._lastFocusNode = null; this._path = ''; - this.addEventListener( 'keyup', this._updatePathOnEvent ); - this.addEventListener( 'mouseup', this._updatePathOnEvent ); - - win.addEventListener( 'focus', this, false ); - win.addEventListener( 'blur', this, false ); + if ( 'onselectionchange' in doc ) { + this.addEventListener( 'selectionchange', this._updatePathOnEvent ); + } else { + this.addEventListener( 'keyup', this._updatePathOnEvent ); + this.addEventListener( 'mouseup', this._updatePathOnEvent ); + } this._undoIndex = -1; this._undoStack = []; this._undoStackLength = 0; this._isInUndoState = false; this._ignoreChange = false; + this._ignoreAllChanges = false; if ( canObserveMutations ) { mutation = new MutationObserver( this._docWasChanged.bind( this ) ); - mutation.observe( body, { + mutation.observe( root, { childList: true, attributes: true, characterData: true, @@ -2200,10 +2302,22 @@ function Squire ( doc, config ) { this.addEventListener( 'keyup', this._keyUpDetectChange ); } + // On blur, restore focus except if there is any change to the content, or + // the user taps or clicks to focus a specific point. Can't actually use + // click event because focus happens before click, so use + // mousedown/touchstart + this._restoreSelection = false; + this.addEventListener( 'blur', enableRestoreSelection ); + this.addEventListener( 'input', disableRestoreSelection ); + this.addEventListener( 'mousedown', disableRestoreSelection ); + this.addEventListener( 'touchstart', disableRestoreSelection ); + this.addEventListener( 'focus', restoreSelection ); + // IE sometimes fires the beforepaste event twice; make sure it is not run // again before our after paste function is called. this._awaitingPaste = false; this.addEventListener( isIElt11 ? 'beforecut' : 'cut', onCut ); + this.addEventListener( 'copy', onCopy ); this.addEventListener( isIElt11 ? 'beforepaste' : 'paste', onPaste ); // Opera does not fire keydown repeatedly. @@ -2244,7 +2358,7 @@ function Squire ( doc, config ) { }; } - body.setAttribute( 'contenteditable', 'true' ); + root.setAttribute( 'contenteditable', 'true' ); // Remove Firefox's built-in controls try { @@ -2269,7 +2383,8 @@ proto.setConfig = function ( config ) { blockquote: null, ul: null, ol: null, - li: null + li: null, + a: null } }, config ); @@ -2288,7 +2403,8 @@ proto.createElement = function ( tag, props, children ) { proto.createDefaultBlock = function ( children ) { var config = this._config; return fixCursor( - this.createElement( config.blockTag, config.blockAttributes, children ) + this.createElement( config.blockTag, config.blockAttributes, children ), + this._root ); }; @@ -2299,6 +2415,28 @@ proto.didError = function ( error ) { proto.getDocument = function () { return this._doc; }; +proto.getRoot = function () { + return this._root; +}; + +proto.modifyDocument = function ( modificationCallback ) { + this._ignoreAllChanges = true; + if ( this._mutation ) { + this._mutation.disconnect(); + } + + modificationCallback(); + + this._ignoreAllChanges = false; + if ( this._mutation ) { + this._mutation.observe( this._root, { + childList: true, + attributes: true, + characterData: true, + subtree: true + }); + } +}; // --- Events --- @@ -2306,7 +2444,6 @@ proto.getDocument = function () { // document node, since these events are fired in a custom manner by the // editor code. var customEvents = { - focus: 1, blur: 1, pathChange: 1, select: 1, input: 1, undoStateChange: 1 }; @@ -2341,21 +2478,15 @@ proto.fireEvent = function ( type, event ) { }; proto.destroy = function () { - var win = this._win, - doc = this._doc, - events = this._events, - type; - win.removeEventListener( 'focus', this, false ); - win.removeEventListener( 'blur', this, false ); + var l = instances.length; + var events = this._events; + var type; for ( type in events ) { - if ( !customEvents[ type ] ) { - doc.removeEventListener( type, this, true ); - } + this.removeEventListener( type ); } if ( this._mutation ) { this._mutation.disconnect(); } - var l = instances.length; while ( l-- ) { if ( instances[l] === this ) { instances.splice( l, 1 ); @@ -2369,6 +2500,7 @@ proto.handleEvent = function ( event ) { proto.addEventListener = function ( type, fn ) { var handlers = this._events[ type ]; + var target = this._root; if ( !fn ) { this.didError({ name: 'Squire: addEventListener with null or undefined fn', @@ -2379,7 +2511,10 @@ proto.addEventListener = function ( type, fn ) { if ( !handlers ) { handlers = this._events[ type ] = []; if ( !customEvents[ type ] ) { - this._doc.addEventListener( type, this, true ); + if ( type === 'selectionchange' ) { + target = this._doc; + } + target.addEventListener( type, this, true ); } } handlers.push( fn ); @@ -2387,19 +2522,27 @@ proto.addEventListener = function ( type, fn ) { }; proto.removeEventListener = function ( type, fn ) { - var handlers = this._events[ type ], - l; + var handlers = this._events[ type ]; + var target = this._root; + var l; if ( handlers ) { - l = handlers.length; - while ( l-- ) { - if ( handlers[l] === fn ) { - handlers.splice( l, 1 ); + if ( fn ) { + l = handlers.length; + while ( l-- ) { + if ( handlers[l] === fn ) { + handlers.splice( l, 1 ); + } } + } else { + handlers.length = 0; } if ( !handlers.length ) { delete this._events[ type ]; if ( !customEvents[ type ] ) { - this._doc.removeEventListener( type, this, false ); + if ( type === 'selectionchange' ) { + target = this._doc; + } + target.removeEventListener( type, this, true ); } } } @@ -2423,28 +2566,35 @@ proto._createRange = return domRange; }; -proto.scrollRangeIntoView = function ( range ) { - var win = this._win; - var top = range.getBoundingClientRect().top; - var height = win.innerHeight; +proto.getCursorPosition = function ( range ) { + if ( ( !range && !( range = this.getSelection() ) ) || + !range.getBoundingClientRect ) { + return null; + } + // Get the bounding rect + var rect = range.getBoundingClientRect(); var node, parent; - if ( !top ) { + if ( rect && !rect.top ) { + this._ignoreChange = true; node = this._doc.createElement( 'SPAN' ); - range = range.cloneRange(); + node.textContent = ZWS; insertNodeInRange( range, node ); - top = node.getBoundingClientRect().top; + rect = node.getBoundingClientRect(); parent = node.parentNode; parent.removeChild( node ); - parent.normalize(); - } - if ( top > height ) { - win.scrollBy( 0, top - height + 20 ); + mergeInlines( parent, { + startContainer: range.startContainer, + endContainer: range.endContainer, + startOffset: range.startOffset, + endOffset: range.endOffset + }); } + return rect; }; proto._moveCursorTo = function ( toStart ) { - var body = this._body, - range = this._createRange( body, toStart ? 0 : body.childNodes.length ); + var root = this._root, + range = this._createRange( root, toStart ? 0 : root.childNodes.length ); moveRangeBoundariesDownTree( range ); this.setSelection( range ); return this; @@ -2456,8 +2606,15 @@ proto.moveCursorToEnd = function () { return this._moveCursorTo( false ); }; +var getWindowSelection = function ( self ) { + return self._win.getSelection() || null; +}; + proto.setSelection = function ( range ) { if ( range ) { + // If we're setting selection, that automatically, and synchronously, // triggers a focus event. Don't want a reentrant call to setSelection. + this._restoreSelection = false; + this._lastSelection = range; // iOS bug: if you don't focus the iframe before setting the // selection, you can end up in a state where you type but the input // doesn't get directed into the contenteditable area but is instead @@ -2465,23 +2622,19 @@ proto.setSelection = function ( range ) { if ( isIOS ) { this._win.focus(); } - var sel = this._getWindowSelection(); + var sel = getWindowSelection( this ); if ( sel ) { sel.removeAllRanges(); sel.addRange( range ); - this.scrollRangeIntoView( range ); } } return this; }; -proto._getWindowSelection = function () { - return this._win.getSelection() || null; -}; - proto.getSelection = function () { - var sel = this._getWindowSelection(), - selection, startContainer, endContainer; + var sel = getWindowSelection( this ); + var root = this._root; + var selection, startContainer, endContainer; if ( sel && sel.rangeCount ) { selection = sel.getRangeAt( 0 ).cloneRange(); startContainer = selection.startContainer; @@ -2493,16 +2646,31 @@ proto.getSelection = function () { if ( endContainer && isLeaf( endContainer ) ) { selection.setEndBefore( endContainer ); } + } + if ( selection && + isOrContains( root, selection.commonAncestorContainer ) ) { this._lastSelection = selection; } else { selection = this._lastSelection; } if ( !selection ) { - selection = this._createRange( this._body.firstChild, 0 ); + selection = this._createRange( root.firstChild, 0 ); } return selection; }; +function enableRestoreSelection () { + this._restoreSelection = true; +} +function disableRestoreSelection () { + this._restoreSelection = false; +} +function restoreSelection () { + if ( this._restoreSelection ) { + this.setSelection( this._lastSelection ); + } +} + proto.getSelectedText = function () { var range = this.getSelection(), walker = new TreeWalker( @@ -2584,7 +2752,7 @@ proto._removeZWS = function () { if ( !this._hasZWS ) { return; } - removeZWS( this._body ); + removeZWS( this._root ); this._hasZWS = false; }; @@ -2599,7 +2767,7 @@ proto._updatePath = function ( range, force ) { this._lastAnchorNode = anchor; this._lastFocusNode = focus; newPath = ( anchor && focus ) ? ( anchor === focus ) ? - getPath( focus ) : '(selection)' : ''; + getPath( focus, this._root ) : '(selection)' : ''; if ( this._path !== newPath ) { this._path = newPath; this.fireEvent( 'pathChange', { path: newPath } ); @@ -2617,26 +2785,12 @@ proto._updatePathOnEvent = function () { // --- Focus --- proto.focus = function () { - // FF seems to need the body to be focussed (at least on first load). - // Chrome also now needs body to be focussed in order to show the cursor - // (otherwise it is focussed, but the cursor doesn't appear). - // Opera (Presto-variant) however will lose the selection if you call this! - if ( !isPresto ) { - this._body.focus(); - } - this._win.focus(); + this._root.focus(); return this; }; proto.blur = function () { - // IE will remove the whole browser window from focus if you call - // win.blur() or body.blur(), so instead we call top.focus() to focus - // the top frame, thus blurring this frame. This works in everything - // except FF, so we need to call body.blur() in that as well. - if ( isGecko ) { - this._body.blur(); - } - top.focus(); + this._root.blur(); return this; }; @@ -2675,9 +2829,9 @@ proto._saveRangeToBookmark = function ( range ) { }; proto._getRangeAndRemoveBookmark = function ( range ) { - var doc = this._doc, - start = doc.getElementById( startSelectionId ), - end = doc.getElementById( endSelectionId ); + var root = this._root, + start = root.querySelector( '#' + startSelectionId ), + end = root.querySelector( '#' + endSelectionId ); if ( start && end ) { var startContainer = start.parentNode, @@ -2705,15 +2859,27 @@ proto._getRangeAndRemoveBookmark = function ( range ) { } if ( !range ) { - range = doc.createRange(); + range = this._doc.createRange(); } range.setStart( _range.startContainer, _range.startOffset ); range.setEnd( _range.endContainer, _range.endOffset ); collapsed = range.collapsed; - moveRangeBoundariesDownTree( range ); + // If we didn't split a text node, we should move into any adjacent + // text node to current selection point if ( collapsed ) { - range.collapse( true ); + startContainer = range.startContainer; + if ( startContainer.nodeType === TEXT_NODE ) { + endContainer = startContainer.childNodes[ range.startOffset ]; + if ( !endContainer || endContainer.nodeType !== TEXT_NODE ) { + endContainer = + startContainer.childNodes[ range.startOffset - 1 ]; + } + if ( endContainer && endContainer.nodeType === TEXT_NODE ) { + range.setStart( endContainer, 0 ); + range.collapse( true ); + } + } } } return range || null; @@ -2735,6 +2901,10 @@ proto._keyUpDetectChange = function ( event ) { }; proto._docWasChanged = function () { + if ( this._ignoreAllChanges ) { + return; + } + if ( canObserveMutations && this._ignoreChange ) { this._ignoreChange = false; return; @@ -2772,6 +2942,17 @@ proto._recordUndoState = function ( range ) { } }; +proto.saveUndoState = function ( range ) { + if ( range === undefined ) { + range = this.getSelection(); + } + if ( !this._isInUndoState ) { + this._recordUndoState( range ); + this._getRangeAndRemoveBookmark( range ); + } + return this; +}; + proto.undo = function () { // Sanity check: must not be at beginning of the history stack if ( this._undoIndex !== 0 || !this._isInUndoState ) { @@ -2843,27 +3024,28 @@ proto.hasFormat = function ( tag, attributes, range ) { // If the common ancestor is inside the tag we require, we definitely // have the format. - var root = range.commonAncestorContainer, - walker, node; - if ( getNearest( root, tag, attributes ) ) { + var root = this._root; + var common = range.commonAncestorContainer; + var walker, node; + if ( getNearest( common, root, tag, attributes ) ) { return true; } // If common ancestor is a text node and doesn't have the format, we // definitely don't have it. - if ( root.nodeType === TEXT_NODE ) { + if ( common.nodeType === TEXT_NODE ) { return false; } // Otherwise, check each text node at least partially contained within // the selection and make sure all of them have the format we want. - walker = new TreeWalker( root, SHOW_TEXT, function ( node ) { + walker = new TreeWalker( common, SHOW_TEXT, function ( node ) { return isNodeContainedInRange( range, node, true ); }, false ); var seenNode = false; while ( node = walker.nextNode() ) { - if ( !getNearest( node, tag, attributes ) ) { + if ( !getNearest( node, root, tag, attributes ) ) { return false; } seenNode = true; @@ -2882,7 +3064,7 @@ proto.getFontInfo = function ( range ) { size: undefined }; var seenAttributes = 0; - var element, style; + var element, style, attr; if ( !range && !( range = this.getSelection() ) ) { return fontInfo; @@ -2893,37 +3075,41 @@ proto.getFontInfo = function ( range ) { if ( element.nodeType === TEXT_NODE ) { element = element.parentNode; } - while ( seenAttributes < 4 && element && ( style = element.style ) ) { - if ( !fontInfo.color ) { - fontInfo.color = style.color; - seenAttributes += 1; - } - if ( !fontInfo.backgroundColor ) { - fontInfo.backgroundColor = style.backgroundColor; - seenAttributes += 1; - } - if ( !fontInfo.family ) { - fontInfo.family = style.fontFamily; - seenAttributes += 1; - } - if ( !fontInfo.size ) { - fontInfo.size = style.fontSize; - seenAttributes += 1; + while ( seenAttributes < 4 && element ) { + if ( style = element.style ) { + if ( !fontInfo.color && ( attr = style.color ) ) { + fontInfo.color = attr; + seenAttributes += 1; + } + if ( !fontInfo.backgroundColor && + ( attr = style.backgroundColor ) ) { + fontInfo.backgroundColor = attr; + seenAttributes += 1; + } + if ( !fontInfo.family && ( attr = style.fontFamily ) ) { + fontInfo.family = attr; + seenAttributes += 1; + } + if ( !fontInfo.size && ( attr = style.fontSize ) ) { + fontInfo.size = attr; + seenAttributes += 1; + } } element = element.parentNode; } } return fontInfo; - }; +}; proto._addFormat = function ( tag, attributes, range ) { // If the range is collapsed we simply insert the node by wrapping // it round the range and focus it. + var root = this._root; var el, walker, startContainer, endContainer, startOffset, endOffset, node, needsFormat; if ( range.collapsed ) { - el = fixCursor( this.createElement( tag, attributes ) ); + el = fixCursor( this.createElement( tag, attributes ), root ); insertNodeInRange( range, el ); range.setStart( el.firstChild, el.firstChild.length ); range.collapse( true ); @@ -2976,7 +3162,7 @@ proto._addFormat = function ( tag, attributes, range ) { do { node = walker.currentNode; - needsFormat = !getNearest( node, tag, attributes ); + needsFormat = !getNearest( node, root, tag, attributes ); if ( needsFormat ) { //
can never be a container node, so must have a text node // if node == (end|start)Container @@ -3141,8 +3327,7 @@ proto.changeFormat = function ( add, remove, range, partial ) { } // Save undo checkpoint - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); + this.saveUndoState( range ); if ( remove ) { range = this._removeFormat( remove.tag.toUpperCase(), @@ -3175,7 +3360,7 @@ var tagAfterSplit = { var splitBlock = function ( self, block, node, offset ) { var splitTag = tagAfterSplit[ block.nodeName ], splitProperties = null, - nodeAfterSplit = split( node, offset, block.parentNode ), + nodeAfterSplit = split( node, offset, block.parentNode, self._root ), config = self._config; if ( !splitTag ) { @@ -3204,16 +3389,16 @@ proto.forEachBlock = function ( fn, mutates, range ) { // Save undo checkpoint if ( mutates ) { - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); + this.saveUndoState( range ); } - var start = getStartBlockOfRange( range ), - end = getEndBlockOfRange( range ); + var root = this._root; + var start = getStartBlockOfRange( range, root ); + var end = getEndBlockOfRange( range, root ); if ( start && end ) { do { if ( fn( start ) || start === end ) { break; } - } while ( start = getNextBlock( start ) ); + } while ( start = getNextBlock( start, root ) ); } if ( mutates ) { @@ -3242,23 +3427,24 @@ proto.modifyBlocks = function ( modify, range ) { this._recordUndoState( range ); } + var root = this._root; + var frag; + // 2. Expand range to block boundaries - expandRangeToBlockBoundaries( range ); + expandRangeToBlockBoundaries( range, root ); // 3. Remove range. - var body = this._body, - frag; - moveRangeBoundariesUpTree( range, body ); - frag = extractContentsOfRange( range, body ); + moveRangeBoundariesUpTree( range, root ); + frag = extractContentsOfRange( range, root, root ); // 4. Modify tree of fragment and reinsert. insertNodeInRange( range, modify.call( this, frag ) ); // 5. Merge containers at edges if ( range.endOffset < range.endContainer.childNodes.length ) { - mergeContainers( range.endContainer.childNodes[ range.endOffset ] ); + mergeContainers( range.endContainer.childNodes[ range.endOffset ], root ); } - mergeContainers( range.startContainer.childNodes[ range.startOffset ] ); + mergeContainers( range.startContainer.childNodes[ range.startOffset ], root ); // 6. Restore selection this._getRangeAndRemoveBookmark( range ); @@ -3281,9 +3467,10 @@ var increaseBlockQuoteLevel = function ( frag ) { }; var decreaseBlockQuoteLevel = function ( frag ) { + var root = this._root; var blockquotes = frag.querySelectorAll( 'blockquote' ); Array.prototype.filter.call( blockquotes, function ( el ) { - return !getNearest( el.parentNode, 'BLOCKQUOTE' ); + return !getNearest( el.parentNode, root, 'BLOCKQUOTE' ); }).forEach( function ( el ) { replaceWith( el, empty( el ) ); }); @@ -3304,7 +3491,7 @@ var removeBlockQuote = function (/* frag */) { }; var makeList = function ( self, frag, type ) { - var walker = getBlockWalker( frag ), + var walker = getBlockWalker( frag, self._root ), node, tag, prev, newLi, tagAttributes = self._config.tagAttributes, listAttrs = tagAttributes[ type.toLowerCase() ], @@ -3367,7 +3554,7 @@ var removeList = function ( frag ) { child = children[ll]; replaceWith( child, empty( child ) ); } - fixContainer( listFrag ); + fixContainer( listFrag, this._root ); replaceWith( list, listFrag ); } return frag; @@ -3403,6 +3590,7 @@ var increaseListLevel = function ( frag ) { }; var decreaseListLevel = function ( frag ) { + var root = this._root; var items = frag.querySelectorAll( 'LI' ); Array.prototype.filter.call( items, function ( el ) { return !isContainer( el.firstChild ); @@ -3413,7 +3601,7 @@ var decreaseListLevel = function ( frag ) { node = first, next; if ( item.previousSibling ) { - parent = split( parent, item, newParent ); + parent = split( parent, item, newParent, root ); } while ( node ) { next = node.nextSibling; @@ -3424,7 +3612,7 @@ var decreaseListLevel = function ( frag ) { node = next; } if ( newParent.nodeName === 'LI' && first.previousSibling ) { - split( newParent, first, newParent.parentNode ); + split( newParent, first, newParent.parentNode, root ); } while ( item !== frag && !item.childNodes.length ) { parent = item.parentNode; @@ -3432,16 +3620,16 @@ var decreaseListLevel = function ( frag ) { item = parent; } }, this ); - fixContainer( frag ); + fixContainer( frag, root ); return frag; }; proto._ensureBottomLine = function () { - var body = this._body, - last = body.lastElementChild; + var root = this._root; + var last = root.lastElementChild; if ( !last || last.nodeName !== this._config.blockTag || !isBlock( last ) ) { - body.appendChild( this.createDefaultBlock() ); + root.appendChild( this.createDefaultBlock() ); } }; @@ -3455,27 +3643,29 @@ proto.setKeyHandler = function ( key, fn ) { // --- Get/Set data --- proto._getHTML = function () { - return this._body.innerHTML; + return this._root.innerHTML; }; proto._setHTML = function ( html ) { - var node = this._body; + var root = this._root; + var node = root; node.innerHTML = html; do { - fixCursor( node ); - } while ( node = getNextBlock( node ) ); + fixCursor( node, root ); + } while ( node = getNextBlock( node, root ) ); this._ignoreChange = true; }; proto.getHTML = function ( withBookMark ) { var brs = [], - node, fixer, html, l, range; + root, node, fixer, html, l, range; if ( withBookMark && ( range = this.getSelection() ) ) { this._saveRangeToBookmark( range ); } if ( useTextFixer ) { - node = this._body; - while ( node = getNextBlock( node ) ) { + root = this._root; + node = root; + while ( node = getNextBlock( node, root ) ) { if ( !node.textContent && !node.querySelector( 'BR' ) ) { fixer = this.createElement( 'BR' ); node.appendChild( fixer ); @@ -3497,37 +3687,37 @@ proto.getHTML = function ( withBookMark ) { }; proto.setHTML = function ( html ) { - var frag = this._doc.createDocumentFragment(), - div = this.createElement( 'DIV' ), - child; + var frag = this._doc.createDocumentFragment(); + var div = this.createElement( 'DIV' ); + var root = this._root; + var child; // Parse HTML into DOM tree div.innerHTML = html; frag.appendChild( empty( div ) ); cleanTree( frag ); - cleanupBRs( frag ); + cleanupBRs( frag, root ); - fixContainer( frag ); + fixContainer( frag, root ); // Fix cursor var node = frag; - while ( node = getNextBlock( node ) ) { - fixCursor( node ); + while ( node = getNextBlock( node, root ) ) { + fixCursor( node, root ); } // Don't fire an input event this._ignoreChange = true; - // Remove existing body children - var body = this._body; - while ( child = body.lastChild ) { - body.removeChild( child ); + // Remove existing root children + while ( child = root.lastChild ) { + root.removeChild( child ); } // And insert new content - body.appendChild( frag ); - fixCursor( body ); + root.appendChild( frag ); + fixCursor( root, root ); // Reset the undo stack this._undoIndex = -1; @@ -3537,18 +3727,13 @@ proto.setHTML = function ( html ) { // Record undo state var range = this._getRangeAndRemoveBookmark() || - this._createRange( body.firstChild, 0 ); - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); + this._createRange( root.firstChild, 0 ); + this.saveUndoState( range ); // IE will also set focus when selecting text so don't use // setSelection. Instead, just store it in lastSelection, so if // anything calls getSelection before first focus, we have a range // to return. - if ( losesSelectionOnBlur ) { - this._lastSelection = range; - } else { - this.setSelection( range ); - } + this._lastSelection = range; this._updatePath( range, true ); return this; @@ -3562,25 +3747,25 @@ proto.insertElement = function ( el, range ) { range.setStartAfter( el ); } else { // Get containing block node. - var body = this._body, - splitNode = getStartBlockOfRange( range ) || body, - parent, nodeAfterSplit; + var root = this._root; + var splitNode = getStartBlockOfRange( range, root ) || root; + var parent, nodeAfterSplit; // While at end of container node, move up DOM tree. - while ( splitNode !== body && !splitNode.nextSibling ) { + while ( splitNode !== root && !splitNode.nextSibling ) { splitNode = splitNode.parentNode; } - // If in the middle of a container node, split up to body. - if ( splitNode !== body ) { + // If in the middle of a container node, split up to root. + if ( splitNode !== root ) { parent = splitNode.parentNode; - nodeAfterSplit = split( parent, splitNode.nextSibling, body ); + nodeAfterSplit = split( parent, splitNode.nextSibling, root, root ); } if ( nodeAfterSplit ) { - body.insertBefore( el, nodeAfterSplit ); + root.insertBefore( el, nodeAfterSplit ); } else { - body.appendChild( el ); + root.appendChild( el ); // Insert blank line below block. nodeAfterSplit = this.createDefaultBlock(); - body.appendChild( nodeAfterSplit ); + root.appendChild( nodeAfterSplit ); } range.setStart( nodeAfterSplit, 0 ); range.setEnd( nodeAfterSplit, 0 ); @@ -3589,6 +3774,11 @@ proto.insertElement = function ( el, range ) { this.focus(); this.setSelection( range ); this._updatePath( range ); + + if ( !canObserveMutations ) { + this._docWasChanged(); + } + return this; }; @@ -3602,12 +3792,13 @@ proto.insertImage = function ( src, attributes ) { var linkRegExp = /\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i; -var addLinks = function ( frag ) { +var addLinks = function ( frag, root, self ) { var doc = frag.ownerDocument, walker = new TreeWalker( frag, SHOW_TEXT, function ( node ) { - return !getNearest( node, 'A' ); + return !getNearest( node, root, 'A' ); }, false ), + defaultAttributes = self._config.tagAttributes.a, node, data, parent, match, index, endIndex, child; while ( node = walker.nextNode() ) { data = node.data; @@ -3619,13 +3810,14 @@ var addLinks = function ( frag ) { child = doc.createTextNode( data.slice( 0, index ) ); parent.insertBefore( child, node ); } - child = doc.createElement( 'A' ); + child = self.createElement( 'A', mergeObjects({ + href: match[1] ? + /^(?:ht|f)tps?:/.test( match[1] ) ? + match[1] : + 'http://' + match[1] : + 'mailto:' + match[2] + }, defaultAttributes )); child.textContent = data.slice( index, endIndex ); - child.href = match[1] ? - /^(?:ht|f)tps?:/.test( match[1] ) ? - match[1] : - 'http://' + match[1] : - 'mailto:' + match[2]; parent.insertBefore( child, node ); node.data = data = data.slice( endIndex ); } @@ -3645,10 +3837,10 @@ proto.insertHTML = function ( html, isPaste ) { frag.appendChild( empty( div ) ); // Record undo checkpoint - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); + this.saveUndoState( range ); try { + var root = this._root; var node = frag; var event = { fragment: frag, @@ -3658,14 +3850,14 @@ proto.insertHTML = function ( html, isPaste ) { defaultPrevented: false }; - addLinks( frag ); + addLinks( frag, frag, this ); cleanTree( frag ); - cleanupBRs( frag ); + cleanupBRs( frag, null ); removeEmptyInlines( frag ); frag.normalize(); - while ( node = getNextBlock( node ) ) { - fixCursor( node ); + while ( node = getNextBlock( node, frag ) ) { + fixCursor( node, null ); } if ( isPaste ) { @@ -3673,7 +3865,7 @@ proto.insertHTML = function ( html, isPaste ) { } if ( !event.defaultPrevented ) { - insertTreeFragmentIntoRange( range, event.fragment ); + insertTreeFragmentIntoRange( range, event.fragment, root ); if ( !canObserveMutations ) { this._docWasChanged(); } @@ -3689,18 +3881,35 @@ proto.insertHTML = function ( html, isPaste ) { return this; }; +var escapeHTMLFragement = function ( text ) { + return text.split( '&' ).join( '&' ) + .split( '<' ).join( '<' ) + .split( '>' ).join( '>' ) + .split( '"' ).join( '"' ); +}; + proto.insertPlainText = function ( plainText, isPaste ) { - var lines = plainText.split( '\n' ), - i, l, line; + var lines = plainText.split( '\n' ); + var config = this._config; + var tag = config.blockTag; + var attributes = config.blockAttributes; + var closeBlock = ''; + var openBlock = '<' + tag; + var attr, i, l, line; + + for ( attr in attributes ) { + openBlock += ' ' + attr + '="' + + escapeHTMLFragement( attributes[ attr ] ) + + '"'; + } + openBlock += '>'; + for ( i = 0, l = lines.length; i < l; i += 1 ) { line = lines[i]; - line = line.split( '&' ).join( '&' ) - .split( '<' ).join( '<' ) - .split( '>' ).join( '>' ) - .replace( / (?= )/g, ' ' ); + line = escapeHTMLFragement( line ).replace( / (?= )/g, ' ' ); // Wrap all but first/last lines in
if ( i && i + 1 < l ) { - line = '
' + ( line || '
' ) + '
'; + line = openBlock + ( line || '
' ) + closeBlock; } lines[i] = line; } @@ -3758,6 +3967,7 @@ proto.makeLink = function ( url, attributes ) { if ( !attributes ) { attributes = {}; } + mergeObjects( attributes, this._config.tagAttributes.a ); attributes.href = url; this.changeFormat({ @@ -3878,28 +4088,27 @@ proto.removeAllFormatting = function ( range ) { return this; } + var root = this._root; var stopNode = range.commonAncestorContainer; while ( stopNode && !isBlock( stopNode ) ) { stopNode = stopNode.parentNode; } if ( !stopNode ) { - expandRangeToBlockBoundaries( range ); - stopNode = this._body; + expandRangeToBlockBoundaries( range, root ); + stopNode = root; } if ( stopNode.nodeType === TEXT_NODE ) { return this; } // Record undo point - this._recordUndoState( range ); - this._getRangeAndRemoveBookmark( range ); - + this.saveUndoState( range ); // Avoid splitting where we're already at edges. moveRangeBoundariesUpTree( range, stopNode ); // Split the selection up to the block, or if whole selection in same - // block, expand range boundaries to ends of block and split up to body. + // block, expand range boundaries to ends of block and split up to root. var doc = stopNode.ownerDocument; var startContainer = range.startContainer; var startOffset = range.startOffset; @@ -3910,8 +4119,8 @@ proto.removeAllFormatting = function ( range ) { // in same container. var formattedNodes = doc.createDocumentFragment(); var cleanNodes = doc.createDocumentFragment(); - var nodeAfterSplit = split( endContainer, endOffset, stopNode ); - var nodeInSplit = split( startContainer, startOffset, stopNode ); + var nodeAfterSplit = split( endContainer, endOffset, stopNode, root ); + var nodeInSplit = split( startContainer, startOffset, stopNode, root ); var nextNode, _range, childNodes; // Then replace contents in split with a cleaned version of the same: diff --git a/build/squire.js b/build/squire.js index cea2650..295bd6b 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e,t,n){if(e.nodeName!==t)return!1;for(var r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function i(e,t){return!a(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function a(e){return e.nodeType===L&&!!ot[e.nodeName]}function s(e){return rt.test(e.nodeName)}function d(e){var t=e.nodeType;return(t===L||t===D)&&!s(e)&&r(e.childNodes,s)}function l(e){var t=e.nodeType;return!(t!==L&&t!==D||s(e)||d(e))}function c(e){var t=e.ownerDocument,r=new n(t.body,I,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function p(e){var t,n,r,o,i,a=e.parentNode;return a&&e.nodeType===L?(t=p(a),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),t+=".",t+=o.join(".")),(i=e.dir)&&(t+="[dir="+i+"]")):t=a?p(a):"",t}function g(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function m(e){var t=e.parentNode;return t&&t.removeChild(e),e}function v(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function S(e){var t,n,r=e.ownerDocument,o=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=k(r).createDefaultBlock(),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;$&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;n||($?(t=r.createTextNode(H),k(r)._didAddZWS()):t=r.createTextNode(""))}else if(Y){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=N(r,"BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null,c=k(a)._config;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=N(a,c.blockTag,c.blockAttributes)),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=N(a,c.blockTag,c.blockAttributes)),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(S(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),m(n),n.nodeType===R?r.appendData(n.data):l.push(C(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());T(n,t)}}function b(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;m(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(C(t)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),V&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=N(a,"DIV"),n.appendChild(C(r)),r.appendChild(n)}m(e),t=!l(e),r.appendChild(C(e)),t&&_(r),o&&E(o)}else s&&(r=N(a,"DIV"),e.insertBefore(r,o),S(r))}function k(e){for(var t,n=Ht.length;n--;)if(t=Ht[n],t._doc===e)return t;return null}function B(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?B(e[n],r):r;return e}function O(e,t){var n,r=e.defaultView,o=e.body;this._win=r,this._doc=e,this._body=o,this._events={},this._lastSelection=null,X&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent),r.addEventListener("focus",this,!1),r.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,J?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(o,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(G?"beforecut":"cut",Ft),this.addEventListener(G?"beforepaste":"paste",Mt),this.addEventListener(V?"keypress":"keydown",_t),this._keyHandlers=Object.create(Et),this.setConfig(t),G&&(r.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t}),o.setAttribute("contenteditable","true");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}Ht.push(this),this.setHTML("")}function x(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,s(r)){if(r.nodeType===R||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(d(r)){n.appendChild(e.createDefaultBlock([x(e,r,e._doc.createDocumentFragment())]));continue}x(e,r,n)}return n}var A=2,L=1,R=3,D=11,I=1,U=4,P=0,w=1,F=2,M=3,H="​",W=e.defaultView,z=navigator.userAgent,K=/iP(?:ad|hone|od)/.test(z),Z=/Mac OS X/.test(z),q=/Gecko\//.test(z),G=/Trident\/[456]\./.test(z),V=!!W.opera,j=/WebKit\//.test(z),Q=Z?"meta-":"ctrl-",Y=G||V,$=G||j,X=G,J="undefined"!=typeof MutationObserver,et=/[^ \t\r\n]/,tt=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var nt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(nt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(nt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(nt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var rt=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,ot={BR:1,IMG:1,INPUT:1},it=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},at=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(w,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(F,r)>-1;return a&&s},ht=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ut=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=tt.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=tt.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},pt=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=it(n,e.startOffset),t=h(t)),t&&ft(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=at(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&&ft(e,t,!0)?t:null},mt=new n(null,U|I,function(e){return e.nodeType===R?et.test(e.data):"IMG"===e.nodeName}),vt=function(e){var t=e.startContainer,n=e.startOffset;if(mt.root=null,t.nodeType===R){if(n)return!1;mt.currentNode=t}else mt.currentNode=at(t,n);return mt.root=pt(e),!mt.previousNode()},Ct=function(e){var t,n=e.endContainer,r=e.endOffset;if(mt.root=null,n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;mt.currentNode=n}else mt.currentNode=it(n,r);return mt.root=gt(e),!mt.nextNode()},Nt=function(e){var t,n=pt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,tt.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,tt.call(t.childNodes,r)+1))},St={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},_t=function(e){var t=e.keyCode,n=St[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),V&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this._recordUndoState(o),this._getRangeAndRemoveBookmark(o),lt(o),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},yt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Tt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},bt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===R&&(r=r.parentNode),n=r;s(n)&&(!n.textContent||n.textContent===H);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,tt.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),d(n)||(n=f(n)),S(n),ht(t)),"BODY"===r.nodeName&&(r=r.firstChild)&&"BR"===r.nodeName&&m(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},Et={enter:function(e,t,n){var r,o,i;if(t.preventDefault(),e._recordUndoState(n),on(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||lt(n),r=pt(n),!r||/^T[HD]$/.test(r.nodeName))return st(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,"LI"))&&(r=o),!r.textContent){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(nn,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Yt,n)}for(i=Vt(e,r,n.startContainer,n.startOffset),Kt(r),It(r),S(r);i.nodeType===L;){var a,s=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===H)){s=e._doc.createTextNode(""),v(i,s),i=s;break}for(;s&&s.nodeType===R&&!s.data&&(a=s.nextSibling,a&&"BR"!==a.nodeName);)m(s),s=a;if(!s||"BR"===s.nodeName||s.nodeType===R&&!V)break;i=s}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(vt(n)){t.preventDefault();var r=pt(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void m(o);for(b(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(nn,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Qt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){bt(e)},0);else t.preventDefault(),lt(n),bt(e,n)},"delete":function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(Ct(n)){t.preventDefault();var r=pt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void m(o);for(b(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i,a,s,d=n.cloneRange();if(ut(n,e._body),i=n.endContainer,a=n.endOffset,i.nodeType===L&&(s=i.childNodes[a],s&&"IMG"===s.nodeName))return t.preventDefault(),m(s),ht(n),void bt(e,n);e.setSelection(d),setTimeout(function(){bt(e)},0)}else t.preventDefault(),lt(n),bt(e,n)},tab:function(e,t,n){var r,o;if(e._removeZWS(),n.collapsed&&vt(n))for(r=pt(n);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(tn,n));break}r=o}},"shift-tab":function(e,t,n){if(e._removeZWS(),n.collapsed&&vt(n)){var r=n.startContainer;(u(r,"UL")||u(r,"OL"))&&(t.preventDefault(),e.modifyBlocks(nn,n))}},space:function(e,t,n){var r,o;e._recordUndoState(n),on(n.startContainer),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===g(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};Z&&q&&W.getSelection().modify&&(Et["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Et["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Z||(Et.pageup=function(e){e.moveCursorToStart()},Et.pagedown=function(e){e.moveCursorToEnd()}),Et[Q+"b"]=Tt("B"),Et[Q+"i"]=Tt("I"),Et[Q+"u"]=Tt("U"),Et[Q+"shift-7"]=Tt("S"),Et[Q+"shift-5"]=Tt("SUB",{tag:"SUP"}),Et[Q+"shift-6"]=Tt("SUP",{tag:"SUB"}),Et[Q+"shift-8"]=yt("makeUnorderedList"),Et[Q+"shift-9"]=yt("makeOrderedList"),Et[Q+"["]=yt("decreaseQuoteLevel"),Et[Q+"]"]=yt("increaseQuoteLevel"),Et[Q+"y"]=yt("redo"),Et[Q+"z"]=yt("undo"),Et[Q+"shift-z"]=yt("redo");var kt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Bt={backgroundColor:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ot=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},xt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Bt)r=Bt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Ot("B"),EM:Ot("I"),STRIKE:Ot("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+kt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},At=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,Lt=/^(?:HEAD|META|STYLE)/,Rt=new n(null,U|I,function(){return!0}),Dt=function sn(e){var t,n,r,o,i,a,d,l,c,f,h,u,p=e.childNodes;for(t=e;s(t);)t=t.parentNode;for(Rt.root=t,n=0,r=p.length;r>n;n+=1)if(o=p[n],i=o.nodeName,a=o.nodeType,d=xt[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(Lt.test(i)){e.removeChild(o),n-=1,r-=1;continue}if(!At.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}}l&&sn(o)}else{if(a===R){if(h=o.data,c=!et.test(h.charAt(0)),f=!et.test(h.charAt(h.length-1)),!c&&!f)continue;if(c){for(Rt.currentNode=o;(u=Rt.previousPONode())&&(i=u.nodeName,!("IMG"===i||"#text"===i&&/\S/.test(u.data)));)if(!s(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(f){for(Rt.currentNode=o;(u=Rt.nextNode())&&!("IMG"===i||"#text"===i&&/\S/.test(u.data));)if(!s(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(h){o.data=h;continue}}e.removeChild(o),n-=1,r-=1}return e},It=function dn(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==L||a(t)?t.nodeType!==R||t.data||e.removeChild(t):(dn(t),s(t)&&!t.firstChild&&e.removeChild(t))},Ut=function(e){return e.nodeType===L?"BR"===e.nodeName:et.test(e.data)},Pt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,I|U,Ut),t.currentNode=e,!!t.nextNode()},wt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Pt(o[t]);for(;a--;)n=o[a],r=n.parentNode,r&&(i[a]?s(r)||_(r):m(n))},Ft=function(){var e=this.getSelection(),t=this;this._recordUndoState(e),this._getRangeAndRemoveBookmark(e),this.setSelection(e),setTimeout(function(){try{t._ensureBottomLine()}catch(e){t.didError(e)}},0)},Mt=function(e){var t,n,r,o,i=e.clipboardData,a=i&&i.items,s=!1,d=!1,l=null,c=this;if(a){for(e.preventDefault(),t=a.length;t--;){if(n=a[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){c.insertHTML(e,!0)});"text/plain"===r&&(l=n),/^image\/.*/.test(r)&&(d=!0)}return void(d?(this.fireEvent("dragover",{dataTransfer:i,preventDefault:function(){s=!0}}),s&&this.fireEvent("drop",{dataTransfer:i})):l&&n.getAsString(function(e){c.insertPlainText(e,!0)}))}if(i&&(tt.call(i.types,"text/html")>-1||tt.call(i.types,"text/plain")>-1&&tt.call(i.types,"text/rtf")<0))return e.preventDefault(),void((o=i.getData("text/html"))?this.insertHTML(o,!0):(o=i.getData("text/plain"))&&this.insertPlainText(o,!0));this._awaitingPaste=!0;var f=this._body,h=this.getSelection(),u=h.startContainer,p=h.startOffset,g=h.endContainer,v=h.endOffset,C=pt(h),N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(f.scrollTop+(C?C.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});f.appendChild(N),h.selectNodeContents(N),this.setSelection(h),setTimeout(function(){try{c._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,m(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=c._createRange(u,p,g,v),c.setSelection(t),n&&c.insertHTML(n,!0)}catch(o){c.didError(o)}},0)},Ht=[],Wt=O.prototype;Wt.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Wt.createElement=function(e,t,n){return N(this._doc,e,t,n)},Wt.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e))},Wt.didError=function(e){console.log(e)},Wt.getDocument=function(){return this._doc};var zt={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Wt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Wt.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)zt[e]||n.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var o=Ht.length;o--;)Ht[o]===this&&Ht.splice(o,1)},Wt.handleEvent=function(e){this.fireEvent(e.type,e)},Wt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],zt[e]||this._doc.addEventListener(e,this,!0)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Wt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],zt[e]||this._doc.removeEventListener(e,this,!1))}return this},Wt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Wt.scrollRangeIntoView=function(e){var t,n,r=this._win,o=e.getBoundingClientRect().top,i=r.innerHeight;o||(t=this._doc.createElement("SPAN"),e=e.cloneRange(),st(e,t),o=t.getBoundingClientRect().top,n=t.parentNode,n.removeChild(t),n.normalize()),o>i&&r.scrollBy(0,o-i+20)},Wt._moveCursorTo=function(e){var t=this._body,n=this._createRange(t,e?0:t.childNodes.length);return ht(n),this.setSelection(n),this},Wt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Wt.moveCursorToEnd=function(){return this._moveCursorTo(!1)},Wt.setSelection=function(e){if(e){K&&this._win.focus();var t=this._getWindowSelection();t&&(t.removeAllRanges(),t.addRange(e),this.scrollRangeIntoView(e))}return this},Wt._getWindowSelection=function(){return this._win.getSelection()||null},Wt.getSelection=function(){var e,t,n,r=this._getWindowSelection();return r&&r.rangeCount?(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n),this._lastSelection=e):e=this._lastSelection,e||(e=this._createRange(this._body.firstChild,0)),e},Wt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,U|I,function(e){return ft(t,e,!0)}),o=t.startContainer,i=t.endContainer,a=r.currentNode=o,d="",l=!1;for(r.filter(a)||(a=r.nextNode());a;)a.nodeType===R?(e=a.data,e&&/\S/.test(e)&&(a===i&&(e=e.slice(0,t.endOffset)),a===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===a.nodeName||l&&!s(a))&&(d+="\n",l=!1),a=r.nextNode();return d},Wt.getPath=function(){return this._path};var Kt=function(e){for(var t,r,o,i=new n(e,U,function(){return!0},!1);r=i.nextNode();)for(;(o=r.data.indexOf(H))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,i.currentNode=t;while(s(r)&&!g(r));break}r.deleteData(o,1)}};Wt._didAddZWS=function(){this._hasZWS=!0},Wt._removeZWS=function(){this._hasZWS&&(Kt(this._body),this._hasZWS=!1)},Wt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Wt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Wt.focus=function(){return V||this._body.focus(),this._win.focus(),this},Wt.blur=function(){return q&&this._body.blur(),top.focus(),this};var Zt="squire-selection-start",qt="squire-selection-end";Wt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Zt,type:"hidden"}),r=this.createElement("INPUT",{id:qt,type:"hidden"});st(e,n),e.collapse(!1),st(e,r),n.compareDocumentPosition(r)&A&&(n.id=qt,r.id=Zt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Wt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Zt),r=t.getElementById(qt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:tt.call(i.childNodes,n),endOffset:tt.call(a.childNodes,r)};i===a&&(s.endOffset-=1),m(n),m(r),T(i,s),i!==a&&T(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ht(e),o&&e.collapse(!0)}return e||null},Wt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Wt._docWasChanged=function(){return J&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},Wt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},Wt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===R&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===R&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,U,function(e){return ft(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Wt.getFontInfo=function(e){var n,r,o={color:t,backgroundColor:t,family:t,size:t},i=0;if(!e&&!(e=this.getSelection()))return o;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===R)for(n.nodeType===R&&(n=n.parentNode);4>i&&n&&(r=n.style);)o.color||(o.color=r.color,i+=1),o.backgroundColor||(o.backgroundColor=r.backgroundColor,i+=1),o.family||(o.family=r.fontFamily,i+=1),o.size||(o.size=r.fontSize,i+=1),n=n.parentNode;return o},Wt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),st(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,U|I,function(e){return(e.nodeType===R||"BR"===e.nodeName||"IMG"===e.nodeName)&&ft(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;do c=i.currentNode,f=!u(c,e,t),f&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(c.nodeType===R?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l)}return r},Wt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&($?(i=a.createTextNode(H),this._didAddZWS()):i=a.createTextNode(""),st(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ft(n,e,!1)){var r,o,i=e.nodeType===R;if(!ft(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},g=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ft(n,r,!0)&&o(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),g.forEach(function(e){v(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return T(d,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},Wt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),J||this._docWasChanged(),this):void 0};var Gt={DT:"DD",DD:"DT",LI:"LI"},Vt=function(e,t,n,r){var i=Gt[t.nodeName],a=null,s=y(n,r,t.parentNode),d=e._config;return i||(i=d.blockTag,a=d.blockAttributes),o(s,i,a)||(t=N(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(C(s)),s=t),s};Wt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=pt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),J||this._docWasChanged()),this},Wt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Nt(t);var n,r=this._body;return ut(t,r),n=dt(t,r),st(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=C(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,C(s));_(i),v(o,i)}return e},tn=function(e){var t,n,r,o,i,a,s=e.querySelectorAll("LI"),d=this._config.tagAttributes,c=d.li;for(t=0,n=s.length;n>t;t+=1)r=s[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=d[o.toLowerCase()],v(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},nn=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e};Wt._ensureBottomLine=function(){var e=this._body,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&d(t)||e.appendChild(this.createDefaultBlock())},Wt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Wt._getHTML=function(){return this._body.innerHTML},Wt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t));this._ignoreChange=!0},Wt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),Y)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),Y)for(o=a.length;o--;)m(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Wt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(C(r)),Dt(n),wt(n),_(n);for(var o=n;o=h(o);)S(o);this._ignoreChange=!0;for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(i),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(i.firstChild,0);return this._recordUndoState(a),this._getRangeAndRemoveBookmark(a),X?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Wt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))st(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=pt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=y(n,i.nextSibling,o)),r?o.insertBefore(e,r):(o.appendChild(e),r=this.createDefaultBlock(),o.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),ht(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this},Wt.insertImage=function(e,t){var n=this.createElement("IMG",B({src:e},t));return this.insertElement(n),n};var rn=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,on=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,U,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=rn.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)};Wt.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(C(o)),this._recordUndoState(n),this._getRangeAndRemoveBookmark(n);try{var i=r,a={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(on(r),Dt(r),wt(r),It(r),r.normalize();i=h(i);)S(i);t&&this.fireEvent("willPaste",a),a.defaultPrevented||(ct(n,a.fragment),J||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(s){this.didError(s)}return this},Wt.insertPlainText=function(e,t){var n,r,o,i=e.split("\n");for(n=0,r=i.length;r>n;n+=1)o=i[n],o=o.split("&").join("&").split("<").join("<").split(">").join(">").replace(/ (?= )/g," "),n&&r>n+1&&(o="
"+(o||"
")+"
"),i[n]=o;return this.insertHTML(i.join(""),t)};var an=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Wt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},Wt.bold=an("changeFormat",{tag:"B"}),Wt.italic=an("changeFormat",{tag:"I"}),Wt.underline=an("changeFormat",{tag:"U"}),Wt.strikethrough=an("changeFormat",{tag:"S"}),Wt.subscript=an("changeFormat",{tag:"SUB"},{tag:"SUP"}),Wt.superscript=an("changeFormat",{tag:"SUP"},{tag:"SUB"}),Wt.removeBold=an("changeFormat",null,{tag:"B"}),Wt.removeItalic=an("changeFormat",null,{tag:"I"}),Wt.removeUnderline=an("changeFormat",null,{tag:"U"}),Wt.removeStrikethrough=an("changeFormat",null,{tag:"S"}),Wt.removeSubscript=an("changeFormat",null,{tag:"SUB"}),Wt.removeSuperscript=an("changeFormat",null,{tag:"SUP"}),Wt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;st(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Wt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Wt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Wt.setFontSize=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},Wt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Wt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Wt.setTextAlignment=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),this.focus()},Wt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},Wt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=e.commonAncestorContainer;t&&!d(t);)t=t.parentNode;if(t||(Nt(e),t=this._body),t.nodeType===R)return this;this._recordUndoState(e),this._getRangeAndRemoveBookmark(e),ut(e,t);for(var n,r,o,i=t.ownerDocument,a=e.startContainer,s=e.startOffset,l=e.endContainer,c=e.endOffset,f=i.createDocumentFragment(),h=i.createDocumentFragment(),u=y(l,c,t),p=y(a,s,t);p!==u;)n=p.nextSibling,f.appendChild(p),p=n;return x(this,f,h),h.normalize(),p=h.firstChild,n=h.lastChild,o=t.childNodes,p?(t.insertBefore(h,u),s=tt.call(o,p),c=tt.call(o,n)+1):(s=tt.call(o,u),c=s),r={startContainer:t,startOffset:s,endContainer:t,endOffset:c},T(t,r),e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),ht(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Wt.increaseQuoteLevel=an("modifyBlocks",jt),Wt.decreaseQuoteLevel=an("modifyBlocks",Qt),Wt.makeUnorderedList=an("modifyBlocks",Xt),Wt.makeOrderedList=an("modifyBlocks",Jt),Wt.removeList=an("modifyBlocks",en),Wt.increaseListLevel=an("modifyBlocks",tn),Wt.decreaseListLevel=an("modifyBlocks",nn),"object"==typeof exports?module.exports=O:"function"==typeof define&&define.amd?define(function(){return O}):(W.Squire=O,top!==W&&"true"===e.documentElement.getAttribute("data-squireinit")&&(W.editor=new O(e),W.onEditorLoad&&(W.onEditorLoad(W.editor),W.onEditorLoad=null)))}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(e){return e.nodeType===P&&!!ct[e.nodeName]}function i(e){return lt.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===P||t===F)&&!i(e)&&r(e.childNodes,i)}function s(e){var t=e.nodeType;return!(t!==P&&t!==F||i(e)||a(e))}function d(e,t){var r=new n(t,M,a);return r.currentNode=e,r}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function h(e,t){return!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&"A"!==e.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function f(e,t,n){if(e.nodeName!==t)return!1;for(var r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function u(e,t,n,r){for(;e&&e!==t;){if(f(e,n,r))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,r,o,i,a="";return e&&e!==t&&(a=g(e.parentNode,t),e.nodeType===P&&(a+=(a?">":"")+e.nodeName,(n=e.id)&&(a+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),a+=".",a+=o.join(".")),(i=e.dir)&&(a+="[dir="+i+"]"))),a}function m(e){var t=e.nodeType;return t===P?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function _(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=k(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),e.nodeType===I)return s;if(i(e)){for(r=e.firstChild;rt&&r&&r.nodeType===I&&!r.data;)e.removeChild(r),r=e.firstChild;r||(rt?(n=a.createTextNode(Z),k(a)._didAddZWS()):n=a.createTextNode(""))}else if(nt){for(;e.nodeType!==I&&!o(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===I?/^ +$/.test(e.data)&&(e.data=""):o(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=S(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;if(n)try{e.appendChild(n)}catch(d){k(a).didError({name:"Squire: fixCursor – "+d,message:"Parent: "+e.nodeName+"/"+e.innerHTML+" appendChild: "+n.nodeName})}return s}function y(e,t){var n,r,o,a,d=e.childNodes,l=e.ownerDocument,c=null,h=k(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=S(l,h.blockTag,h.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=S(l,h.blockTag,h.blockAttributes)),_(c,t),a?e.replaceChild(c,o):(e.insertBefore(c,o),n+=1,r+=1),c=null),s(o)&&y(o,t);return c&&e.appendChild(_(c,t)),e}function T(e,t,n,r){var o,i,a,s=e.nodeType;if(s===I&&e!==n)return T(e.parentNode,e.splitText(t),n,r);if(s===P){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=m(r))),v(n),n.nodeType===I?r.appendData(n.data):d.push(N(n));else if(n.nodeType===P){for(o=d.length;o--;)n.appendChild(d.pop());b(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(N(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),X&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,o=e.previousSibling,i=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||i&&/^[OU]L$/.test(i.nodeName))if(o&&h(o,e)){if(!s(o)){if(!d)return;r=S(a,"DIV"),r.appendChild(N(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(N(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=S(a,"DIV"),e.insertBefore(o,i),_(o,t))}function k(e){for(var t,n=jt.length;n--;)if(t=jt[n],t._doc===e)return t;return null}function O(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?O(e[n],r):r;return e}function B(e,t){e.nodeType===w&&(e=e.body);var n,r=e.ownerDocument,o=r.defaultView;this._win=o,this._doc=r,this._root=e,this._events={},this._lastSelection=null,ot&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="","onselectionchange"in r?this.addEventListener("selectionchange",this._updatePathOnEvent):(this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent)),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,it?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._restoreSelection=!1,this.addEventListener("blur",L),this.addEventListener("input",A),this.addEventListener("mousedown",A),this.addEventListener("touchstart",A),this.addEventListener("focus",D),this._awaitingPaste=!1,this.addEventListener(Y?"beforecut":"cut",Kt),this.addEventListener("copy",Zt),this.addEventListener(Y?"beforepaste":"paste",Gt),this.addEventListener(X?"keypress":"keydown",kt),this._keyHandlers=Object.create(At),this.setConfig(t),Y&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}jt.push(this),this.setHTML("")}function L(){this._restoreSelection=!0}function A(){this._restoreSelection=!1}function D(){this._restoreSelection&&this.setSelection(this._lastSelection)}function R(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,i(r)){if(r.nodeType===I||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(a(r)){n.appendChild(e.createDefaultBlock([R(e,r,e._doc.createDocumentFragment())]));continue}R(e,r,n)}return n}var U=2,P=1,I=3,w=9,F=11,M=1,H=4,W=0,z=1,q=2,K=3,Z="​",G=e.defaultView,j=navigator.userAgent,Q=/iP(?:ad|hone|od)/.test(j),V=/Mac OS X/.test(j),$=/Gecko\//.test(j),Y=/Trident\/[456]\./.test(j),X=!!G.opera,J=/Edge\//.test(j),et=!J&&/WebKit\//.test(j),tt=V?"meta-":"ctrl-",nt=Y||X,rt=Y||et,ot=Y,it="undefined"!=typeof MutationObserver,at=/[^ \t\r\n]/,st=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var dt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(dt[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var lt=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,ct={BR:1,HR:1,IFRAME:1,IMG:1,INPUT:1},ht=function(e,t){for(var n=e.childNodes;t&&e.nodeType===P;)e=n[t-1],n=e.childNodes,t=n.length;return e},ft=function(e,t){if(e.nodeType===P){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(z,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(W,r)<1,s=e.compareBoundaryPoints(q,r)>-1;return a&&s},Ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;n.nodeType!==I&&(t=n.childNodes[r],t&&!o(t));)n=t,r=0;if(a)for(;i.nodeType!==I&&(t=i.childNodes[a-1],t&&!o(t));)i=t,a=m(i);else for(;i.nodeType!==I&&(t=i.firstChild,t&&!o(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(i,a))},Nt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=st.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=st.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},St=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=ht(r,e.startOffset),n=c(n,t)),n&&vt(e,n,!0)?n:null},_t=function(e,t){var n,r,o=e.endContainer;if(i(o))n=l(o,t);else if(a(o))n=o;else{if(n=ft(o,e.endOffset),!n)for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&vt(e,n,!0)?n:null},yt=new n(null,H|M,function(e){return e.nodeType===I?at.test(e.data):"IMG"===e.nodeName}),Tt=function(e,t){var n=e.startContainer,r=e.startOffset;if(yt.root=null,n.nodeType===I){if(r)return!1;yt.currentNode=n}else yt.currentNode=ft(n,r),yt.currentNode||(yt.currentNode=n);return yt.root=St(e,t),!yt.previousNode()},bt=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(yt.root=null,r.nodeType===I){if(n=r.data.length,n&&n>o)return!1;yt.currentNode=r}else yt.currentNode=ht(r,o);return yt.root=_t(e,t),!yt.nextNode()},Et=function(e,t){var n,r=St(e,t),o=_t(e,t);r&&o&&(n=r.parentNode,e.setStart(n,st.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,st.call(n.childNodes,o)+1))},xt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},kt=function(e){var t=e.keyCode,n=xt[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),X&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this.saveUndoState(o),gt(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Ot=function(e){return function(t,n){n.preventDefault(),t[e]()}},Bt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Lt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===I&&(r=r.parentNode),n=r;i(n)&&(!n.textContent||n.textContent===Z);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,st.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),_(n,e._root),Ct(t)),r===e._root&&(r=r.firstChild)&&"BR"===r.nodeName&&v(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},At={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),un(n.startContainer,a,e),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||gt(n,a),r=St(n,a),!r||/^T[HD]$/.test(r.nodeName))return ut(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,a,"LI"))&&(r=o),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(hn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(on,n)}for(i=tn(e,r,n.startContainer,n.startOffset),Yt(r),Ht(r),_(r,a);i.nodeType===P;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===Z)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===I&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===I&&!X)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var r=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Tt(n,r)){t.preventDefault();var o,i=St(n,r);if(!i)return;if(y(i.parentNode,r),o=l(i,r)){if(!o.isContentEditable)return void v(o);for(E(o,i,n),i=o.parentNode;i!==r&&!i.nextSibling;)i=i.parentNode;i!==r&&(i=i.nextSibling)&&x(i,r),e.setSelection(n)}else if(i){if(u(i,r,"UL")||u(i,r,"OL"))return e.modifyBlocks(hn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(rn,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Lt(e)},0);else t.preventDefault(),gt(n,r),Lt(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(bt(n,l)){if(t.preventDefault(),r=St(n,l),!r)return;if(y(r.parentNode,l),o=c(r,l)){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o!==l&&!o.nextSibling;)o=o.parentNode;o!==l&&(o=o.nextSibling)&&x(o,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),Nt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===P&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),Ct(n),void Lt(e,n);e.setSelection(i),setTimeout(function(){Lt(e)},0)}else t.preventDefault(),gt(n,l),Lt(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&Tt(n,i))for(r=St(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(cn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&Tt(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(hn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),un(n.startContainer,e._root,e),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&$&&(At["meta-left"]=function(e,t){t.preventDefault();var n=$t(e);n&&n.modify&&n.modify("move","backward","lineboundary")},At["meta-right"]=function(e,t){t.preventDefault();var n=$t(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),V||(At.pageup=function(e){e.moveCursorToStart()},At.pagedown=function(e){e.moveCursorToEnd()}),At[tt+"b"]=Bt("B"),At[tt+"i"]=Bt("I"),At[tt+"u"]=Bt("U"),At[tt+"shift-7"]=Bt("S"),At[tt+"shift-5"]=Bt("SUB",{tag:"SUP"}),At[tt+"shift-6"]=Bt("SUP",{tag:"SUB"}),At[tt+"shift-8"]=Ot("makeUnorderedList"),At[tt+"shift-9"]=Ot("makeOrderedList"),At[tt+"["]=Ot("decreaseQuoteLevel"),At[tt+"]"]=Ot("increaseQuoteLevel"),At[tt+"y"]=Ot("redo"),At[tt+"z"]=Ot("undo"),At[tt+"shift-z"]=Ot("redo");var Dt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Rt={backgroundColor:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:at,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ut=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Pt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Rt)r=Rt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ut("B"),EM:Ut("I"),STRIKE:Ut("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+Dt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},It=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,wt=/^(?:HEAD|META|STYLE)/,Ft=new n(null,H|M,function(){return!0}),Mt=function mn(e,t){var n,r,o,a,s,d,l,c,h,f,u,p,g=e.childNodes;for(n=e;i(n);)n=n.parentNode;for(Ft.root=n,r=0,o=g.length;o>r;r+=1)if(a=g[r],s=a.nodeName,d=a.nodeType,l=Pt[s],d===P){if(c=a.childNodes.length,l)a=l(a,e);else{if(wt.test(s)){e.removeChild(a),r-=1,o-=1;continue}if(!It.test(s)&&!i(a)){r-=1,o+=c-1,e.replaceChild(N(a),a);continue}}c&&mn(a,t||"PRE"===s)}else{if(d===I){if(u=a.data,h=!at.test(u.charAt(0)),f=!at.test(u.charAt(u.length-1)),t||!h&&!f)continue;if(h){for(Ft.currentNode=a;(p=Ft.previousPONode())&&(s=p.nodeName,!("IMG"===s||"#text"===s&&/\S/.test(p.data)));)if(!i(p)){p=null;break}u=u.replace(/^\s+/g,p?" ":"")}if(f){for(Ft.currentNode=a;(p=Ft.nextNode())&&!("IMG"===s||"#text"===s&&/\S/.test(p.data));)if(!i(p)){p=null;break}u=u.replace(/\s+$/g,p?" ":"")}if(u){a.data=u;continue}}e.removeChild(a),r-=1,o-=1}return e},Ht=function vn(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==P||o(t)?t.nodeType!==I||t.data||e.removeChild(t):(vn(t),i(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e){return e.nodeType===P?"BR"===e.nodeName:at.test(e.data)},zt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,M|H,Wt),t.currentNode=e,!!t.nextNode()},qt=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=zt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Kt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),J||Q||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(Nt(n,o),r.appendChild(gt(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},Zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");J||Q||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Gt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,h=this;if(!J&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){h.insertHTML(e,!0)});"text/plain"===r&&(c=n),/^image\/.*/.test(r)&&(l=!0)}return void(l?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){d=!0}}),d&&this.fireEvent("drop",{dataTransfer:a})):c&&n.getAsString(function(e){h.insertPlainText(e,!0)}))}if(o=a&&a.types,!J&&o&&(st.call(o,"text/html")>-1||!$&&st.call(o,"text/plain")>-1&&st.call(o,"text/rtf")<0))return e.preventDefault(),void((i=a.getData("text/html"))?this.insertHTML(i,!0):((i=a.getData("text/plain"))||(i=a.getData("text/uri-list")))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var f=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});f.appendChild(N),u.selectNodeContents(N),this.setSelection(u),setTimeout(function(){try{h._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,v(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=h._createRange(p,g,m,C),h.setSelection(t),n&&h.insertHTML(n,!0)}catch(o){h.didError(o)}},0)},jt=[],Qt=B.prototype;Qt.setConfig=function(e){return e=O({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null,a:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Qt.createElement=function(e,t,n){return S(this._doc,e,t,n)},Qt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Qt.didError=function(e){console.log(e)},Qt.getDocument=function(){return this._doc},Qt.getRoot=function(){return this._root},Qt.modifyDocument=function(e){this._ignoreAllChanges=!0,this._mutation&&this._mutation.disconnect(),e(),this._ignoreAllChanges=!1,this._mutation&&this._mutation.observe(this._root,{childList:!0,attributes:!0,characterData:!0,subtree:!0})};var Vt={pathChange:1,select:1,input:1,undoStateChange:1};Qt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Qt.destroy=function(){var e,t=jt.length,n=this._events;for(e in n)this.removeEventListener(e);for(this._mutation&&this._mutation.disconnect();t--;)jt[t]===this&&jt.splice(t,1)},Qt.handleEvent=function(e){this.fireEvent(e.type,e)},Qt.addEventListener=function(e,t){var n=this._events[e],r=this._root;return t?(n||(n=this._events[e]=[],Vt[e]||("selectionchange"===e&&(r=this._doc),r.addEventListener(e,this,!0))),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Qt.removeEventListener=function(e,t){var n,r=this._events[e],o=this._root;if(r){if(t)for(n=r.length;n--;)r[n]===t&&r.splice(n,1);else r.length=0;r.length||(delete this._events[e],Vt[e]||("selectionchange"===e&&(o=this._doc),o.removeEventListener(e,this,!0)))}return this},Qt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Qt.getCursorPosition=function(e){if(!e&&!(e=this.getSelection())||!e.getBoundingClientRect)return null;var t,n,r=e.getBoundingClientRect();return r&&!r.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=Z,ut(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),b(n,{startContainer:e.startContainer,endContainer:e.endContainer,startOffset:e.startOffset,endOffset:e.endOffset})),r},Qt._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return Ct(n),this.setSelection(n),this},Qt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Qt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var $t=function(e){return e._win.getSelection()||null};Qt.setSelection=function(e){if(e){this._restoreSelection=!1,this._lastSelection=e,Q&&this._win.focus();var t=$t(this);t&&(t.removeAllRanges(),t.addRange(e))}return this},Qt.getSelection=function(){var e,t,n,r=$t(this),i=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&p(i,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(i.firstChild,0)),e},Qt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,H|M,function(e){return vt(t,e,!0)}),o=t.startContainer,a=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===I?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!i(s))&&(d+="\n",l=!1),s=r.nextNode();return d},Qt.getPath=function(){return this._path};var Yt=function(e){for(var t,r,o,a=new n(e,H,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(Z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(i(r)&&!m(r));break}r.deleteData(o,1)}};Qt._didAddZWS=function(){this._hasZWS=!0},Qt._removeZWS=function(){this._hasZWS&&(Yt(this._root),this._hasZWS=!1)},Qt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?g(o,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Qt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Qt.focus=function(){return this._root.focus(),this},Qt.blur=function(){return this._root.blur(),this};var Xt="squire-selection-start",Jt="squire-selection-end";Qt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Xt,type:"hidden"}),r=this.createElement("INPUT",{id:Jt,type:"hidden"});ut(e,n),e.collapse(!1),ut(e,r),n.compareDocumentPosition(r)&U&&(n.id=Jt,r.id=Xt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Qt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+Xt),r=t.querySelector("#"+Jt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:st.call(i.childNodes,n),endOffset:st.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),b(i,s),i!==a&&b(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,o&&(i=e.startContainer,i.nodeType===I&&(a=i.childNodes[e.startOffset],a&&a.nodeType===I||(a=i.childNodes[e.startOffset-1]),a&&a.nodeType===I&&(e.setStart(a,0),e.collapse(!0))))}return e||null},Qt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Qt._docWasChanged=function(){if(!this._ignoreAllChanges){if(it&&this._ignoreChange)return void(this._ignoreChange=!1);this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}},Qt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},Qt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===I&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===I&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===I)return!1;o=new n(s,H,function(e){return vt(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},Qt.getFontInfo=function(e){var n,r,o,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===I)for(n.nodeType===I&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!i.color&&(o=r.color)&&(i.color=o,a+=1),!i.backgroundColor&&(o=r.backgroundColor)&&(i.backgroundColor=o,a+=1),!i.family&&(o=r.fontFamily)&&(i.family=o,a+=1),!i.size&&(o=r.fontSize)&&(i.size=o,a+=1)),n=n.parentNode;return i},Qt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,h,f=this._root;if(r.collapsed)o=_(this.createElement(e,t),f),ut(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,H|M,function(e){return(e.nodeType===I||"BR"===e.nodeName||"IMG"===e.nodeName)&&vt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;do c=i.currentNode,h=!u(c,f,e,t),h&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),o=this.createElement(e,t),C(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==I&&(c.nodeType===I?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l) +}return r},Qt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(rt?(o=a.createTextNode(Z),this._didAddZWS()):o=a.createTextNode(""),ut(n,o));for(var s=n.commonAncestorContainer;i(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!vt(n,e,!1)){var r,o,i=e.nodeType===I;if(!vt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===c&&h!==e.length&&u.push([t,e.splitText(h)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(r){return vt(n,r,!0)&&f(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return b(s,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},Qt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),it||this._docWasChanged(),this):void 0};var en={DT:"DD",DD:"DT",LI:"LI"},tn=function(e,t,n,r){var o=en[t.nodeName],i=null,a=T(n,r,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,i=s.blockAttributes),f(a,o,i)||(t=S(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};Qt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=St(n,r),i=_t(n,r);if(o&&i)do if(e(o)||o===i)break;while(o=c(o,r));return t&&(this.setSelection(n),this._updatePath(n,!0),it||this._docWasChanged()),this},Qt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,r=this._root;return Et(t,r),Nt(t,r),n=pt(t,r,r),ut(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],C(s,N(s));y(i,this._root),C(o,i)}return e},cn=function(e){var t,n,r,o,i,a,d=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=d.length;n>t;t+=1)r=d[t],s(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=l[o.toLowerCase()],C(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},hn=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!s(e.firstChild)}).forEach(function(n){var r,o=n.parentNode,i=o.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(o=T(o,n,i,t));d&&(r=d.nextSibling,!s(d));)i.insertBefore(d,o),d=r;for("LI"===i.nodeName&&a.previousSibling&&T(i,a,i.parentNode,t);n!==e&&!n.childNodes.length;)o=n.parentNode,o.removeChild(n),n=o},this),y(e,t),e};Qt._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},Qt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Qt._getHTML=function(){return this._root.innerHTML},Qt._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do _(n,t);while(n=c(n,t));this._ignoreChange=!0},Qt.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),nt)for(t=this._root,n=t;n=c(n,t);)n.textContent||n.querySelector("BR")||(r=this.createElement("BR"),n.appendChild(r),s.push(r));if(o=this._getHTML().replace(/\u200B/g,""),nt)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},Qt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(N(r)),Mt(n),qt(n,o),y(n,o);for(var i=n;i=c(i,o);)_(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),_(o,o),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(o.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,this._updatePath(a,!0),this},Qt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ut(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=St(t,o)||o;a!==o&&!a.nextSibling;)a=a.parentNode;a!==o&&(n=a.parentNode,r=T(n,a.nextSibling,o,o)),r?o.insertBefore(e,r):(o.appendChild(e),r=this.createDefaultBlock(),o.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),Ct(t)}return this.focus(),this.setSelection(t),this._updatePath(t),it||this._docWasChanged(),this},Qt.insertImage=function(e,t){var n=this.createElement("IMG",O({src:e},t));return this.insertElement(n),n};var fn=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,un=function(e,t,r){for(var o,i,a,s,d,l,c,h=e.ownerDocument,f=new n(e,H,function(e){return!u(e,t,"A")},!1),p=r._config.tagAttributes.a;o=f.nextNode();)for(i=o.data,a=o.parentNode;s=fn.exec(i);)d=s.index,l=d+s[0].length,d&&(c=h.createTextNode(i.slice(0,d)),a.insertBefore(c,o)),c=r.createElement("A",O({href:s[1]?/^(?:ht|f)tps?:/.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[2]},p)),c.textContent=i.slice(d,l),a.insertBefore(c,o),o.data=i=i.slice(l)};Qt.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(N(o)),this.saveUndoState(n);try{var i=this._root,a=r,s={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(un(r,r,this),Mt(r),qt(r,null),Ht(r),r.normalize();a=c(a,r);)_(a,null);t&&this.fireEvent("willPaste",s),s.defaultPrevented||(mt(n,s.fragment,i),it||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(d){this.didError(d)}return this};var pn=function(e){return e.split("&").join("&").split("<").join("<").split(">").join(">").split('"').join(""")};Qt.insertPlainText=function(e,t){var n,r,o,i,a=e.split("\n"),s=this._config,d=s.blockTag,l=s.blockAttributes,c="",h="<"+d;for(n in l)h+=" "+n+'="'+pn(l[n])+'"';for(h+=">",r=0,o=a.length;o>r;r+=1)i=a[r],i=pn(i).replace(/ (?= )/g," "),r&&o>r+1&&(i=h+(i||"
")+c),a[r]=i;return this.insertHTML(a.join(""),t)};var gn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Qt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},Qt.bold=gn("changeFormat",{tag:"B"}),Qt.italic=gn("changeFormat",{tag:"I"}),Qt.underline=gn("changeFormat",{tag:"U"}),Qt.strikethrough=gn("changeFormat",{tag:"S"}),Qt.subscript=gn("changeFormat",{tag:"SUB"},{tag:"SUP"}),Qt.superscript=gn("changeFormat",{tag:"SUP"},{tag:"SUB"}),Qt.removeBold=gn("changeFormat",null,{tag:"B"}),Qt.removeItalic=gn("changeFormat",null,{tag:"I"}),Qt.removeUnderline=gn("changeFormat",null,{tag:"U"}),Qt.removeStrikethrough=gn("changeFormat",null,{tag:"S"}),Qt.removeSubscript=gn("changeFormat",null,{tag:"SUB"}),Qt.removeSuperscript=gn("changeFormat",null,{tag:"SUP"}),Qt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ut(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),O(t,this._config.tagAttributes.a),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Qt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Qt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Qt.setFontSize=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},Qt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Qt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Qt.setTextAlignment=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),this.focus()},Qt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},Qt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!a(n);)n=n.parentNode;if(n||(Et(e,t),n=t),n.nodeType===I)return this;this.saveUndoState(e),Nt(e,n);for(var r,o,i,s=n.ownerDocument,d=e.startContainer,l=e.startOffset,c=e.endContainer,h=e.endOffset,f=s.createDocumentFragment(),u=s.createDocumentFragment(),p=T(c,h,n,t),g=T(d,l,n,t);g!==p;)r=g.nextSibling,f.appendChild(g),g=r;return R(this,f,u),u.normalize(),g=u.firstChild,r=u.lastChild,i=n.childNodes,g?(n.insertBefore(u,p),l=st.call(i,g),h=st.call(i,r)+1):(l=st.call(i,p),h=l),o={startContainer:n,startOffset:l,endContainer:n,endOffset:h},b(n,o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),Ct(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Qt.increaseQuoteLevel=gn("modifyBlocks",nn),Qt.decreaseQuoteLevel=gn("modifyBlocks",rn),Qt.makeUnorderedList=gn("modifyBlocks",sn),Qt.makeOrderedList=gn("modifyBlocks",dn),Qt.removeList=gn("modifyBlocks",ln),Qt.increaseListLevel=gn("modifyBlocks",cn),Qt.decreaseListLevel=gn("modifyBlocks",hn),"object"==typeof exports?module.exports=B:"function"==typeof define&&define.amd?define(function(){return B}):(G.Squire=B,top!==G&&"true"===e.documentElement.getAttribute("data-squireinit")&&(G.editor=new B(e),G.onEditorLoad&&(G.onEditorLoad(G.editor),G.onEditorLoad=null)))}(document); \ No newline at end of file