From a88e7018da9da7a9f7a38e428200ef0f6b6468fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gert=20K=2E=20S=C3=B8nderby?= Date: Mon, 28 Sep 2015 15:16:48 +0200 Subject: [PATCH] Made JSCS checking much, much stricter, brought code into line with checking. --- .jscsrc | 24 ++++- build/squire-raw.js | 219 ++++++++++++++++++++++---------------------- build/squire.js | 4 +- source/Clean.js | 32 +++---- source/Clipboard.js | 16 ++-- source/Editor.js | 134 +++++++++++++-------------- source/Node.js | 27 +++--- source/Range.js | 6 +- source/intro.js | 2 +- source/outro.js | 2 +- 10 files changed, 242 insertions(+), 224 deletions(-) diff --git a/.jscsrc b/.jscsrc index 891243e..a68e8bc 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,6 +1,22 @@ { - "disallowSpacesInsideParentheses": false, - "disallowSpacesInFunctionDeclaration": { - "beforeOpeningRoundBrace": false - } + "requireCamelCaseOrUpperCaseIdentifiers": true, + "requireCapitalizedConstructors": true, + "requireCurlyBraces": true, + "requireDotNotation": true, + "requireLineBreakAfterVariableAssignment": true, + "requireLineFeedAtFileEnd": true, + "requireSpaceAfterBinaryOperators": true, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBetweenArguments": true, + "requireSpaceBeforeKeywords": true, + "requireSpacesInConditionalExpression": true, + "requireSpacesInForStatement": true, + "requireSpacesInFunction": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInsideBrackets": true, + "requireSpacesInsideParentheses": "all", + "validateQuoteMarks": "'" } diff --git a/build/squire-raw.js b/build/squire-raw.js index c165eaf1..0b3d1bb 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2,7 +2,7 @@ ( function ( doc, undefined ) { -"use strict"; +'use strict'; var DOCUMENT_POSITION_PRECEDING = 2; // Node.DOCUMENT_POSITION_PRECEDING var ELEMENT_NODE = 1; // Node.ELEMENT_NODE; @@ -180,7 +180,7 @@ var leafNodeNames = { function every ( nodeList, fn ) { var l = nodeList.length; while ( l-- ) { - if ( !fn( nodeList[l] ) ) { + if ( !fn( nodeList[ l ] ) ) { return false; } } @@ -200,15 +200,6 @@ function hasTagAttributes ( node, tag, attributes ) { } 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 && @@ -228,6 +219,16 @@ function isContainer ( node ) { !isInline( node ) && !isBlock( node ); } +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 getBlockWalker ( node ) { var doc = node.ownerDocument, walker = new TreeWalker( @@ -321,7 +322,7 @@ function createElement ( doc, tag, props, children ) { } if ( children ) { for ( i = 0, l = children.length; i < l; i += 1 ) { - el.appendChild( children[i] ); + el.appendChild( children[ i ] ); } } return el; @@ -408,7 +409,7 @@ function fixContainer ( container ) { config = getSquireInstance( doc )._config; for ( i = 0, l = children.length; i < l; i += 1 ) { - child = children[i]; + child = children[ i ]; isBR = child.nodeName === 'BR'; if ( !isBR && isInline( child ) ) { if ( !wrapper ) { @@ -503,7 +504,7 @@ function mergeInlines ( node, range ) { frags = [], child, prev, len; while ( l-- ) { - child = children[l]; + child = children[ l ]; prev = l && children[ l - 1 ]; if ( l && isInline( child ) && areAlike( child, prev ) && !leafNodeNames[ child.nodeName ] ) { @@ -698,7 +699,7 @@ var insertNodeInRange = function ( range, node ) { childCount = children.length; - if ( startOffset === childCount) { + if ( startOffset === childCount ) { startContainer.appendChild( node ); } else { startContainer.insertBefore( node, children[ startOffset ] ); @@ -817,7 +818,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { children = frag.childNodes, l = children.length; while ( l-- ) { - if ( !isInline( children[l] ) ) { + if ( !isInline( children[ l ] ) ) { allInline = false; break; } @@ -1083,7 +1084,7 @@ var getEndBlockOfRange = function ( range ) { }; var contentWalker = new TreeWalker( null, - SHOW_TEXT|SHOW_ELEMENT, + SHOW_TEXT | SHOW_ELEMENT, function ( node ) { return node.nodeType === TEXT_NODE ? notWS.test( node.data ) : @@ -1633,7 +1634,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'highlight', style: 'background-color: ' + colour - }); + } ); } }, color: { @@ -1642,7 +1643,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'colour', style: 'color:' + colour - }); + } ); } }, fontWeight: { @@ -1663,7 +1664,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'font', style: 'font-family:' + family - }); + } ); } }, fontSize: { @@ -1672,7 +1673,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'size', style: 'font-size:' + size - }); + } ); } } }; @@ -1728,7 +1729,7 @@ var stylesRewriters = { fontSpan = createElement( doc, 'SPAN', { 'class': 'font', style: 'font-family:' + face - }); + } ); newTreeTop = fontSpan; newTreeBottom = fontSpan; } @@ -1736,7 +1737,7 @@ var stylesRewriters = { sizeSpan = createElement( doc, 'SPAN', { 'class': 'size', style: 'font-size:' + fontSizes[ size ] + 'px' - }); + } ); if ( !newTreeTop ) { newTreeTop = sizeSpan; } @@ -1752,7 +1753,7 @@ var stylesRewriters = { colourSpan = createElement( doc, 'SPAN', { 'class': 'colour', style: 'color:' + colour - }); + } ); if ( !newTreeTop ) { newTreeTop = colourSpan; } @@ -1772,7 +1773,7 @@ var stylesRewriters = { var el = createElement( node.ownerDocument, 'SPAN', { 'class': 'font', style: 'font-family:menlo,consolas,"courier new",monospace' - }); + } ); parent.replaceChild( el, node ); el.appendChild( empty( node ) ); return el; @@ -1783,9 +1784,9 @@ var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT var blacklist = /^(?:HEAD|META|STYLE)/; -var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () { +var walker = new TreeWalker( null, SHOW_TEXT | SHOW_ELEMENT, function () { return true; -}); +} ); /* Two purposes: @@ -1806,7 +1807,7 @@ var cleanTree = function cleanTree ( node ) { walker.root = nonInlineParent; for ( i = 0, l = children.length; i < l; i += 1 ) { - child = children[i]; + child = children[ i ]; nodeName = child.nodeName; nodeType = child.nodeType; rewriter = stylesRewriters[ nodeName ]; @@ -1893,7 +1894,7 @@ var removeEmptyInlines = function removeEmptyInlines ( root ) { l = children.length, child; while ( l-- ) { - child = children[l]; + child = children[ l ]; if ( child.nodeType === ELEMENT_NODE && !isLeaf( child ) ) { removeEmptyInlines( child ); if ( isInline( child ) && !child.firstChild ) { @@ -1919,7 +1920,7 @@ var isLineBreak = function ( br ) { block = block.parentNode; } walker = new TreeWalker( - block, SHOW_ELEMENT|SHOW_TEXT, notWSTextNode ); + block, SHOW_ELEMENT | SHOW_TEXT, notWSTextNode ); walker.currentNode = br; return !!walker.nextNode(); }; @@ -1942,10 +1943,10 @@ var cleanupBRs = function ( root ) { // therefore seem to not be a line break. But in its original context it // was, so we should also convert it to a block split. for ( i = 0; i < l; i += 1 ) { - brBreaksLine[i] = isLineBreak( brs[i] ); + brBreaksLine[ i ] = isLineBreak( brs[ i ] ); } while ( l-- ) { - br = brs[l]; + br = brs[ l ]; // Cleanup may have removed it parent = br.parentNode; if ( !parent ) { continue; } @@ -1953,7 +1954,7 @@ var cleanupBRs = function ( root ) { // anything useful. We'll add it back later if required by the // browser. If it breaks a line, wrap the content in div tags // and replace the brs. - if ( !brBreaksLine[l] ) { + if ( !brBreaksLine[ l ] ) { detach( br ); } else if ( !isInline( parent ) ) { fixContainer( parent ); @@ -1995,13 +1996,13 @@ var onPaste = function ( event ) { event.preventDefault(); l = items.length; while ( l-- ) { - item = items[l]; + item = items[ l ]; type = item.type; if ( type === 'text/html' ) { /*jshint loopfunc: true */ item.getAsString( function ( html ) { self.insertHTML( html, true ); - }); + } ); /*jshint loopfunc: false */ return; } @@ -2021,16 +2022,16 @@ var onPaste = function ( event ) { fireDrop = true; } /*jshint loopfunc: false */ - }); + } ); if ( fireDrop ) { this.fireEvent( 'drop', { dataTransfer: clipboardData - }); + } ); } } else if ( plainItem ) { item.getAsString( function ( text ) { self.insertPlainText( text, true ); - }); + } ); } return; } @@ -2050,9 +2051,9 @@ var onPaste = function ( event ) { // 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. - if (( data = clipboardData.getData( 'text/html' ) )) { + if ( ( data = clipboardData.getData( 'text/html' ) ) ) { this.insertHTML( data, true ); - } else if (( data = clipboardData.getData( 'text/plain' ) )) { + } else if ( ( data = clipboardData.getData( 'text/plain' ) ) ) { this.insertPlainText( data, true ); } return; @@ -2078,7 +2079,7 @@ var onPaste = function ( event ) { ( body.scrollTop + ( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) + 'px; right: 150%; width: 1px; height: 1px;' - }); + } ); body.appendChild( pasteArea ); range.selectNodeContents( pasteArea ); this.setSelection( range ); @@ -2130,7 +2131,7 @@ function getSquireInstance ( doc ) { var l = instances.length, instance; while ( l-- ) { - instance = instances[l]; + instance = instances[ l ]; if ( instance._doc === doc ) { return instance; } @@ -2197,7 +2198,7 @@ function Squire ( doc, config ) { attributes: true, characterData: true, subtree: true - }); + } ); this._mutation = mutation; } else { this.addEventListener( 'keyup', this._keyUpDetectChange ); @@ -2265,7 +2266,7 @@ function Squire ( doc, config ) { var proto = Squire.prototype; proto.setConfig = function ( config ) { - config = mergeObjects({ + config = mergeObjects( { blockTag: 'DIV', blockAttributes: null, tagAttributes: { @@ -2327,7 +2328,7 @@ proto.fireEvent = function ( type, event ) { handlers = handlers.slice(); l = handlers.length; while ( l-- ) { - obj = handlers[l]; + obj = handlers[ l ]; try { if ( obj.handleEvent ) { obj.handleEvent( event ); @@ -2360,7 +2361,7 @@ proto.destroy = function () { } var l = instances.length; while ( l-- ) { - if ( instances[l] === this ) { + if ( instances[ l ] === this ) { instances.splice( l, 1 ); } } @@ -2373,10 +2374,10 @@ proto.handleEvent = function ( event ) { proto.addEventListener = function ( type, fn ) { var handlers = this._events[ type ]; if ( !fn ) { - this.didError({ + this.didError( { name: 'Squire: addEventListener with null or undefined fn', message: 'Event type: ' + type - }); + } ); return this; } if ( !handlers ) { @@ -2395,7 +2396,7 @@ proto.removeEventListener = function ( type, fn ) { if ( handlers ) { l = handlers.length; while ( l-- ) { - if ( handlers[l] === fn ) { + if ( handlers[ l ] === fn ) { handlers.splice( l, 1 ); } } @@ -2484,7 +2485,7 @@ proto.getSelectedText = function () { var range = this.getSelection(), walker = new TreeWalker( range.commonAncestorContainer, - SHOW_TEXT|SHOW_ELEMENT, + SHOW_TEXT | SHOW_ELEMENT, function ( node ) { return isNodeContainedInRange( range, node, true ); } @@ -2625,11 +2626,11 @@ proto._saveRangeToBookmark = function ( range ) { var startNode = this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' - }), + } ), endNode = this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' - }), + } ), temp; insertNodeInRange( range, startNode ); @@ -2705,7 +2706,7 @@ proto._keyUpDetectChange = function ( event ) { // 3. The key pressed is not in range 33<=x<=45 (navigation keys) if ( !event.ctrlKey && !event.metaKey && !event.altKey && ( code < 16 || code > 20 ) && - ( code < 33 || code > 45 ) ) { + ( code < 33 || code > 45 ) ) { this._docWasChanged(); } }; @@ -2720,7 +2721,7 @@ proto._docWasChanged = function () { this.fireEvent( 'undoStateChange', { canUndo: true, canRedo: false - }); + } ); } this.fireEvent( 'input' ); }; @@ -2734,7 +2735,7 @@ proto._recordUndoState = function ( range ) { undoStack = this._undoStack; // Truncate stack if longer (i.e. if has been previously undone) - if ( undoIndex < this._undoStackLength) { + if ( undoIndex < this._undoStackLength ) { undoStack.length = this._undoStackLength = undoIndex; } @@ -2764,7 +2765,7 @@ proto.undo = function () { this.fireEvent( 'undoStateChange', { canUndo: this._undoIndex !== 0, canRedo: true - }); + } ); this.fireEvent( 'input' ); } return this; @@ -2785,7 +2786,7 @@ proto.redo = function () { this.fireEvent( 'undoStateChange', { canUndo: true, canRedo: undoIndex + 2 < undoStackLength - }); + } ); this.fireEvent( 'input' ); } return this; @@ -2895,10 +2896,10 @@ proto._addFormat = function ( tag, attributes, range ) { // and adding other styles is harmless. walker = new TreeWalker( range.commonAncestorContainer, - SHOW_TEXT|SHOW_ELEMENT, + SHOW_TEXT | SHOW_ELEMENT, function ( node ) { return ( node.nodeType === TEXT_NODE || - node.nodeName === 'BR'|| + node.nodeName === 'BR' || node.nodeName === 'IMG' ) && isNodeContainedInRange( range, node, true ); }, @@ -3015,7 +3016,7 @@ proto._removeFormat = function ( tag, attributes, range, partial ) { // Ignore bookmarks and empty text nodes if ( node.nodeName !== 'INPUT' && ( !isText || node.data ) ) { - toWrap.push([ exemplar, node ]); + toWrap.push( [ exemplar, node ] ); } return; } @@ -3023,11 +3024,11 @@ proto._removeFormat = function ( tag, attributes, range, partial ) { // Split any partially selected text nodes. if ( isText ) { if ( node === endContainer && endOffset !== node.length ) { - toWrap.push([ exemplar, node.splitText( endOffset ) ]); + toWrap.push( [ exemplar, node.splitText( endOffset ) ] ); } if ( node === startContainer && startOffset ) { node.splitText( startOffset ); - toWrap.push([ exemplar, node ]); + toWrap.push( [ exemplar, node ] ); } } // If not a text node, recurse onto all children. @@ -3050,21 +3051,21 @@ proto._removeFormat = function ( tag, attributes, range, partial ) { if ( !partial ) { formatTags.forEach( function ( node ) { examineNode( node, node ); - }); + } ); } // Now wrap unselected nodes in the tag toWrap.forEach( function ( item ) { // [ exemplar, node ] tuple - var el = item[0].cloneNode( false ), - node = item[1]; + var el = item[ 0 ].cloneNode( false ), + node = item[ 1 ]; replaceWith( node, el ); el.appendChild( node ); - }); + } ); // and remove old formatting tags. formatTags.forEach( function ( el ) { replaceWith( el, empty( el ) ); - }); + } ); // Merge adjacent inlines: this._getRangeAndRemoveBookmark( range ); @@ -3227,30 +3228,30 @@ var increaseBlockQuoteLevel = function ( frag ) { return this.createElement( 'BLOCKQUOTE', this._config.tagAttributes.blockquote, [ frag - ]); + ] ); }; var decreaseBlockQuoteLevel = function ( frag ) { var blockquotes = frag.querySelectorAll( 'blockquote' ); Array.prototype.filter.call( blockquotes, function ( el ) { return !getNearest( el.parentNode, 'BLOCKQUOTE' ); - }).forEach( function ( el ) { + } ).forEach( function ( el ) { replaceWith( el, empty( el ) ); - }); + } ); return frag; }; -var removeBlockQuote = function (/* frag */) { - return this.createDefaultBlock([ +var removeBlockQuote = function ( /* frag */ ) { + return this.createDefaultBlock( [ this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' - }), + } ), this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' - }) - ]); + } ) + ] ); }; var makeList = function ( self, frag, type ) { @@ -3279,7 +3280,7 @@ var makeList = function ( self, frag, type ) { node, self.createElement( type, listAttrs, [ newLi - ]) + ] ) ); } newLi.appendChild( node ); @@ -3309,12 +3310,12 @@ var removeList = function ( frag ) { var lists = frag.querySelectorAll( 'UL, OL' ), i, l, ll, list, listFrag, children, child; for ( i = 0, l = lists.length; i < l; i += 1 ) { - list = lists[i]; + list = lists[ i ]; listFrag = empty( list ); children = listFrag.childNodes; ll = children.length; while ( ll-- ) { - child = children[ll]; + child = children[ ll ]; replaceWith( child, empty( child ) ); } fixContainer( listFrag ); @@ -3331,7 +3332,7 @@ var increaseListLevel = function ( frag ) { listItemAttrs = tagAttributes.li, listAttrs; for ( i = 0, l = items.length; i < l; i += 1 ) { - item = items[i]; + item = items[ i ]; if ( !isContainer( item.firstChild ) ) { // type => 'UL' or 'OL' type = item.parentNode.nodeName; @@ -3343,7 +3344,7 @@ var increaseListLevel = function ( frag ) { item, this.createElement( 'LI', listItemAttrs, [ newParent = this.createElement( type, listAttrs ) - ]) + ] ) ); } newParent.appendChild( item ); @@ -3356,7 +3357,7 @@ var decreaseListLevel = function ( frag ) { var items = frag.querySelectorAll( 'LI' ); Array.prototype.filter.call( items, function ( el ) { return !isContainer( el.firstChild ); - }).forEach( function ( item ) { + } ).forEach( function ( item ) { var parent = item.parentNode, newParent = parent.parentNode, first = item.firstChild, @@ -3437,7 +3438,7 @@ proto.getHTML = function ( withBookMark ) { if ( useTextFixer ) { l = brs.length; while ( l-- ) { - detach( brs[l] ); + detach( brs[ l ] ); } } if ( range ) { @@ -3543,9 +3544,9 @@ proto.insertElement = function ( el, range ) { }; proto.insertImage = function ( src, attributes ) { - var img = this.createElement( 'IMG', mergeObjects({ + var img = this.createElement( 'IMG', mergeObjects( { src: src - }, attributes )); + }, attributes ) ); this.insertElement( img ); return img; }; @@ -3564,18 +3565,18 @@ var addLinks = function ( frag ) { parent = node.parentNode; while ( match = linkRegExp.exec( data ) ) { index = match.index; - endIndex = index + match[0].length; + endIndex = index + match[ 0 ].length; if ( index ) { child = doc.createTextNode( data.slice( 0, index ) ); parent.insertBefore( child, node ); } child = doc.createElement( 'A' ); child.textContent = data.slice( index, endIndex ); - child.href = match[1] ? - /^(?:ht|f)tps?:/.test( match[1] ) ? - match[1] : - 'http://' + match[1] : - 'mailto:' + match[2]; + 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 ); } @@ -3643,11 +3644,11 @@ proto.insertPlainText = function ( plainText, isPaste ) { var lines = plainText.split( '\n' ), i, l; for ( i = 1, l = lines.length - 1; i < l; i += 1 ) { - lines[i] = '
' + - lines[i].split( '&' ).join( '&' ) - .split( '<' ).join( '<' ) - .split( '>' ).join( '>' ) - .replace( / (?= )/g, ' ' ) + + lines[ i ] = '
' + + lines[ i ].split( '&' ).join( '&' ) + .split( '<' ).join( '<' ) + .split( '>' ).join( '>' ) + .replace( / (?= )/g, ' ' ) + '
'; } return this.insertHTML( lines.join( '' ), isPaste ); @@ -3667,7 +3668,7 @@ proto.addStyles = function ( styles ) { var head = this._doc.documentElement.firstChild, style = this.createElement( 'STYLE', { type: 'text/css' - }); + } ); style.appendChild( this._doc.createTextNode( styles ) ); head.appendChild( style ); } @@ -3706,7 +3707,7 @@ proto.makeLink = function ( url, attributes ) { } attributes.href = url; - this.changeFormat({ + this.changeFormat( { tag: 'A', attributes: attributes }, { @@ -3722,7 +3723,7 @@ proto.removeLink = function () { }; proto.setFontFace = function ( name ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'font', @@ -3731,11 +3732,11 @@ proto.setFontFace = function ( name ) { }, { tag: 'SPAN', attributes: { 'class': 'font' } - }); + } ); return this.focus(); }; proto.setFontSize = function ( size ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'size', @@ -3745,12 +3746,12 @@ proto.setFontSize = function ( size ) { }, { tag: 'SPAN', attributes: { 'class': 'size' } - }); + } ); return this.focus(); }; proto.setTextColour = function ( colour ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'colour', @@ -3759,12 +3760,12 @@ proto.setTextColour = function ( colour ) { }, { tag: 'SPAN', attributes: { 'class': 'colour' } - }); + } ); return this.focus(); }; proto.setHighlightColour = function ( colour ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'highlight', @@ -3773,7 +3774,7 @@ proto.setHighlightColour = function ( colour ) { }, { tag: 'SPAN', attributes: { 'class': 'highlight' } - }); + } ); return this.focus(); }; @@ -3783,7 +3784,7 @@ proto.setTextAlignment = function ( alignment ) { .split( /\s+/ ) .filter( function ( klass ) { return !( /align/.test( klass ) ); - }) + } ) .join( ' ' ) + ' align-' + alignment ).trim(); block.style.textAlign = alignment; @@ -3808,10 +3809,10 @@ function removeFormatting ( self, root, clean ) { continue; } } else if ( isBlock( node ) ) { - clean.appendChild( self.createDefaultBlock([ + clean.appendChild( self.createDefaultBlock( [ removeFormatting( self, node, self._doc.createDocumentFragment() ) - ])); + ] ) ); continue; } removeFormatting( self, node, clean ); @@ -3919,7 +3920,7 @@ if ( typeof exports === 'object' ) { } else if ( typeof define === 'function' && define.amd ) { define( function () { return Squire; - }); + } ); } else { win.Squire = Squire; diff --git a/build/squire.js b/build/squire.js index 8d3aa60..9976e43 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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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=C(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=C(a,c.blockTag,c.blockAttributes)),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=C(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(N(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(N(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=C(a,"DIV"),n.appendChild(N(r)),r.appendChild(n)}m(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&E(o)}else s&&(r=C(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._sel=r.getSelection(),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),q=/Mac OS X/.test(z),Z=/Gecko\//.test(z),G=/Trident\/[456]\./.test(z),V=!!W.opera,j=/WebKit\//.test(z),Q=q?"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()},Nt=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()},Ct=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),i.nodeType===R&&(i=i.parentNode);var d=e._doc,l=e._body;i.offsetTop+i.offsetHeight>(d.documentElement.scrollTop||l.scrollTop)+l.offsetHeight&&i.scrollIntoView(!1)},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(Nt(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)&&Nt(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}},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()}};q&&Z&&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")}),q||(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 C(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:et,replace:function(e,t){return C(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return C(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return C(e,"I")}},fontFamily:{regexp:et,replace:function(e,t){return C(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:et,replace:function(e,t){return C(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ot=function(e){return function(t,n){var r=C(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(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(N(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=C(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=C(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=C(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=C(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=C(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(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(N(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,N=pt(h),C=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(f.scrollTop+(N?N.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});f.appendChild(C),h.selectNodeContents(C),this.setSelection(h),setTimeout(function(){try{c._awaitingPaste=!1;for(var e,t,n="",r=C;C=r;)r=C.nextSibling,m(C),e=C.firstChild,e&&e===C.lastChild&&"DIV"===e.nodeName&&(C=e),n+=C.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 C(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._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._sel;t.removeAllRanges(),t.addRange(e)}return this},Wt.getSelection=function(){var e,t,n,r=this._sel;return 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;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 Z&&this._body.blur(),top.focus(),this};var qt="squire-selection-start",Zt="squire-selection-end";Wt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:qt,type:"hidden"}),r=this.createElement("INPUT",{id:Zt,type:"hidden"});st(e,n),e.collapse(!1),st(e,r),n.compareDocumentPosition(r)&A&&(n.id=Zt,r.id=qt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Wt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(qt),r=t.getElementById(Zt);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;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={family:t,size:t};if(!e&&!(e=this.getSelection()))return o;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===R)for(n.nodeType===R&&(n=n.parentNode);(!o.family||!o.size)&&n&&(r=n.style);)o.family||(o.family=r.fontFamily),o.size||(o.size=r.fontSize),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,N(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=C(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(N(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),Ct(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=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(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(N(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(N(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=e.split("\n");for(n=1,r=o.length-1;r>n;n+=1)o[n]="
"+o[n].split("&").join("&").split("<").join("<").split(">").join(">").replace(/ (?= )/g," ")+"
";return this.insertHTML(o.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||(Ct(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,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){return e.nodeType===L&&!!oe[e.nodeName]}function a(e){return re.test(e.nodeName)}function s(e){var t=e.nodeType;return(t===L||t===D)&&!a(e)&&r(e.childNodes,a)}function d(e){var t=e.nodeType;return!(t!==L&&t!==D||a(e)||s(e))}function l(e,t){return!i(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function c(e){var t=e.ownerDocument,r=new n(t.body,I,s,!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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),a(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&&!i(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=C(r,"BR");(n=e.lastElementChild)&&!a(n);)e=n;return t&&e.appendChild(t),o}function _(e){var t,n,r,o,i=e.childNodes,s=e.ownerDocument,l=null,c=k(s)._config;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&a(r)?(l||(l=C(s,c.blockTag,c.blockAttributes)),l.appendChild(r),t-=1,n-=1):(o||l)&&(l||(l=C(s,c.blockTag,c.blockAttributes)),S(l),o?e.replaceChild(l,r):(e.insertBefore(l,r),t+=1,n+=1),l=null),d(r)&&_(r);return l&&e.appendChild(S(l)),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=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=g(r))),m(n),n.nodeType===R?r.appendData(n.data):d.push(N(n));else if(n.nodeType===L){for(o=d.length;o--;)n.appendChild(d.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(N(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,i=e.ownerDocument,a="LI"===e.nodeName;if(!a||o&&/^[OU]L$/.test(o.nodeName))if(r&&l(r,e)){if(!d(r)){if(!a)return;n=C(i,"DIV"),n.appendChild(N(r)),r.appendChild(n)}m(e),t=!d(e),r.appendChild(N(e)),t&&_(r),o&&E(o)}else a&&(r=C(i,"DIV"),e.insertBefore(r,o),S(r))}function k(e){for(var t,n=He.length;n--;)if(t=He[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._sel=r.getSelection(),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",Fe),this.addEventListener(G?"beforepaste":"paste",Me),this.addEventListener(V?"keypress":"keydown",_e),this._keyHandlers=Object.create(Ee),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){}He.push(this),this.setHTML("")}function x(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,a(r)){if(r.nodeType===R||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(s(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),q=/Mac OS X/.test(z),Z=/Gecko\//.test(z),G=/Trident\/[456]\./.test(z),V=!!W.opera,j=/WebKit\//.test(z),Q=q?"meta-":"ctrl-",Y=G||V,$=G||j,X=G,J="undefined"!=typeof MutationObserver,ee=/[^ \t\r\n]/,te=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var ne={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(ne[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(ne[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(ne[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var re=/^(?:#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)$/,oe={BR:1,IMG:1,INPUT:1},ie=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},ae=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},he=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,a=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!i(t));)n=t,r=0;if(a)for(;o.nodeType!==R&&(t=o.childNodes[a-1],t&&!i(t));)o=t,a=g(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!i(t));)o=t;e.collapsed?(e.setStart(o,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,a))},ue=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=te.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=te.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},pe=function(e){var t,n=e.startContainer;return a(n)?t=f(n):s(n)?t=n:(t=ie(n,e.startOffset),t=h(t)),t&&fe(e,t,!0)?t:null},ge=function(e){var t,n,r=e.endContainer;if(a(r))t=f(r);else if(s(r))t=r;else{if(t=ae(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&&fe(e,t,!0)?t:null},me=new n(null,U|I,function(e){return e.nodeType===R?ee.test(e.data):"IMG"===e.nodeName}),ve=function(e){var t=e.startContainer,n=e.startOffset;if(me.root=null,t.nodeType===R){if(n)return!1;me.currentNode=t}else me.currentNode=ae(t,n);return me.root=pe(e),!me.previousNode()},Ne=function(e){var t,n=e.endContainer,r=e.endOffset;if(me.root=null,n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;me.currentNode=n}else me.currentNode=ie(n,r);return me.root=ge(e),!me.nextNode()},Ce=function(e){var t,n=pe(e),r=ge(e);n&&r&&(t=n.parentNode,e.setStart(t,te.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,te.call(t.childNodes,r)+1))},Se={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},_e=function(e){var t=e.keyCode,n=Se[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),le(o),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},ye=function(e){return function(t,n){n.preventDefault(),t[e]()}},Te=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)}},be=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===R&&(r=r.parentNode),n=r;a(n)&&(!n.textContent||n.textContent===H);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,te.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),s(n)||(n=f(n)),S(n),he(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)}},Ee={enter:function(e,t,n){var r,o,i;if(t.preventDefault(),e._recordUndoState(n),ot(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||le(n),r=pe(n),!r||/^T[HD]$/.test(r.nodeName))return se(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(nt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Ye,n)}for(i=Ve(e,r,n.startContainer,n.startOffset),Ke(r),Ie(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),i.nodeType===R&&(i=i.parentNode);var d=e._doc,l=e._body;i.offsetTop+i.offsetHeight>(d.documentElement.scrollTop||l.scrollTop)+l.offsetHeight&&i.scrollIntoView(!1)},backspace:function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(ve(n)){t.preventDefault();var r=pe(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(nt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Qe,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){be(e)},0);else t.preventDefault(),le(n),be(e,n)},"delete":function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(Ne(n)){t.preventDefault();var r=pe(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(ue(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),he(n),void be(e,n);e.setSelection(d),setTimeout(function(){be(e)},0)}else t.preventDefault(),le(n),be(e,n)},tab:function(e,t,n){var r,o;if(e._removeZWS(),n.collapsed&&ve(n)&&Ne(n))for(r=pe(n);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(tt,n));break}r=o}},space:function(e,t,n){var r,o;e._recordUndoState(n),ot(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()}};q&&Z&&W.getSelection().modify&&(Ee["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Ee["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),q||(Ee.pageup=function(e){e.moveCursorToStart()},Ee.pagedown=function(e){e.moveCursorToEnd()}),Ee[Q+"b"]=Te("B"),Ee[Q+"i"]=Te("I"),Ee[Q+"u"]=Te("U"),Ee[Q+"shift-7"]=Te("S"),Ee[Q+"shift-5"]=Te("SUB",{tag:"SUP"}),Ee[Q+"shift-6"]=Te("SUP",{tag:"SUB"}),Ee[Q+"shift-8"]=ye("makeUnorderedList"),Ee[Q+"shift-9"]=ye("makeOrderedList"),Ee[Q+"["]=ye("decreaseQuoteLevel"),Ee[Q+"]"]=ye("increaseQuoteLevel"),Ee[Q+"y"]=ye("redo"),Ee[Q+"z"]=ye("undo"),Ee[Q+"shift-z"]=ye("redo");var ke={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Be={backgroundColor:{regexp:ee,replace:function(e,t){return C(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:ee,replace:function(e,t){return C(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return C(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return C(e,"I")}},fontFamily:{regexp:ee,replace:function(e,t){return C(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:ee,replace:function(e,t){return C(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Oe=function(e){return function(t,n){var r=C(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},xe={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Be)r=Be[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:Oe("B"),EM:Oe("I"),STRIKE:Oe("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=C(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=C(c,"SPAN",{"class":"size",style:"font-size:"+ke[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=C(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=C(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=C(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ae=/^(?: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)$/,Le=/^(?:HEAD|META|STYLE)/,Re=new n(null,U|I,function(){return!0}),De=function at(e){var t,n,r,o,i,s,d,l,c,f,h,u,p=e.childNodes;for(t=e;a(t);)t=t.parentNode;for(Re.root=t,n=0,r=p.length;r>n;n+=1)if(o=p[n],i=o.nodeName,s=o.nodeType,d=xe[i],s===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(Le.test(i)){e.removeChild(o),n-=1,r-=1;continue}if(!Ae.test(i)&&!a(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}}l&&at(o)}else{if(s===R){if(h=o.data,c=!ee.test(h.charAt(0)),f=!ee.test(h.charAt(h.length-1)),!c&&!f)continue;if(c){for(Re.currentNode=o;(u=Re.previousPONode())&&(i=u.nodeName,!("IMG"===i||"#text"===i&&/\S/.test(u.data)));)if(!a(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(f){for(Re.currentNode=o;(u=Re.nextNode())&&!("IMG"===i||"#text"===i&&/\S/.test(u.data));)if(!a(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},Ie=function st(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==L||i(t)?t.nodeType!==R||t.data||e.removeChild(t):(st(t),a(t)&&!t.firstChild&&e.removeChild(t))},Ue=function(e){return e.nodeType===L?"BR"===e.nodeName:ee.test(e.data)},Pe=function(e){for(var t,r=e.parentNode;a(r);)r=r.parentNode;return t=new n(r,I|U,Ue),t.currentNode=e,!!t.nextNode()},we=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],s=o.length;for(t=0;s>t;t+=1)i[t]=Pe(o[t]);for(;s--;)n=o[s],r=n.parentNode,r&&(i[s]?a(r)||_(r):m(n))},Fe=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)},Me=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&&(te.call(i.types,"text/html")>-1||te.call(i.types,"text/plain")>-1&&te.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,N=pe(h),C=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(f.scrollTop+(N?N.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});f.appendChild(C),h.selectNodeContents(C),this.setSelection(h),setTimeout(function(){try{c._awaitingPaste=!1;for(var e,t,n="",r=C;C=r;)r=C.nextSibling,m(C),e=C.firstChild,e&&e===C.lastChild&&"DIV"===e.nodeName&&(C=e),n+=C.innerHTML;t=c._createRange(u,p,g,v),c.setSelection(t),n&&c.insertHTML(n,!0)}catch(o){c.didError(o)}},0)},He=[],We=O.prototype;We.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},We.createElement=function(e,t,n){return C(this._doc,e,t,n)},We.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e))},We.didError=function(e){console.log(e)},We.getDocument=function(){return this._doc};var ze={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};We.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},We.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)ze[e]||n.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var o=He.length;o--;)He[o]===this&&He.splice(o,1)},We.handleEvent=function(e){this.fireEvent(e.type,e)},We.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],ze[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)},We.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],ze[e]||this._doc.removeEventListener(e,this,!1))}return this},We._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},We._moveCursorTo=function(e){var t=this._body,n=this._createRange(t,e?0:t.childNodes.length);return he(n),this.setSelection(n),this},We.moveCursorToStart=function(){return this._moveCursorTo(!0)},We.moveCursorToEnd=function(){return this._moveCursorTo(!1)},We.setSelection=function(e){if(e){K&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},We.getSelection=function(){var e,t,n,r=this._sel;return r.rangeCount?(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&i(t)&&e.setStartBefore(t),n&&i(n)&&e.setEndBefore(n),this._lastSelection=e):e=this._lastSelection,e||(e=this._createRange(this._body.firstChild,0)),e},We.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,U|I,function(e){return fe(t,e,!0)}),o=t.startContainer,i=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===R?(e=s.data,e&&/\S/.test(e)&&(s===i&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!a(s))&&(d+="\n",l=!1),s=r.nextNode();return d},We.getPath=function(){return this._path};var Ke=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;while(a(r)&&!g(r));break}r.deleteData(o,1)}};We._didAddZWS=function(){this._hasZWS=!0},We._removeZWS=function(){this._hasZWS&&(Ke(this._body),this._hasZWS=!1)},We._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")},We._updatePathOnEvent=function(){this._updatePath(this.getSelection())},We.focus=function(){return V||this._body.focus(),this._win.focus(),this},We.blur=function(){return Z&&this._body.blur(),top.focus(),this};var qe="squire-selection-start",Ze="squire-selection-end";We._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:qe,type:"hidden"}),r=this.createElement("INPUT",{id:Ze,type:"hidden"});se(e,n),e.collapse(!1),se(e,r),n.compareDocumentPosition(r)&A&&(n.id=Ze,r.id=qe,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},We._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(qe),r=t.getElementById(Ze);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:te.call(i.childNodes,n),endOffset:te.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,he(e),o&&e.collapse(!0)}return e||null},We._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},We._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"))},We._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},We.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;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 fe(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},We.getFontInfo=function(e){var n,r,o={family:t,size:t};if(!e&&!(e=this.getSelection()))return o;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===R)for(n.nodeType===R&&(n=n.parentNode);(!o.family||!o.size)&&n&&(r=n.style);)o.family||(o.family=r.fontFamily),o.size||(o.size=r.fontSize),n=n.parentNode;return o},We._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),se(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)&&fe(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},We._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,s=this._doc;n.collapsed&&($?(i=s.createTextNode(H),this._didAddZWS()):i=s.createTextNode(""),se(n,i));for(var d=n.commonAncestorContainer;a(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!fe(n,e,!1)){var r,o,i=e.nodeType===R;if(!fe(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 fe(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,N(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},We.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 Ge={DT:"DD",DD:"DT",LI:"LI"},Ve=function(e,t,n,r){var i=Ge[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=C(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(N(s)),s=t),s};We.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=pe(n),o=ge(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},We.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ce(t);var n,r=this._body;return ue(t,r),n=de(t,r),se(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],v(s,N(s));_(i),v(o,i)}return e},tt=function(e){var t,n,r,o,i,a,s=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=s.length;n>t;t+=1)r=s[t],d(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=l[o.toLowerCase()],v(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},nt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!d(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,!d(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};We._ensureBottomLine=function(){var e=this._body,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&s(t)||e.appendChild(this.createDefaultBlock())},We.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},We._getHTML=function(){return this._body.innerHTML},We._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t));this._ignoreChange=!0},We.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},We.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),De(n),we(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},We.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),a(e))se(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=pe(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),he(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this},We.insertImage=function(e,t){var n=this.createElement("IMG",B({src:e},t));return this.insertElement(n),n};var rt=/\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,ot=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=rt.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)};We.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(N(o)),this._recordUndoState(n),this._getRangeAndRemoveBookmark(n);try{var i=r,a={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(ot(r),De(r),we(r),Ie(r),r.normalize();i=h(i);)S(i);t&&this.fireEvent("willPaste",a),a.defaultPrevented||(ce(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},We.insertPlainText=function(e,t){var n,r,o=e.split("\n");for(n=1,r=o.length-1;r>n;n+=1)o[n]="
"+o[n].split("&").join("&").split("<").join("<").split(">").join(">").replace(/ (?= )/g," ")+"
";return this.insertHTML(o.join(""),t)};var it=function(e,t,n){return function(){return this[e](t,n),this.focus()}};We.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},We.bold=it("changeFormat",{tag:"B"}),We.italic=it("changeFormat",{tag:"I"}),We.underline=it("changeFormat",{tag:"U"}),We.strikethrough=it("changeFormat",{tag:"S"}),We.subscript=it("changeFormat",{tag:"SUB"},{tag:"SUP"}),We.superscript=it("changeFormat",{tag:"SUP"},{tag:"SUB"}),We.removeBold=it("changeFormat",null,{tag:"B"}),We.removeItalic=it("changeFormat",null,{tag:"I"}),We.removeUnderline=it("changeFormat",null,{tag:"U"}),We.removeStrikethrough=it("changeFormat",null,{tag:"S"}),We.removeSubscript=it("changeFormat",null,{tag:"SUB"}),We.removeSuperscript=it("changeFormat",null,{tag:"SUP"}),We.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;se(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},We.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},We.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},We.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()},We.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},We.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},We.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()},We.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},We.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=e.commonAncestorContainer;t&&!s(t);)t=t.parentNode;if(t||(Ce(e),t=this._body),t.nodeType===R)return this;this._recordUndoState(e),this._getRangeAndRemoveBookmark(e),ue(e,t);for(var n,r,o,i=t.ownerDocument,a=e.startContainer,d=e.startOffset,l=e.endContainer,c=e.endOffset,f=i.createDocumentFragment(),h=i.createDocumentFragment(),u=y(l,c,t),p=y(a,d,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),d=te.call(o,p),c=te.call(o,n)+1):(d=te.call(o,u),c=d),r={startContainer:t,startOffset:d,endContainer:t,endOffset:c},T(t,r),e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),he(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},We.increaseQuoteLevel=it("modifyBlocks",je),We.decreaseQuoteLevel=it("modifyBlocks",Qe),We.makeUnorderedList=it("modifyBlocks",Xe),We.makeOrderedList=it("modifyBlocks",Je),We.removeList=it("modifyBlocks",et),We.increaseListLevel=it("modifyBlocks",tt),We.decreaseListLevel=it("modifyBlocks",nt),"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 diff --git a/source/Clean.js b/source/Clean.js index 2191e25..7b38eee 100644 --- a/source/Clean.js +++ b/source/Clean.js @@ -17,7 +17,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'highlight', style: 'background-color: ' + colour - }); + } ); } }, color: { @@ -26,7 +26,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'colour', style: 'color:' + colour - }); + } ); } }, fontWeight: { @@ -47,7 +47,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'font', style: 'font-family:' + family - }); + } ); } }, fontSize: { @@ -56,7 +56,7 @@ var spanToSemantic = { return createElement( doc, 'SPAN', { 'class': 'size', style: 'font-size:' + size - }); + } ); } } }; @@ -112,7 +112,7 @@ var stylesRewriters = { fontSpan = createElement( doc, 'SPAN', { 'class': 'font', style: 'font-family:' + face - }); + } ); newTreeTop = fontSpan; newTreeBottom = fontSpan; } @@ -120,7 +120,7 @@ var stylesRewriters = { sizeSpan = createElement( doc, 'SPAN', { 'class': 'size', style: 'font-size:' + fontSizes[ size ] + 'px' - }); + } ); if ( !newTreeTop ) { newTreeTop = sizeSpan; } @@ -136,7 +136,7 @@ var stylesRewriters = { colourSpan = createElement( doc, 'SPAN', { 'class': 'colour', style: 'color:' + colour - }); + } ); if ( !newTreeTop ) { newTreeTop = colourSpan; } @@ -156,7 +156,7 @@ var stylesRewriters = { var el = createElement( node.ownerDocument, 'SPAN', { 'class': 'font', style: 'font-family:menlo,consolas,"courier new",monospace' - }); + } ); parent.replaceChild( el, node ); el.appendChild( empty( node ) ); return el; @@ -167,9 +167,9 @@ var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT var blacklist = /^(?:HEAD|META|STYLE)/; -var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () { +var walker = new TreeWalker( null, SHOW_TEXT | SHOW_ELEMENT, function () { return true; -}); +} ); /* Two purposes: @@ -190,7 +190,7 @@ var cleanTree = function cleanTree ( node ) { walker.root = nonInlineParent; for ( i = 0, l = children.length; i < l; i += 1 ) { - child = children[i]; + child = children[ i ]; nodeName = child.nodeName; nodeType = child.nodeType; rewriter = stylesRewriters[ nodeName ]; @@ -277,7 +277,7 @@ var removeEmptyInlines = function removeEmptyInlines ( root ) { l = children.length, child; while ( l-- ) { - child = children[l]; + child = children[ l ]; if ( child.nodeType === ELEMENT_NODE && !isLeaf( child ) ) { removeEmptyInlines( child ); if ( isInline( child ) && !child.firstChild ) { @@ -303,7 +303,7 @@ var isLineBreak = function ( br ) { block = block.parentNode; } walker = new TreeWalker( - block, SHOW_ELEMENT|SHOW_TEXT, notWSTextNode ); + block, SHOW_ELEMENT | SHOW_TEXT, notWSTextNode ); walker.currentNode = br; return !!walker.nextNode(); }; @@ -326,10 +326,10 @@ var cleanupBRs = function ( root ) { // therefore seem to not be a line break. But in its original context it // was, so we should also convert it to a block split. for ( i = 0; i < l; i += 1 ) { - brBreaksLine[i] = isLineBreak( brs[i] ); + brBreaksLine[ i ] = isLineBreak( brs[ i ] ); } while ( l-- ) { - br = brs[l]; + br = brs[ l ]; // Cleanup may have removed it parent = br.parentNode; if ( !parent ) { continue; } @@ -337,7 +337,7 @@ var cleanupBRs = function ( root ) { // anything useful. We'll add it back later if required by the // browser. If it breaks a line, wrap the content in div tags // and replace the brs. - if ( !brBreaksLine[l] ) { + if ( !brBreaksLine[ l ] ) { detach( br ); } else if ( !isInline( parent ) ) { fixContainer( parent ); diff --git a/source/Clipboard.js b/source/Clipboard.js index c42d6d3..1d7d3d5 100644 --- a/source/Clipboard.js +++ b/source/Clipboard.js @@ -34,13 +34,13 @@ var onPaste = function ( event ) { event.preventDefault(); l = items.length; while ( l-- ) { - item = items[l]; + item = items[ l ]; type = item.type; if ( type === 'text/html' ) { /*jshint loopfunc: true */ item.getAsString( function ( html ) { self.insertHTML( html, true ); - }); + } ); /*jshint loopfunc: false */ return; } @@ -60,16 +60,16 @@ var onPaste = function ( event ) { fireDrop = true; } /*jshint loopfunc: false */ - }); + } ); if ( fireDrop ) { this.fireEvent( 'drop', { dataTransfer: clipboardData - }); + } ); } } else if ( plainItem ) { item.getAsString( function ( text ) { self.insertPlainText( text, true ); - }); + } ); } return; } @@ -89,9 +89,9 @@ var onPaste = function ( event ) { // 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. - if (( data = clipboardData.getData( 'text/html' ) )) { + if ( ( data = clipboardData.getData( 'text/html' ) ) ) { this.insertHTML( data, true ); - } else if (( data = clipboardData.getData( 'text/plain' ) )) { + } else if ( ( data = clipboardData.getData( 'text/plain' ) ) ) { this.insertPlainText( data, true ); } return; @@ -117,7 +117,7 @@ var onPaste = function ( event ) { ( body.scrollTop + ( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) + 'px; right: 150%; width: 1px; height: 1px;' - }); + } ); body.appendChild( pasteArea ); range.selectNodeContents( pasteArea ); this.setSelection( range ); diff --git a/source/Editor.js b/source/Editor.js index 8aabcfd..0ef944f 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -6,7 +6,7 @@ function getSquireInstance ( doc ) { var l = instances.length, instance; while ( l-- ) { - instance = instances[l]; + instance = instances[ l ]; if ( instance._doc === doc ) { return instance; } @@ -73,7 +73,7 @@ function Squire ( doc, config ) { attributes: true, characterData: true, subtree: true - }); + } ); this._mutation = mutation; } else { this.addEventListener( 'keyup', this._keyUpDetectChange ); @@ -141,7 +141,7 @@ function Squire ( doc, config ) { var proto = Squire.prototype; proto.setConfig = function ( config ) { - config = mergeObjects({ + config = mergeObjects( { blockTag: 'DIV', blockAttributes: null, tagAttributes: { @@ -203,7 +203,7 @@ proto.fireEvent = function ( type, event ) { handlers = handlers.slice(); l = handlers.length; while ( l-- ) { - obj = handlers[l]; + obj = handlers[ l ]; try { if ( obj.handleEvent ) { obj.handleEvent( event ); @@ -236,7 +236,7 @@ proto.destroy = function () { } var l = instances.length; while ( l-- ) { - if ( instances[l] === this ) { + if ( instances[ l ] === this ) { instances.splice( l, 1 ); } } @@ -249,10 +249,10 @@ proto.handleEvent = function ( event ) { proto.addEventListener = function ( type, fn ) { var handlers = this._events[ type ]; if ( !fn ) { - this.didError({ + this.didError( { name: 'Squire: addEventListener with null or undefined fn', message: 'Event type: ' + type - }); + } ); return this; } if ( !handlers ) { @@ -271,7 +271,7 @@ proto.removeEventListener = function ( type, fn ) { if ( handlers ) { l = handlers.length; while ( l-- ) { - if ( handlers[l] === fn ) { + if ( handlers[ l ] === fn ) { handlers.splice( l, 1 ); } } @@ -360,7 +360,7 @@ proto.getSelectedText = function () { var range = this.getSelection(), walker = new TreeWalker( range.commonAncestorContainer, - SHOW_TEXT|SHOW_ELEMENT, + SHOW_TEXT | SHOW_ELEMENT, function ( node ) { return isNodeContainedInRange( range, node, true ); } @@ -501,11 +501,11 @@ proto._saveRangeToBookmark = function ( range ) { var startNode = this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' - }), + } ), endNode = this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' - }), + } ), temp; insertNodeInRange( range, startNode ); @@ -581,7 +581,7 @@ proto._keyUpDetectChange = function ( event ) { // 3. The key pressed is not in range 33<=x<=45 (navigation keys) if ( !event.ctrlKey && !event.metaKey && !event.altKey && ( code < 16 || code > 20 ) && - ( code < 33 || code > 45 ) ) { + ( code < 33 || code > 45 ) ) { this._docWasChanged(); } }; @@ -596,7 +596,7 @@ proto._docWasChanged = function () { this.fireEvent( 'undoStateChange', { canUndo: true, canRedo: false - }); + } ); } this.fireEvent( 'input' ); }; @@ -610,7 +610,7 @@ proto._recordUndoState = function ( range ) { undoStack = this._undoStack; // Truncate stack if longer (i.e. if has been previously undone) - if ( undoIndex < this._undoStackLength) { + if ( undoIndex < this._undoStackLength ) { undoStack.length = this._undoStackLength = undoIndex; } @@ -640,7 +640,7 @@ proto.undo = function () { this.fireEvent( 'undoStateChange', { canUndo: this._undoIndex !== 0, canRedo: true - }); + } ); this.fireEvent( 'input' ); } return this; @@ -661,7 +661,7 @@ proto.redo = function () { this.fireEvent( 'undoStateChange', { canUndo: true, canRedo: undoIndex + 2 < undoStackLength - }); + } ); this.fireEvent( 'input' ); } return this; @@ -771,10 +771,10 @@ proto._addFormat = function ( tag, attributes, range ) { // and adding other styles is harmless. walker = new TreeWalker( range.commonAncestorContainer, - SHOW_TEXT|SHOW_ELEMENT, + SHOW_TEXT | SHOW_ELEMENT, function ( node ) { return ( node.nodeType === TEXT_NODE || - node.nodeName === 'BR'|| + node.nodeName === 'BR' || node.nodeName === 'IMG' ) && isNodeContainedInRange( range, node, true ); }, @@ -891,7 +891,7 @@ proto._removeFormat = function ( tag, attributes, range, partial ) { // Ignore bookmarks and empty text nodes if ( node.nodeName !== 'INPUT' && ( !isText || node.data ) ) { - toWrap.push([ exemplar, node ]); + toWrap.push( [ exemplar, node ] ); } return; } @@ -899,11 +899,11 @@ proto._removeFormat = function ( tag, attributes, range, partial ) { // Split any partially selected text nodes. if ( isText ) { if ( node === endContainer && endOffset !== node.length ) { - toWrap.push([ exemplar, node.splitText( endOffset ) ]); + toWrap.push( [ exemplar, node.splitText( endOffset ) ] ); } if ( node === startContainer && startOffset ) { node.splitText( startOffset ); - toWrap.push([ exemplar, node ]); + toWrap.push( [ exemplar, node ] ); } } // If not a text node, recurse onto all children. @@ -926,21 +926,21 @@ proto._removeFormat = function ( tag, attributes, range, partial ) { if ( !partial ) { formatTags.forEach( function ( node ) { examineNode( node, node ); - }); + } ); } // Now wrap unselected nodes in the tag toWrap.forEach( function ( item ) { // [ exemplar, node ] tuple - var el = item[0].cloneNode( false ), - node = item[1]; + var el = item[ 0 ].cloneNode( false ), + node = item[ 1 ]; replaceWith( node, el ); el.appendChild( node ); - }); + } ); // and remove old formatting tags. formatTags.forEach( function ( el ) { replaceWith( el, empty( el ) ); - }); + } ); // Merge adjacent inlines: this._getRangeAndRemoveBookmark( range ); @@ -1103,30 +1103,30 @@ var increaseBlockQuoteLevel = function ( frag ) { return this.createElement( 'BLOCKQUOTE', this._config.tagAttributes.blockquote, [ frag - ]); + ] ); }; var decreaseBlockQuoteLevel = function ( frag ) { var blockquotes = frag.querySelectorAll( 'blockquote' ); Array.prototype.filter.call( blockquotes, function ( el ) { return !getNearest( el.parentNode, 'BLOCKQUOTE' ); - }).forEach( function ( el ) { + } ).forEach( function ( el ) { replaceWith( el, empty( el ) ); - }); + } ); return frag; }; -var removeBlockQuote = function (/* frag */) { - return this.createDefaultBlock([ +var removeBlockQuote = function ( /* frag */ ) { + return this.createDefaultBlock( [ this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' - }), + } ), this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' - }) - ]); + } ) + ] ); }; var makeList = function ( self, frag, type ) { @@ -1155,7 +1155,7 @@ var makeList = function ( self, frag, type ) { node, self.createElement( type, listAttrs, [ newLi - ]) + ] ) ); } newLi.appendChild( node ); @@ -1185,12 +1185,12 @@ var removeList = function ( frag ) { var lists = frag.querySelectorAll( 'UL, OL' ), i, l, ll, list, listFrag, children, child; for ( i = 0, l = lists.length; i < l; i += 1 ) { - list = lists[i]; + list = lists[ i ]; listFrag = empty( list ); children = listFrag.childNodes; ll = children.length; while ( ll-- ) { - child = children[ll]; + child = children[ ll ]; replaceWith( child, empty( child ) ); } fixContainer( listFrag ); @@ -1207,7 +1207,7 @@ var increaseListLevel = function ( frag ) { listItemAttrs = tagAttributes.li, listAttrs; for ( i = 0, l = items.length; i < l; i += 1 ) { - item = items[i]; + item = items[ i ]; if ( !isContainer( item.firstChild ) ) { // type => 'UL' or 'OL' type = item.parentNode.nodeName; @@ -1219,7 +1219,7 @@ var increaseListLevel = function ( frag ) { item, this.createElement( 'LI', listItemAttrs, [ newParent = this.createElement( type, listAttrs ) - ]) + ] ) ); } newParent.appendChild( item ); @@ -1232,7 +1232,7 @@ var decreaseListLevel = function ( frag ) { var items = frag.querySelectorAll( 'LI' ); Array.prototype.filter.call( items, function ( el ) { return !isContainer( el.firstChild ); - }).forEach( function ( item ) { + } ).forEach( function ( item ) { var parent = item.parentNode, newParent = parent.parentNode, first = item.firstChild, @@ -1313,7 +1313,7 @@ proto.getHTML = function ( withBookMark ) { if ( useTextFixer ) { l = brs.length; while ( l-- ) { - detach( brs[l] ); + detach( brs[ l ] ); } } if ( range ) { @@ -1419,9 +1419,9 @@ proto.insertElement = function ( el, range ) { }; proto.insertImage = function ( src, attributes ) { - var img = this.createElement( 'IMG', mergeObjects({ + var img = this.createElement( 'IMG', mergeObjects( { src: src - }, attributes )); + }, attributes ) ); this.insertElement( img ); return img; }; @@ -1440,18 +1440,18 @@ var addLinks = function ( frag ) { parent = node.parentNode; while ( match = linkRegExp.exec( data ) ) { index = match.index; - endIndex = index + match[0].length; + endIndex = index + match[ 0 ].length; if ( index ) { child = doc.createTextNode( data.slice( 0, index ) ); parent.insertBefore( child, node ); } child = doc.createElement( 'A' ); child.textContent = data.slice( index, endIndex ); - child.href = match[1] ? - /^(?:ht|f)tps?:/.test( match[1] ) ? - match[1] : - 'http://' + match[1] : - 'mailto:' + match[2]; + 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 ); } @@ -1519,11 +1519,11 @@ proto.insertPlainText = function ( plainText, isPaste ) { var lines = plainText.split( '\n' ), i, l; for ( i = 1, l = lines.length - 1; i < l; i += 1 ) { - lines[i] = '
' + - lines[i].split( '&' ).join( '&' ) - .split( '<' ).join( '<' ) - .split( '>' ).join( '>' ) - .replace( / (?= )/g, ' ' ) + + lines[ i ] = '
' + + lines[ i ].split( '&' ).join( '&' ) + .split( '<' ).join( '<' ) + .split( '>' ).join( '>' ) + .replace( / (?= )/g, ' ' ) + '
'; } return this.insertHTML( lines.join( '' ), isPaste ); @@ -1543,7 +1543,7 @@ proto.addStyles = function ( styles ) { var head = this._doc.documentElement.firstChild, style = this.createElement( 'STYLE', { type: 'text/css' - }); + } ); style.appendChild( this._doc.createTextNode( styles ) ); head.appendChild( style ); } @@ -1582,7 +1582,7 @@ proto.makeLink = function ( url, attributes ) { } attributes.href = url; - this.changeFormat({ + this.changeFormat( { tag: 'A', attributes: attributes }, { @@ -1598,7 +1598,7 @@ proto.removeLink = function () { }; proto.setFontFace = function ( name ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'font', @@ -1607,11 +1607,11 @@ proto.setFontFace = function ( name ) { }, { tag: 'SPAN', attributes: { 'class': 'font' } - }); + } ); return this.focus(); }; proto.setFontSize = function ( size ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'size', @@ -1621,12 +1621,12 @@ proto.setFontSize = function ( size ) { }, { tag: 'SPAN', attributes: { 'class': 'size' } - }); + } ); return this.focus(); }; proto.setTextColour = function ( colour ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'colour', @@ -1635,12 +1635,12 @@ proto.setTextColour = function ( colour ) { }, { tag: 'SPAN', attributes: { 'class': 'colour' } - }); + } ); return this.focus(); }; proto.setHighlightColour = function ( colour ) { - this.changeFormat({ + this.changeFormat( { tag: 'SPAN', attributes: { 'class': 'highlight', @@ -1649,7 +1649,7 @@ proto.setHighlightColour = function ( colour ) { }, { tag: 'SPAN', attributes: { 'class': 'highlight' } - }); + } ); return this.focus(); }; @@ -1659,7 +1659,7 @@ proto.setTextAlignment = function ( alignment ) { .split( /\s+/ ) .filter( function ( klass ) { return !( /align/.test( klass ) ); - }) + } ) .join( ' ' ) + ' align-' + alignment ).trim(); block.style.textAlign = alignment; @@ -1684,10 +1684,10 @@ function removeFormatting ( self, root, clean ) { continue; } } else if ( isBlock( node ) ) { - clean.appendChild( self.createDefaultBlock([ + clean.appendChild( self.createDefaultBlock( [ removeFormatting( self, node, self._doc.createDocumentFragment() ) - ])); + ] ) ); continue; } removeFormatting( self, node, clean ); diff --git a/source/Node.js b/source/Node.js index dc5c3be..f60a465 100644 --- a/source/Node.js +++ b/source/Node.js @@ -11,7 +11,7 @@ var leafNodeNames = { function every ( nodeList, fn ) { var l = nodeList.length; while ( l-- ) { - if ( !fn( nodeList[l] ) ) { + if ( !fn( nodeList[ l ] ) ) { return false; } } @@ -31,15 +31,6 @@ function hasTagAttributes ( node, tag, attributes ) { } 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 && @@ -59,6 +50,16 @@ function isContainer ( node ) { !isInline( node ) && !isBlock( node ); } +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 getBlockWalker ( node ) { var doc = node.ownerDocument, walker = new TreeWalker( @@ -152,7 +153,7 @@ function createElement ( doc, tag, props, children ) { } if ( children ) { for ( i = 0, l = children.length; i < l; i += 1 ) { - el.appendChild( children[i] ); + el.appendChild( children[ i ] ); } } return el; @@ -239,7 +240,7 @@ function fixContainer ( container ) { config = getSquireInstance( doc )._config; for ( i = 0, l = children.length; i < l; i += 1 ) { - child = children[i]; + child = children[ i ]; isBR = child.nodeName === 'BR'; if ( !isBR && isInline( child ) ) { if ( !wrapper ) { @@ -334,7 +335,7 @@ function mergeInlines ( node, range ) { frags = [], child, prev, len; while ( l-- ) { - child = children[l]; + child = children[ l ]; prev = l && children[ l - 1 ]; if ( l && isInline( child ) && areAlike( child, prev ) && !leafNodeNames[ child.nodeName ] ) { diff --git a/source/Range.js b/source/Range.js index 9eac669..3008d46 100644 --- a/source/Range.js +++ b/source/Range.js @@ -66,7 +66,7 @@ var insertNodeInRange = function ( range, node ) { childCount = children.length; - if ( startOffset === childCount) { + if ( startOffset === childCount ) { startContainer.appendChild( node ); } else { startContainer.insertBefore( node, children[ startOffset ] ); @@ -185,7 +185,7 @@ var insertTreeFragmentIntoRange = function ( range, frag ) { children = frag.childNodes, l = children.length; while ( l-- ) { - if ( !isInline( children[l] ) ) { + if ( !isInline( children[ l ] ) ) { allInline = false; break; } @@ -451,7 +451,7 @@ var getEndBlockOfRange = function ( range ) { }; var contentWalker = new TreeWalker( null, - SHOW_TEXT|SHOW_ELEMENT, + SHOW_TEXT | SHOW_ELEMENT, function ( node ) { return node.nodeType === TEXT_NODE ? notWS.test( node.data ) : diff --git a/source/intro.js b/source/intro.js index 5fe3fb9..1753f81 100644 --- a/source/intro.js +++ b/source/intro.js @@ -3,4 +3,4 @@ ( function ( doc, undefined ) { -"use strict"; +'use strict'; diff --git a/source/outro.js b/source/outro.js index 4939423..4e21b71 100644 --- a/source/outro.js +++ b/source/outro.js @@ -5,7 +5,7 @@ if ( typeof exports === 'object' ) { } else if ( typeof define === 'function' && define.amd ) { define( function () { return Squire; - }); + } ); } else { win.Squire = Squire;