2013-03-01 01:17:02 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWHeadingNode class.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; 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
|
|
|
|
this.surface = this.root.getSurface().getSurface();
|
|
|
|
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 ) {
|
|
|
|
surface.getModel().getDocument().once( 'transact', function () {
|
|
|
|
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 ) {
|
|
|
|
surface.getModel().getDocument().once( 'transact', function () {
|
|
|
|
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 );
|