diff --git a/modules/ve/ce/ve.ce.BranchNode.js b/modules/ve/ce/ve.ce.BranchNode.js index 19e65672fc..6704aa447a 100644 --- a/modules/ve/ce/ve.ce.BranchNode.js +++ b/modules/ve/ce/ve.ce.BranchNode.js @@ -197,28 +197,33 @@ ve.ce.BranchNode.prototype.onSplice = function ( index ) { * @method */ ve.ce.BranchNode.prototype.setupSlugs = function () { - var key, $slug, i; + var key, slug, i, len, first, last, doc = this.getElementDocument(); // Remove all slugs in this branch for ( key in this.slugs ) { - this.slugs[key].remove(); + if ( this.slugs[key].parentNode ) { + this.slugs[key].parentNode.removeChild( this.slugs[key] ); + } delete this.slugs[key]; } if ( this.canHaveChildrenNotContent() ) { - $slug = ve.ce.BranchNode.$blockSlugTemplate.clone(); + slug = ve.ce.BranchNode.$blockSlugTemplate[0]; } else { - $slug = ve.ce.BranchNode.$inlineSlugTemplate.clone(); + slug = ve.ce.BranchNode.$inlineSlugTemplate[0]; } if ( this.getLength() === 0 ) { - this.slugs[0] = $slug.clone().appendTo( this.$ ); + this.slugs[0] = doc.importNode( slug, true ); + this.$[0].appendChild( this.slugs[0] ); } else { // Iterate over all children of this branch and add slugs in appropriate places - for ( i = 0; i < this.children.length; i++ ) { + for ( i = 0, len = this.children.length; i < len; i++ ) { // First sluggable child (left side) if ( i === 0 && this.children[i].canHaveSlugBefore() ) { - this.slugs[i] = $slug.clone().insertBefore( this.children[i].$.first() ); + this.slugs[i] = doc.importNode( slug, true ); + first = this.children[i].$[0]; + first.parentNode.insertBefore( this.slugs[i], first ); } if ( this.children[i].canHaveSlugAfter() ) { if ( @@ -227,7 +232,9 @@ ve.ce.BranchNode.prototype.setupSlugs = function () { // Sluggable child followed by another sluggable child (in between) ( this.children[i + 1] && this.children[i + 1].canHaveSlugBefore() ) ) { - this.slugs[i + 1] = $slug.clone().insertAfter( this.children[i].$.last() ); + this.slugs[i + 1] = doc.importNode( slug, true ); + last = this.children[i].$[this.children[i].$.length - 1]; + last.parentNode.insertBefore( this.slugs[i + 1], last.nextSibling ); } } } @@ -239,6 +246,7 @@ ve.ce.BranchNode.prototype.setupSlugs = function () { * * @method * @param {number} offset Offset to get slug at + * @returns {HTMLElement} */ ve.ce.BranchNode.prototype.getSlugAtOffset = function ( offset ) { var i, diff --git a/modules/ve/ce/ve.ce.Document.js b/modules/ve/ce/ve.ce.Document.js index 29d4108436..4dc671fbcb 100644 --- a/modules/ve/ce/ve.ce.Document.js +++ b/modules/ve/ce/ve.ce.Document.js @@ -49,7 +49,7 @@ ve.ce.Document.prototype.getNodeFromOffset = function ( offset ) { * * @method * @param {number} offset Offset to get slug at - * @returns {jQuery} Slug at offset + * @returns {HTMLElement} Slug at offset */ ve.ce.Document.prototype.getSlugAtOffset = function ( offset ) { var node = this.getNodeFromOffset( offset ); @@ -130,9 +130,9 @@ ve.ce.Document.prototype.getRelativeOffset = function ( offset, direction, unit */ ve.ce.Document.prototype.getNodeAndOffset = function ( offset ) { var node, startOffset, current, stack, item, $item, length, - $slug = this.getSlugAtOffset( offset ); - if ( $slug ) { - return { node: $slug[0].childNodes[0], offset: 0 }; + slug = this.getSlugAtOffset( offset ); + if ( slug ) { + return { node: slug, offset: 0 }; } node = this.getNodeFromOffset( offset ); startOffset = node.getOffset() + ( ( node.isWrapped() ) ? 1 : 0 ); diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index 24ed81caa7..539b90d78e 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -967,7 +967,7 @@ ve.ce.Surface.prototype.handleUpOrDownArrowKey = function ( e ) { // Perform programatic handling only for selection that is expanded and backwards according to // model data but not according to browser data. if ( !selection.isCollapsed() && selection.isBackwards() && !rangySelection.isBackwards() ) { - $element = this.documentView.getSlugAtOffset( selection.to ); + $element = $( this.documentView.getSlugAtOffset( selection.to ) ); if ( !$element ) { $element = this.$$( '' ) .html( ' ' )