2011-11-02 21:00:55 +00:00
|
|
|
/**
|
|
|
|
* Creates an es.HeadingView object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {es.DocumentViewLeafNode}
|
|
|
|
* @param {es.HeadingModel} model Heading model to view
|
|
|
|
*/
|
|
|
|
es.HeadingView = function( model ) {
|
|
|
|
// Inheritance
|
2011-11-02 23:01:35 +00:00
|
|
|
es.DocumentViewLeafNode.call( this, model );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
2011-11-23 23:22:59 +00:00
|
|
|
// Properties
|
|
|
|
this.currentLevelHash = null;
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 'es-headingView' );
|
|
|
|
|
|
|
|
// Events
|
2011-12-07 23:13:57 +00:00
|
|
|
var _this = this;
|
|
|
|
this.model.on( 'update', function() {
|
|
|
|
_this.setClasses();
|
|
|
|
} );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.setClasses();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
es.HeadingView.prototype.setClasses = function() {
|
2011-11-23 23:22:59 +00:00
|
|
|
var level = this.model.getElementAttribute( 'level' );
|
|
|
|
if ( level !== this.currentLevelHash ) {
|
|
|
|
this.currentLevelHash = level;
|
|
|
|
var classes = this.$.attr( 'class' );
|
|
|
|
this.$
|
|
|
|
// Remove any existing level classes
|
|
|
|
.attr( 'class', classes.replace( / ?es-headingView-level[0-9]+/, '' ) )
|
|
|
|
// Add a new level class
|
|
|
|
.addClass( 'es-headingView-level' + level );
|
|
|
|
}
|
2011-11-02 21:00:55 +00:00
|
|
|
};
|
|
|
|
|
2011-11-14 23:59:36 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2011-11-16 18:54:05 +00:00
|
|
|
es.DocumentView.splitRules.heading = {
|
2011-11-14 23:59:36 +00:00
|
|
|
'self': true,
|
|
|
|
'children': null
|
|
|
|
};
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
es.extendClass( es.HeadingView, es.DocumentViewLeafNode );
|