Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ce/nodes/ve.ce.MWHeadingNode.js

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