mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-11 05:56:11 +00:00
25d00cc777
jshint: * Update to grunt-contrib-jshint v0.10.0 (jshint v2.5.0). * Remove coding style options covered by jscs. * Enable new option "freeze" (prohibits changing native prototypes). http://www.jshint.com/blog/new-in-jshint-oct-2013/#option-freeze * Re-order to match http://www.jshint.com/docs/options/ jscs: * Update to grunt-jscs-checker v0.4.4 (jscs v1.4.5). * Format .jscsrc file in a more spacious way and order the properties less arbitrarily (using the jscs's readme order). * Enforce more details of our coding style * Get rid of the unsable "sticky" operator rules which have been deprecated in favour of using other rules instead that are able to enforce this more accurately. - disallowLeftStickedOperators: Remove deprecated rule. * Ternary covered by requireSpacesInConditionalExpression. * Rest covered by requireSpace{Before,After}BinaryOperators. - requireLeftStickedOperators: Remove deprecated rule. * Comma covered by disallowSpaceBeforeBinaryOperators. - requireRightStickedOperators: Remove deprecated rule. * Logical not (!) covered by disallowSpaceAfterPrefixUnaryOperators. See also If46b94ce1, Ib731f11b1 and I0b0cadbc5 in oojs/core. Also: * Update grunt-contrib-watch to latest upstream version. Change log at https://github.com/gruntjs/grunt-contrib-watch/blob/v0.6.1/CHANGELOG#L1-L17 Change-Id: I6c5a34afea8b05a3dca617897c192594df06ca90
89 lines
2.3 KiB
JavaScript
89 lines
2.3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MWTocItemWidget class.
|
|
*
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an item an item for the MWTocWidget
|
|
*
|
|
* @class
|
|
* @extends OO.ui.Widget
|
|
* @mixins OO.ui.GroupElement
|
|
*
|
|
* @constructor
|
|
* @param {Object} config TOC Item configuration
|
|
* @cfg {ve.ce.Node} node ContentEditable node
|
|
* @cfg {ve.ui.MWTocItemWidget} parent Parent toc item
|
|
* @cfg {string} sectionPrefix TOC item section number
|
|
* @cfg {number} tocLevel Depth level of the TOC item
|
|
* @cfg {number} tocIndex Running count of TOC items
|
|
*
|
|
*/
|
|
ve.ui.MWTocItemWidget = function VeCeMWTocItemWidget( config ) {
|
|
// Parent constructor
|
|
OO.ui.Widget.call( this, config );
|
|
|
|
// Mixin Constructor
|
|
OO.ui.GroupElement.call( this, this.$( '<ul>' ), config );
|
|
|
|
config = config || {};
|
|
|
|
// Properties
|
|
this.node = config.node || null;
|
|
this.parent = config.parent;
|
|
this.sectionPrefix = config.sectionPrefix;
|
|
this.tocLevel = config.tocLevel;
|
|
this.tocIndex = config.tocIndex;
|
|
|
|
// Allows toc items to be optionally associated to a node.
|
|
// For the case of the zero level parent item.
|
|
if ( this.node ) {
|
|
this.$tocNumber = this.$( '<span>' ).addClass( 'tocnumber' )
|
|
.text( this.sectionPrefix );
|
|
this.$tocText = this.$( '<span>' ).addClass( 'toctext' )
|
|
.text( this.node.$element.text() );
|
|
this.$element
|
|
.addClass( 'toclevel-' + this.tocLevel )
|
|
.addClass( 'tocsection-' + this.tocIndex )
|
|
.append( this.$( '<a>' ).append( this.$tocNumber, this.$tocText ) );
|
|
|
|
// Monitor node events
|
|
this.node.model.connect( this, { 'update': 'onUpdate' } );
|
|
}
|
|
this.$element.append( this.$group );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWTocItemWidget, OO.ui.Widget );
|
|
|
|
OO.mixinClass( ve.ui.MWTocItemWidget, OO.ui.GroupElement );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ui.MWTocItemWidget.static.tagName = 'li';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Updates the text of the toc item
|
|
*
|
|
*/
|
|
ve.ui.MWTocItemWidget.prototype.onUpdate = function () {
|
|
// Timeout needed to let the dom element actually update
|
|
setTimeout( ve.bind( function () {
|
|
this.$tocText.text( this.node.$element.text() );
|
|
}, this ), 0 );
|
|
};
|
|
|
|
/**
|
|
* Removes this toc item from its parent
|
|
*
|
|
*/
|
|
ve.ui.MWTocItemWidget.prototype.remove = function () {
|
|
this.node.model.disconnect( this );
|
|
this.parent.removeItems( [this] );
|
|
};
|