Debian Codegraph @

extensions/Cite/modules/ve-cite/ve.ui.MWCitationDialogTool.js

raw symbols SCIP
1 'use strict';
2
3 /*!
4 * VisualEditor MediaWiki UserInterface citation dialog tool class.
5 *
6 * @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
7 * @license MIT
8 */
9
10 /**
11 * MediaWiki UserInterface citation dialog tool.
12 *
13 * @abstract
14 * @constructor
15 * @extends ve.ui.MWReferenceDialogTool
16 * @param {OO.ui.Toolbar} toolbar
17 * @param {Object} [config] Configuration options
18 */
19 ve.ui.MWCitationDialogTool = function VeUiMWCitationDialogTool( toolbar, config ) {
20 // Parent method
21 ve.ui.MWCitationDialogTool.super.call( this, toolbar, config );
22 };
23
24 /* Inheritance */
25
26 OO.inheritClass( ve.ui.MWCitationDialogTool, ve.ui.MWReferenceDialogTool );
27
28 /* Static Properties */
29 ve.ui.MWCitationDialogTool.static.group = 'cite';
30
31 /**
32 * Only display tool for single-template transclusions of these templates.
33 *
34 * @property {string|string[]|null}
35 * @static
36 * @inheritable
37 */
38 ve.ui.MWCitationDialogTool.static.template = null;
39
40 /* Static Methods */
41
42 /**
43 * @override
44 */
45 ve.ui.MWCitationDialogTool.static.isCompatibleWith = function ( model ) {
46 const compatible = ve.ui.MWCitationDialogTool.super.static.isCompatibleWith.call( this, model );
47
48 if ( compatible && this.template ) {
49 // Check if content of the reference node contains only a template with the same name as
50 // this.template
51 const internalItem = model.getInternalItem();
52 const branches = internalItem ? internalItem.getChildren() : [];
53 if ( branches.length === 1 && branches[ 0 ].canContainContent() ) {
54 const leaves = branches[ 0 ].getChildren();
55 if ( leaves.length === 1 && leaves[ 0 ] instanceof ve.dm.MWTransclusionNode ) {
56 return leaves[ 0 ].isSingleTemplate( this.template );
57 }
58 }
59 return false;
60 }
61
62 return compatible;
63 };