1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*!
* VisualEditor ContentEditable MWHeadingNode class.
*
* @copyright See AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MW heading node.
*
* @class
* @extends ve.ce.HeadingNode
* @constructor
* @param {ve.dm.MWHeadingNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWHeadingNode = function VeCeMWHeadingNode() {
// Parent constructor
ve.ce.MWHeadingNode.super.apply( this, arguments );
// Events
this.model.connect( this, { update: 'onUpdate' } );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWHeadingNode, ve.ce.HeadingNode );
/* Static Properties */
ve.ce.MWHeadingNode.static.name = 'mwHeading';
/* Methods */
ve.ce.MWHeadingNode.prototype.onSetup = function () {
// Parent method
ve.ce.MWHeadingNode.super.prototype.onSetup.call( this );
// Make reference to the surface
this.surface = this.root && this.root.getSurface().getSurface();
this.rebuildToc();
};
ve.ce.MWHeadingNode.prototype.onTeardown = function () {
// Parent method
ve.ce.MWHeadingNode.super.prototype.onTeardown.call( this );
this.rebuildToc();
};
ve.ce.MWHeadingNode.prototype.onUpdate = function () {
const surface = this.surface;
// Parent method
ve.ce.MWHeadingNode.super.prototype.onUpdate.call( this );
if ( surface && surface.mwTocWidget ) {
surface.getModel().getDocument().once( 'transact', () => {
surface.mwTocWidget.updateNode( this );
} );
}
};
ve.ce.MWHeadingNode.prototype.rebuildToc = function () {
const surface = this.surface;
if ( surface && surface.mwTocWidget ) {
surface.getModel().getDocument().once( 'transact', () => {
surface.mwTocWidget.rebuild();
} );
}
};
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWHeadingNode );
|