mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
Refactor mechanism of adding slugs in before and after particular nodes in branch
Change-Id: I8b3f4a9b27ff09d569f366c32f96e7e8191487c0
This commit is contained in:
parent
cce32103ff
commit
bea881daca
|
@ -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 = '<span class="ve-ce-slug"> </span>',
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue