mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 08:10:35 +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
|
// Properties
|
||||||
this.domWrapperElementType = this.$.get(0).nodeName.toLowerCase();
|
this.domWrapperElementType = this.$.get(0).nodeName.toLowerCase();
|
||||||
this.slugs = [];
|
this.$slugs = $();
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.addListenerMethod( this, 'splice', 'onSplice' );
|
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
|
// Remove all slugs in this branch
|
||||||
for ( i = 0; i < this.slugs.length; i++ ) {
|
this.$slugs.remove();
|
||||||
this.slugs[i].remove();
|
|
||||||
}
|
|
||||||
this.slugs = [];
|
|
||||||
|
|
||||||
|
// Iterate over all children of this branch and add slugs in appropriate places
|
||||||
var slug = '<span class="ve-ce-slug"> </span>',
|
var slug = '<span class="ve-ce-slug"> </span>',
|
||||||
$slug;
|
$slug;
|
||||||
|
|
||||||
for( i = 0; i < this.children.length; i++ ) {
|
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 ) {
|
if ( i === 0 ) {
|
||||||
// first
|
// first
|
||||||
$slug = $( slug );
|
$slug = $( slug );
|
||||||
this.slugs.push( $slug );
|
|
||||||
this.children[i].$.before( $slug );
|
this.children[i].$.before( $slug );
|
||||||
|
this.$slugs = this.$slugs.add($slug);
|
||||||
}
|
}
|
||||||
if ( i === this.children.length - 1 ) {
|
if ( i === this.children.length - 1 ) {
|
||||||
// last
|
// last
|
||||||
$slug = $( slug );
|
$slug = $( slug );
|
||||||
this.slugs.push( $slug );
|
|
||||||
this.children[i].$.after( $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
|
// special next to special
|
||||||
$slug = $( slug );
|
$slug = $( slug );
|
||||||
this.slugs.push( $slug );
|
|
||||||
this.children[i].$.after( $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
|
//'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.
|
* RegExp pattern for matching all whitespaces in HTML text.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue