mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
38 lines
906 B
JavaScript
38 lines
906 B
JavaScript
|
/**
|
||
|
* Creates an es.HeadingView object.
|
||
|
*
|
||
|
* @class
|
||
|
* @constructor
|
||
|
* @extends {es.DocumentViewLeafNode}
|
||
|
* @param {es.HeadingModel} model Heading model to view
|
||
|
*/
|
||
|
es.HeadingView = function( model ) {
|
||
|
// Inheritance
|
||
|
es.DocumentViewLeafNode.call( this, model, $( '<h' + model.getElementAttribute( 'level' ) + '>') );
|
||
|
|
||
|
// DOM Changes
|
||
|
this.$.addClass( 'es-headingView' );
|
||
|
|
||
|
// Events
|
||
|
this.on( 'update', this.setClasses );
|
||
|
|
||
|
// Initialization
|
||
|
this.setClasses();
|
||
|
};
|
||
|
|
||
|
/* Methods */
|
||
|
|
||
|
es.HeadingView.prototype.setClasses = function() {
|
||
|
var classes = this.$.attr( 'class' ),
|
||
|
level = this.model.getElementAttribute( 'level' );
|
||
|
this.$
|
||
|
// Remove any existing level classes
|
||
|
.attr( 'class', classes.replace( /es-headingView-level[1-6]/, '' ) )
|
||
|
// Add a new level class
|
||
|
.addClass( 'es-headingView-level' + level );
|
||
|
};
|
||
|
|
||
|
/* Inheritance */
|
||
|
|
||
|
es.extendClass( es.HeadingView, es.DocumentViewLeafNode );
|