2013-03-01 01:17:02 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWHeadingNode class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-03-01 01:17:02 +00:00
|
|
|
* @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
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-03-01 01:17:02 +00:00
|
|
|
*/
|
2016-07-06 14:16:00 +00:00
|
|
|
ve.ce.MWHeadingNode = function VeCeMWHeadingNode() {
|
2013-03-01 01:17:02 +00:00
|
|
|
// Parent constructor
|
2016-07-06 14:16:00 +00:00
|
|
|
ve.ce.MWHeadingNode.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.model.connect( this, { update: 'onUpdate' } );
|
2013-03-01 01:17:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ce.MWHeadingNode, ve.ce.HeadingNode );
|
2013-03-01 01:17:02 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2013-05-28 11:31:41 +00:00
|
|
|
ve.ce.MWHeadingNode.static.name = 'mwHeading';
|
2013-03-01 01:17:02 +00:00
|
|
|
|
2014-01-09 01:32:13 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ve.ce.MWHeadingNode.prototype.onSetup = function () {
|
|
|
|
// Parent method
|
2016-08-22 21:18:30 +00:00
|
|
|
ve.ce.MWHeadingNode.super.prototype.onSetup.call( this );
|
2014-01-09 01:32:13 +00:00
|
|
|
|
|
|
|
// Make reference to the surface
|
2021-08-26 19:35:19 +00:00
|
|
|
this.surface = this.root && this.root.getSurface().getSurface();
|
2014-01-09 01:32:13 +00:00
|
|
|
this.rebuildToc();
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ce.MWHeadingNode.prototype.onTeardown = function () {
|
|
|
|
// Parent method
|
2016-08-22 21:18:30 +00:00
|
|
|
ve.ce.MWHeadingNode.super.prototype.onTeardown.call( this );
|
2014-01-09 01:32:13 +00:00
|
|
|
|
|
|
|
this.rebuildToc();
|
|
|
|
};
|
|
|
|
|
2016-07-06 14:16:00 +00:00
|
|
|
ve.ce.MWHeadingNode.prototype.onUpdate = function () {
|
|
|
|
var surface = this.surface,
|
|
|
|
node = this;
|
|
|
|
|
2016-08-22 21:18:30 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ce.MWHeadingNode.super.prototype.onUpdate.call( this );
|
|
|
|
|
2016-07-06 14:16:00 +00:00
|
|
|
if ( surface && surface.mwTocWidget ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
surface.getModel().getDocument().once( 'transact', () => {
|
2016-07-06 14:16:00 +00:00
|
|
|
surface.mwTocWidget.updateNode( node );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-09 01:32:13 +00:00
|
|
|
ve.ce.MWHeadingNode.prototype.rebuildToc = function () {
|
2016-07-06 14:16:00 +00:00
|
|
|
var surface = this.surface;
|
|
|
|
|
|
|
|
if ( surface && surface.mwTocWidget ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
surface.getModel().getDocument().once( 'transact', () => {
|
2016-07-06 14:16:00 +00:00
|
|
|
surface.mwTocWidget.rebuild();
|
|
|
|
} );
|
2014-01-09 01:32:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-01 01:17:02 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWHeadingNode );
|