From bea881daca86ddd6f4ebe215754fc116b0c2a422 Mon Sep 17 00:00:00 2001 From: Inez Korczynski Date: Wed, 23 May 2012 13:24:49 -0700 Subject: [PATCH] Refactor mechanism of adding slugs in before and after particular nodes in branch Change-Id: I8b3f4a9b27ff09d569f366c32f96e7e8191487c0 --- modules/ve2/ce/ve.ce.BranchNode.js | 21 ++++++++------------- modules/ve2/ce/ve.ce.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/modules/ve2/ce/ve.ce.BranchNode.js b/modules/ve2/ce/ve.ce.BranchNode.js index 6b29fac73b..e5a241771e 100644 --- a/modules/ve2/ce/ve.ce.BranchNode.js +++ b/modules/ve2/ce/ve.ce.BranchNode.js @@ -17,7 +17,7 @@ ve.ce.BranchNode = function( type, model, $element ) { // Properties this.domWrapperElementType = this.$.get(0).nodeName.toLowerCase(); - this.slugs = []; + this.$slugs = $(); // Events this.model.addListenerMethod( this, 'splice', 'onSplice' ); @@ -110,36 +110,31 @@ ve.ce.BranchNode.prototype.onSplice = function( index, howmany ) { } } - var specials = ['image', 'alien', 'list', 'table']; - // Remove all slugs in this branch - for ( i = 0; i < this.slugs.length; i++ ) { - this.slugs[i].remove(); - } - this.slugs = []; + this.$slugs.remove(); + // Iterate over all children of this branch and add slugs in appropriate places var slug = ' ', $slug; - for( i = 0; i < this.children.length; i++ ) { - if ( specials.indexOf( this.children[i].type ) !== -1 ) { + if ( ve.ce.sluggable.indexOf( this.children[i].type ) !== -1 ) { if ( i === 0 ) { // first $slug = $( slug ); - this.slugs.push( $slug ); this.children[i].$.before( $slug ); + this.$slugs = this.$slugs.add($slug); } if ( i === this.children.length - 1 ) { // last $slug = $( slug ); - this.slugs.push( $slug ); this.children[i].$.after( $slug ); + this.$slugs = this.$slugs.add($slug); } - if ( this.children[i + 1] && specials.indexOf( this.children[i + 1].type ) !== -1 ) { + if ( this.children[i + 1] && ve.ce.sluggable.indexOf( this.children[i + 1].type ) !== -1 ) { // special next to special $slug = $( slug ); - this.slugs.push( $slug ); this.children[i].$.after( $slug ); + this.$slugs = this.$slugs.add($slug); } } } diff --git a/modules/ve2/ce/ve.ce.js b/modules/ve2/ce/ve.ce.js index 680eb0b1be..45244eb4ed 100644 --- a/modules/ve2/ce/ve.ce.js +++ b/modules/ve2/ce/ve.ce.js @@ -7,6 +7,23 @@ ve.ce = { //'factory': Initialized in ve.ce.NodeFactory.js }; +/** + * List of all nodes that may need to have "slug" on their left or right side + * For more information look into ve.ce.BrancNode.js + * + * TODO: Implement it as a one of node rules instead of a "global" array + * + * @static + * @member + */ +ve.ce.sluggable = [ + 'image', + 'list', + 'table', + 'alienInline', + 'alienBlock' +]; + /** * RegExp pattern for matching all whitespaces in HTML text. *