mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 00:00:49 +00:00
Moved "is slug gable" functionality to a static method of ve.ce.BranchNode
Also optimized some query stuff Change-Id: I5675258c6e276a1ba410dcf1ee111392140a04eb
This commit is contained in:
parent
c9dddf60da
commit
e150ba2e54
|
@ -31,6 +31,10 @@ ve.ce.BranchNode = function( type, model, $element ) {
|
|||
}
|
||||
};
|
||||
|
||||
/* Static Members */
|
||||
|
||||
ve.ce.BranchNode.$slugTemplate = $( '<span class="ve-ce-slug"> </span>' );
|
||||
|
||||
/* Static Methods */
|
||||
|
||||
ve.ce.BranchNode.getDomWrapperType = function( model, key ) {
|
||||
|
@ -50,6 +54,26 @@ ve.ce.BranchNode.getDomWrapper = function( model, key ) {
|
|||
return $( '<' + type + '></' + type + '>' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a node can have a slug before or after it.
|
||||
*
|
||||
* TODO: Implement it as a one of node rules instead of a static array
|
||||
*
|
||||
* @static
|
||||
* @method
|
||||
* @param {ve.ce.Node} node Node to check
|
||||
* @returns {Boolean} Node can have a slug
|
||||
*/
|
||||
ve.ce.BranchNode.canNodeHaveSlug = function( node ) {
|
||||
return [
|
||||
'image',
|
||||
'list',
|
||||
'table',
|
||||
'alienInline',
|
||||
'alienBlock'
|
||||
].indexOf( node.getType() ) !== -1;
|
||||
};
|
||||
|
||||
/* Methods */
|
||||
|
||||
ve.ce.BranchNode.prototype.updateDomWrapper = function( key ) {
|
||||
|
@ -114,27 +138,23 @@ ve.ce.BranchNode.prototype.onSplice = function( index, howmany ) {
|
|||
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 ( ve.ce.sluggable.indexOf( this.children[i].type ) !== -1 ) {
|
||||
for ( i = 0; i < this.children.length; i++ ) {
|
||||
if ( ve.ce.BranchNode.canNodeHaveSlug( this.children[i] ) ) {
|
||||
if ( i === 0 ) {
|
||||
// first
|
||||
$slug = $( slug );
|
||||
this.children[i].$.before( $slug );
|
||||
this.$slugs = this.$slugs.add($slug);
|
||||
// First sluggable child (left side)
|
||||
this.$slugs = this.$slugs.add(
|
||||
ve.ce.BranchNode.$slugTemplate.clone().insertBefore( this.children[i].$ )
|
||||
);
|
||||
}
|
||||
if ( i === this.children.length - 1 ) {
|
||||
// last
|
||||
$slug = $( slug );
|
||||
this.children[i].$.after( $slug );
|
||||
this.$slugs = this.$slugs.add($slug);
|
||||
}
|
||||
if ( this.children[i + 1] && ve.ce.sluggable.indexOf( this.children[i + 1].type ) !== -1 ) {
|
||||
// special next to special
|
||||
$slug = $( slug );
|
||||
this.children[i].$.after( $slug );
|
||||
this.$slugs = this.$slugs.add($slug);
|
||||
if (
|
||||
// Last sluggable child (right side)
|
||||
i === this.children.length - 1 ||
|
||||
// Sluggable child followed by another sluggable child (in between)
|
||||
( this.children[i + 1] && ve.ce.BranchNode.canNodeHaveSlug( this.children[i + 1] ) )
|
||||
) {
|
||||
this.$slugs = this.$slugs.add(
|
||||
ve.ce.BranchNode.$slugTemplate.clone().insertAfter( this.children[i].$ )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,23 +7,6 @@ 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