mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
8d33a3de0d
* Made method descriptions imperative: "Do this" rather than "Does this" * Changed use of "this object" to "the object" in method documentation * Added missing documentation * Fixed incorrect documentation * Fixed incorrect debug method names (as in those VeDmClassName tags we add to functions so they make sense when dumped into in the console) * Normalized use of package names throughout * Normalized class descriptions * Removed incorrect @abstract tags * Added missing @method tags * Lots of other minor cleanup Change-Id: I4ea66a2dd107613e2ea3a5f56ff54d675d72957e
134 lines
3.3 KiB
JavaScript
134 lines
3.3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface FormatDropdownTool class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface format dropdown tool.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.DropdownTool
|
|
* @constructor
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
*/
|
|
ve.ui.FormatDropdownTool = function VeUiFormatDropdownTool( toolbar ) {
|
|
// Parent constructor
|
|
ve.ui.DropdownTool.call( this, toolbar, ve.ui.FormatDropdownTool.static.options );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.FormatDropdownTool, ve.ui.DropdownTool );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ui.FormatDropdownTool.static.name = 'format';
|
|
|
|
ve.ui.FormatDropdownTool.static.titleMessage = 'visualeditor-formatdropdown-title';
|
|
|
|
/**
|
|
* Options given to ve.ui.DropdownTool.
|
|
*
|
|
* @static
|
|
* @property
|
|
* @type {Object[]}
|
|
*/
|
|
ve.ui.FormatDropdownTool.static.options = [
|
|
{
|
|
'name': 'paragraph',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-paragraph' ),
|
|
'type' : 'paragraph'
|
|
},
|
|
{
|
|
'name': 'heading-1',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading1' ),
|
|
'type' : 'heading',
|
|
'attributes': { 'level': 1 }
|
|
},
|
|
{
|
|
'name': 'heading-2',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading2' ),
|
|
'type' : 'heading',
|
|
'attributes': { 'level': 2 }
|
|
},
|
|
{
|
|
'name': 'heading-3',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading3' ),
|
|
'type' : 'heading',
|
|
'attributes': { 'level': 3 }
|
|
},
|
|
{
|
|
'name': 'heading-4',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading4' ),
|
|
'type' : 'heading',
|
|
'attributes': { 'level': 4 }
|
|
},
|
|
{
|
|
'name': 'heading-5',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading5' ),
|
|
'type' : 'heading',
|
|
'attributes': { 'level': 5 }
|
|
},
|
|
{
|
|
'name': 'heading-6',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading6' ),
|
|
'type' : 'heading',
|
|
'attributes': { 'level': 6 }
|
|
},
|
|
{
|
|
'name': 'preformatted',
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-preformatted' ),
|
|
'type' : 'preformatted'
|
|
}
|
|
];
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle dropdown option being selected.
|
|
*
|
|
* @method
|
|
* @param {Object} item Menu item
|
|
*/
|
|
ve.ui.FormatDropdownTool.prototype.onSelect = function ( item ) {
|
|
this.toolbar.getSurface().execute( 'format', 'convert', item.type, item.attributes );
|
|
};
|
|
|
|
/**
|
|
* Handle the toolbar state being updated.
|
|
*
|
|
* @method
|
|
* @param {ve.dm.Node[]} nodes List of nodes covered by the current selection
|
|
* @param {ve.AnnotationSet} full Annotations that cover all of the current selection
|
|
* @param {ve.AnnotationSet} partial Annotations that cover some or all of the current selection
|
|
*/
|
|
ve.ui.FormatDropdownTool.prototype.onUpdateState = function ( nodes ) {
|
|
var i, nodesLength, node, j, itemsLength, item,
|
|
items = this.menuView.getItems(),
|
|
matches = [];
|
|
for ( i = 0, nodesLength = nodes.length; i < nodesLength; i++ ) {
|
|
node = nodes[i];
|
|
if ( !node.canHaveChildren() ) {
|
|
node = node.getParent();
|
|
}
|
|
if ( node ) {
|
|
for ( j = 0, itemsLength = items.length; j < itemsLength; j++ ) {
|
|
item = items[j];
|
|
if ( item.type === node.getType() ) {
|
|
if ( item.attributes && !node.hasAttributes( item.attributes ) ) {
|
|
continue;
|
|
}
|
|
matches.push( item );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.setLabel( matches.length === 1 ? matches[0].label : '' );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.toolFactory.register( 'format', ve.ui.FormatDropdownTool );
|