2013-04-07 22:27:06 -05:00
|
|
|
/*global
|
|
|
|
ELEMENT_NODE,
|
|
|
|
TEXT_NODE,
|
|
|
|
SHOW_ELEMENT,
|
|
|
|
FILTER_ACCEPT,
|
|
|
|
FILTER_SKIP,
|
2013-07-16 02:51:31 -05:00
|
|
|
win,
|
2013-04-07 22:27:06 -05:00
|
|
|
isOpera,
|
|
|
|
useTextFixer,
|
|
|
|
cantFocusEmptyTextNodes,
|
2011-10-28 22:15:21 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
TreeWalker,
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2013-07-16 02:51:31 -05:00
|
|
|
Text
|
2013-04-07 22:27:06 -05:00
|
|
|
*/
|
|
|
|
/*jshint strict:false */
|
2011-10-28 22:15:21 -05:00
|
|
|
|
2014-02-03 02:19:13 -05:00
|
|
|
var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/;
|
2013-04-07 22:27:06 -05:00
|
|
|
|
|
|
|
var leafNodeNames = {
|
|
|
|
BR: 1,
|
|
|
|
IMG: 1,
|
|
|
|
INPUT: 1
|
2011-10-28 22:15:21 -05:00
|
|
|
};
|
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function every ( nodeList, fn ) {
|
2011-10-28 22:15:21 -05:00
|
|
|
var l = nodeList.length;
|
|
|
|
while ( l-- ) {
|
|
|
|
if ( !fn( nodeList[l] ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
2011-10-28 22:15:21 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
// ---
|
2011-11-01 19:55:08 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function hasTagAttributes ( node, tag, attributes ) {
|
|
|
|
if ( node.nodeName !== tag ) {
|
|
|
|
return false;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
for ( var attr in attributes ) {
|
|
|
|
if ( node.getAttribute( attr ) !== attributes[ attr ] ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
function areAlike ( node, node2 ) {
|
|
|
|
return (
|
|
|
|
node.nodeType === node2.nodeType &&
|
|
|
|
node.nodeName === node2.nodeName &&
|
|
|
|
node.className === node2.className &&
|
|
|
|
( ( !node.style && !node2.style ) ||
|
|
|
|
node.style.cssText === node2.style.cssText )
|
|
|
|
);
|
|
|
|
}
|
2011-10-28 22:15:21 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function isLeaf ( node ) {
|
|
|
|
return node.nodeType === ELEMENT_NODE &&
|
|
|
|
!!leafNodeNames[ node.nodeName ];
|
|
|
|
}
|
|
|
|
function isInline ( node ) {
|
|
|
|
return inlineNodeNames.test( node.nodeName );
|
|
|
|
}
|
|
|
|
function isBlock ( node ) {
|
|
|
|
return node.nodeType === ELEMENT_NODE &&
|
|
|
|
!isInline( node ) && every( node.childNodes, isInline );
|
|
|
|
}
|
|
|
|
function isContainer ( node ) {
|
|
|
|
return node.nodeType === ELEMENT_NODE &&
|
|
|
|
!isInline( node ) && !isBlock( node );
|
|
|
|
}
|
2011-10-28 22:15:21 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function acceptIfBlock ( el ) {
|
|
|
|
return isBlock( el ) ? FILTER_ACCEPT : FILTER_SKIP;
|
|
|
|
}
|
|
|
|
function getBlockWalker ( node ) {
|
|
|
|
var doc = node.ownerDocument,
|
|
|
|
walker = new TreeWalker(
|
|
|
|
doc.body, SHOW_ELEMENT, acceptIfBlock, false );
|
|
|
|
walker.currentNode = node;
|
|
|
|
return walker;
|
|
|
|
}
|
2011-10-28 22:15:21 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function getPreviousBlock ( node ) {
|
|
|
|
return getBlockWalker( node ).previousNode();
|
|
|
|
}
|
|
|
|
function getNextBlock ( node ) {
|
|
|
|
return getBlockWalker( node ).nextNode();
|
|
|
|
}
|
|
|
|
function getNearest ( node, tag, attributes ) {
|
|
|
|
do {
|
|
|
|
if ( hasTagAttributes( node, tag, attributes ) ) {
|
|
|
|
return node;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
} while ( node = node.parentNode );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPath ( node ) {
|
|
|
|
var parent = node.parentNode,
|
|
|
|
path, id, className, classNames;
|
|
|
|
if ( !parent || node.nodeType !== ELEMENT_NODE ) {
|
|
|
|
path = parent ? getPath( parent ) : '';
|
|
|
|
} else {
|
|
|
|
path = getPath( parent );
|
|
|
|
path += ( path ? '>' : '' ) + node.nodeName;
|
|
|
|
if ( id = node.id ) {
|
2011-10-28 22:15:21 -05:00
|
|
|
path += '#' + id;
|
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( className = node.className.trim() ) {
|
2013-01-29 19:28:36 -05:00
|
|
|
classNames = className.split( /\s\s*/ );
|
|
|
|
classNames.sort();
|
2011-10-28 22:15:21 -05:00
|
|
|
path += '.';
|
2013-01-29 19:28:36 -05:00
|
|
|
path += classNames.join( '.' );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLength ( node ) {
|
|
|
|
var nodeType = node.nodeType;
|
|
|
|
return nodeType === ELEMENT_NODE ?
|
|
|
|
node.childNodes.length : node.length || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function detach ( node ) {
|
|
|
|
var parent = node.parentNode;
|
|
|
|
if ( parent ) {
|
|
|
|
parent.removeChild( node );
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
function replaceWith ( node, node2 ) {
|
|
|
|
var parent = node.parentNode;
|
|
|
|
if ( parent ) {
|
|
|
|
parent.replaceChild( node2, node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function empty ( node ) {
|
|
|
|
var frag = node.ownerDocument.createDocumentFragment(),
|
|
|
|
childNodes = node.childNodes,
|
|
|
|
l = childNodes ? childNodes.length : 0;
|
|
|
|
while ( l-- ) {
|
|
|
|
frag.appendChild( node.firstChild );
|
|
|
|
}
|
|
|
|
return frag;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fixCursor ( node ) {
|
|
|
|
// In Webkit and Gecko, block level elements are collapsed and
|
|
|
|
// unfocussable if they have no content. To remedy this, a <BR> must be
|
|
|
|
// inserted. In Opera and IE, we just need a textnode in order for the
|
|
|
|
// cursor to appear.
|
|
|
|
var doc = node.ownerDocument,
|
2013-04-09 19:21:25 -05:00
|
|
|
root = node,
|
2013-04-07 22:27:06 -05:00
|
|
|
fixer, child;
|
|
|
|
|
|
|
|
if ( node.nodeName === 'BODY' ) {
|
|
|
|
if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) {
|
|
|
|
fixer = doc.createElement( 'DIV' );
|
|
|
|
if ( child ) {
|
|
|
|
node.replaceChild( fixer, child );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.appendChild( fixer );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
node = fixer;
|
|
|
|
fixer = null;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isInline( node ) ) {
|
2014-08-27 20:10:31 -05:00
|
|
|
child = node.firstChild;
|
|
|
|
while ( cantFocusEmptyTextNodes && child &&
|
|
|
|
child.nodeType === TEXT_NODE && !child.data ) {
|
|
|
|
node.removeChild( child );
|
|
|
|
child = node.firstChild;
|
|
|
|
}
|
|
|
|
if ( !child ) {
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( cantFocusEmptyTextNodes ) {
|
|
|
|
fixer = doc.createTextNode( '\u200B' );
|
2013-07-16 02:51:31 -05:00
|
|
|
if ( win.editor ) {
|
2014-04-16 03:06:10 -05:00
|
|
|
win.editor._didAddZWS();
|
2013-07-16 02:51:31 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
} else {
|
|
|
|
fixer = doc.createTextNode( '' );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( useTextFixer ) {
|
|
|
|
while ( node.nodeType !== TEXT_NODE && !isLeaf( node ) ) {
|
|
|
|
child = node.firstChild;
|
|
|
|
if ( !child ) {
|
|
|
|
fixer = doc.createTextNode( '' );
|
|
|
|
break;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
node = child;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( node.nodeType === TEXT_NODE ) {
|
|
|
|
// Opera will collapse the block element if it contains
|
|
|
|
// just spaces (but not if it contains no data at all).
|
|
|
|
if ( /^ +$/.test( node.data ) ) {
|
|
|
|
node.data = '';
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
} else if ( isLeaf( node ) ) {
|
|
|
|
node.parentNode.insertBefore( doc.createTextNode( '' ), node );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
else if ( !node.querySelector( 'BR' ) ) {
|
|
|
|
fixer = doc.createElement( 'BR' );
|
|
|
|
while ( ( child = node.lastElementChild ) && !isInline( child ) ) {
|
|
|
|
node = child;
|
|
|
|
}
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
if ( fixer ) {
|
|
|
|
node.appendChild( fixer );
|
|
|
|
}
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2013-04-09 19:21:25 -05:00
|
|
|
return root;
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function split ( node, offset, stopNode ) {
|
|
|
|
var nodeType = node.nodeType,
|
|
|
|
parent, clone, next;
|
2013-04-09 22:43:31 -05:00
|
|
|
if ( nodeType === TEXT_NODE && node !== stopNode ) {
|
2013-04-07 22:27:06 -05:00
|
|
|
return split( node.parentNode, node.splitText( offset ), stopNode );
|
|
|
|
}
|
|
|
|
if ( nodeType === ELEMENT_NODE ) {
|
|
|
|
if ( typeof( offset ) === 'number' ) {
|
|
|
|
offset = offset < node.childNodes.length ?
|
|
|
|
node.childNodes[ offset ] : null;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2011-11-04 00:53:12 -05:00
|
|
|
if ( node === stopNode ) {
|
2013-04-07 22:27:06 -05:00
|
|
|
return offset;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2011-10-28 22:15:21 -05:00
|
|
|
// Clone node without children
|
2013-06-20 08:15:18 -05:00
|
|
|
parent = node.parentNode;
|
2013-04-07 22:27:06 -05:00
|
|
|
clone = node.cloneNode( false );
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2011-10-28 22:15:21 -05:00
|
|
|
// Add right-hand siblings to the clone
|
2013-04-07 22:27:06 -05:00
|
|
|
while ( offset ) {
|
|
|
|
next = offset.nextSibling;
|
|
|
|
clone.appendChild( offset );
|
|
|
|
offset = next;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2011-10-28 22:15:21 -05:00
|
|
|
// DO NOT NORMALISE. This may undo the fixCursor() call
|
|
|
|
// of a node lower down the tree!
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2011-10-28 22:15:21 -05:00
|
|
|
// We need something in the element in order for the cursor to appear.
|
2013-04-07 22:27:06 -05:00
|
|
|
fixCursor( node );
|
|
|
|
fixCursor( clone );
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2011-10-28 22:15:21 -05:00
|
|
|
// Inject clone after original node
|
|
|
|
if ( next = node.nextSibling ) {
|
|
|
|
parent.insertBefore( clone, next );
|
|
|
|
} else {
|
|
|
|
parent.appendChild( clone );
|
|
|
|
}
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2011-10-28 22:15:21 -05:00
|
|
|
// Keep on splitting up the tree
|
2013-04-07 22:27:06 -05:00
|
|
|
return split( parent, clone, stopNode );
|
|
|
|
}
|
2013-04-09 22:43:31 -05:00
|
|
|
return offset;
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
function mergeInlines ( node, range ) {
|
|
|
|
if ( node.nodeType !== ELEMENT_NODE ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var children = node.childNodes,
|
|
|
|
l = children.length,
|
|
|
|
frags = [],
|
|
|
|
child, prev, len;
|
|
|
|
while ( l-- ) {
|
|
|
|
child = children[l];
|
|
|
|
prev = l && children[ l - 1 ];
|
|
|
|
if ( l && isInline( child ) && areAlike( child, prev ) &&
|
|
|
|
!leafNodeNames[ child.nodeName ] ) {
|
|
|
|
if ( range.startContainer === child ) {
|
|
|
|
range.startContainer = prev;
|
|
|
|
range.startOffset += getLength( prev );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( range.endContainer === child ) {
|
|
|
|
range.endContainer = prev;
|
|
|
|
range.endOffset += getLength( prev );
|
|
|
|
}
|
|
|
|
if ( range.startContainer === node ) {
|
|
|
|
if ( range.startOffset > l ) {
|
|
|
|
range.startOffset -= 1;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
else if ( range.startOffset === l ) {
|
|
|
|
range.startContainer = prev;
|
|
|
|
range.startOffset = getLength( prev );
|
2011-11-01 19:55:08 -05:00
|
|
|
}
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( range.endContainer === node ) {
|
|
|
|
if ( range.endOffset > l ) {
|
|
|
|
range.endOffset -= 1;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
else if ( range.endOffset === l ) {
|
|
|
|
range.endContainer = prev;
|
|
|
|
range.endOffset = getLength( prev );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
detach( child );
|
|
|
|
if ( child.nodeType === TEXT_NODE ) {
|
2014-04-16 03:06:10 -05:00
|
|
|
prev.appendData( child.data );
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
frags.push( empty( child ) );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
else if ( child.nodeType === ELEMENT_NODE ) {
|
|
|
|
len = frags.length;
|
|
|
|
while ( len-- ) {
|
|
|
|
child.appendChild( frags.pop() );
|
|
|
|
}
|
|
|
|
mergeInlines( child, range );
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mergeWithBlock ( block, next, range ) {
|
|
|
|
var container = next,
|
|
|
|
last, offset, _range;
|
|
|
|
while ( container.parentNode.childNodes.length === 1 ) {
|
|
|
|
container = container.parentNode;
|
|
|
|
}
|
|
|
|
detach( container );
|
|
|
|
|
|
|
|
offset = block.childNodes.length;
|
2012-01-24 19:47:26 -05:00
|
|
|
|
2013-04-07 22:27:06 -05:00
|
|
|
// Remove extra <BR> fixer if present.
|
|
|
|
last = block.lastChild;
|
|
|
|
if ( last && last.nodeName === 'BR' ) {
|
|
|
|
block.removeChild( last );
|
|
|
|
offset -= 1;
|
2011-10-28 22:15:21 -05:00
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
|
|
|
|
_range = {
|
|
|
|
startContainer: block,
|
|
|
|
startOffset: offset,
|
|
|
|
endContainer: block,
|
|
|
|
endOffset: offset
|
|
|
|
};
|
|
|
|
|
|
|
|
block.appendChild( empty( next ) );
|
|
|
|
mergeInlines( block, _range );
|
|
|
|
|
|
|
|
range.setStart( _range.startContainer, _range.startOffset );
|
|
|
|
range.collapse( true );
|
|
|
|
|
|
|
|
// Opera inserts a BR if you delete the last piece of text
|
|
|
|
// in a block-level element. Unfortunately, it then gets
|
|
|
|
// confused when setting the selection subsequently and
|
|
|
|
// refuses to accept the range that finishes just before the
|
|
|
|
// BR. Removing the BR fixes the bug.
|
|
|
|
// Steps to reproduce bug: Type "a-b-c" (where - is return)
|
|
|
|
// then backspace twice. The cursor goes to the top instead
|
|
|
|
// of after "b".
|
|
|
|
if ( isOpera && ( last = block.lastChild ) && last.nodeName === 'BR' ) {
|
|
|
|
block.removeChild( last );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mergeContainers ( node ) {
|
|
|
|
var prev = node.previousSibling,
|
2014-04-06 22:05:44 -05:00
|
|
|
first = node.firstChild,
|
2014-06-01 19:17:00 -05:00
|
|
|
doc = node.ownerDocument,
|
2014-05-23 00:26:47 -05:00
|
|
|
isListItem = ( node.nodeName === 'LI' ),
|
2014-05-26 20:31:06 -05:00
|
|
|
needsFix, block;
|
2014-04-06 22:05:44 -05:00
|
|
|
|
|
|
|
// Do not merge LIs, unless it only contains a UL
|
|
|
|
if ( isListItem && ( !first || !/^[OU]L$/.test( first.nodeName ) ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-23 00:26:47 -05:00
|
|
|
if ( prev && areAlike( prev, node ) ) {
|
|
|
|
if ( !isContainer( prev ) ) {
|
|
|
|
if ( isListItem ) {
|
2014-06-01 19:17:00 -05:00
|
|
|
block = doc.createElement( 'DIV' );
|
2014-05-23 00:26:47 -05:00
|
|
|
block.appendChild( empty( prev ) );
|
|
|
|
prev.appendChild( block );
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
detach( node );
|
2014-05-26 20:31:06 -05:00
|
|
|
needsFix = !isContainer( node );
|
2013-04-07 22:27:06 -05:00
|
|
|
prev.appendChild( empty( node ) );
|
2014-05-26 20:31:06 -05:00
|
|
|
if ( needsFix ) {
|
|
|
|
fixContainer( prev );
|
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( first ) {
|
|
|
|
mergeContainers( first );
|
|
|
|
}
|
2014-04-06 22:05:44 -05:00
|
|
|
} else if ( isListItem ) {
|
2014-06-01 19:17:00 -05:00
|
|
|
prev = doc.createElement( 'DIV' );
|
2014-04-06 22:05:44 -05:00
|
|
|
node.insertBefore( prev, first );
|
|
|
|
fixCursor( prev );
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-26 20:31:06 -05:00
|
|
|
// Recursively examine container nodes and wrap any inline children.
|
|
|
|
function fixContainer ( container ) {
|
|
|
|
var children = container.childNodes,
|
|
|
|
doc = container.ownerDocument,
|
|
|
|
wrapper = null,
|
|
|
|
i, l, child, isBR;
|
|
|
|
for ( i = 0, l = children.length; i < l; i += 1 ) {
|
|
|
|
child = children[i];
|
|
|
|
isBR = child.nodeName === 'BR';
|
|
|
|
if ( !isBR && isInline( child ) ) {
|
|
|
|
if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); }
|
|
|
|
wrapper.appendChild( child );
|
|
|
|
i -= 1;
|
|
|
|
l -= 1;
|
|
|
|
} else if ( isBR || wrapper ) {
|
|
|
|
if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); }
|
|
|
|
fixCursor( wrapper );
|
|
|
|
if ( isBR ) {
|
|
|
|
container.replaceChild( wrapper, child );
|
|
|
|
} else {
|
|
|
|
container.insertBefore( wrapper, child );
|
|
|
|
i += 1;
|
|
|
|
l += 1;
|
|
|
|
}
|
|
|
|
wrapper = null;
|
|
|
|
}
|
|
|
|
if ( isContainer( child ) ) {
|
|
|
|
fixContainer( child );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( wrapper ) {
|
|
|
|
container.appendChild( fixCursor( wrapper ) );
|
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:15:18 -05:00
|
|
|
function createElement ( doc, tag, props, children ) {
|
2013-04-07 22:27:06 -05:00
|
|
|
var el = doc.createElement( tag ),
|
2014-04-06 22:05:44 -05:00
|
|
|
attr, value, i, l;
|
2013-04-07 22:27:06 -05:00
|
|
|
if ( props instanceof Array ) {
|
|
|
|
children = props;
|
|
|
|
props = null;
|
|
|
|
}
|
|
|
|
if ( props ) {
|
|
|
|
for ( attr in props ) {
|
2014-04-06 22:05:44 -05:00
|
|
|
value = props[ attr ];
|
|
|
|
if ( value !== undefined ) {
|
|
|
|
el.setAttribute( attr, props[ attr ] );
|
|
|
|
}
|
2013-04-07 22:27:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( children ) {
|
|
|
|
for ( i = 0, l = children.length; i < l; i += 1 ) {
|
|
|
|
el.appendChild( children[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return el;
|
|
|
|
}
|