2012-02-07 19:13:19 +00:00
|
|
|
/**
|
2012-03-06 22:39:43 +00:00
|
|
|
* Creates an ve.ce.DocumentNode object.
|
2012-02-07 19:13:19 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-03-06 22:39:43 +00:00
|
|
|
* @extends {ve.ce.BranchNode}
|
2012-02-07 19:13:19 +00:00
|
|
|
* @param {ve.dm.DocumentNode} documentModel Document model to view
|
2012-03-06 22:39:43 +00:00
|
|
|
* @param {ve.ce.Surface} surfaceView Surface view this view is a child of
|
2012-02-07 19:13:19 +00:00
|
|
|
*/
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce.DocumentNode = function( model, surfaceView ) {
|
2012-02-07 19:13:19 +00:00
|
|
|
// Inheritance
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce.BranchNode.call( this, model );
|
2012-02-07 19:13:19 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.surfaceView = surfaceView;
|
|
|
|
|
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 'es-documentView' );
|
|
|
|
this.$.attr('contentEditable', 'true');
|
2012-02-28 23:43:38 +00:00
|
|
|
this.$.attr('spellcheck', 'true');
|
2012-02-07 19:13:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mapping of symbolic names and splitting rules.
|
|
|
|
*
|
|
|
|
* Each rule is an object with a self and children property. Each of these properties may contain
|
|
|
|
* one of two possible values:
|
|
|
|
* Boolean - Whether a split is allowed
|
|
|
|
* Null - Node is a leaf, so there's nothing to split
|
|
|
|
*
|
|
|
|
* @example Paragraph rules
|
|
|
|
* {
|
|
|
|
* 'self': true
|
|
|
|
* 'children': null
|
|
|
|
* }
|
|
|
|
* @example List rules
|
|
|
|
* {
|
|
|
|
* 'self': false,
|
|
|
|
* 'children': true
|
|
|
|
* }
|
|
|
|
* @example ListItem rules
|
|
|
|
* {
|
|
|
|
* 'self': true,
|
|
|
|
* 'children': false
|
|
|
|
* }
|
|
|
|
*/
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce.DocumentNode.splitRules = {};
|
2012-02-07 19:13:19 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the document offset of a position created from passed DOM event
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param e {Event} Event to create ve.Position from
|
|
|
|
* @returns {Integer} Document offset
|
|
|
|
*/
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce.DocumentNode.prototype.getOffsetFromEvent = function( e ) {
|
2012-02-07 19:13:19 +00:00
|
|
|
var position = ve.Position.newFromEventPagePosition( e );
|
|
|
|
return this.getOffsetFromRenderedPosition( position );
|
|
|
|
};
|
|
|
|
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.ce.DocumentNode.splitRules.document = {
|
2012-02-07 19:13:19 +00:00
|
|
|
'self': false,
|
|
|
|
'children': true
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2012-03-06 22:39:43 +00:00
|
|
|
ve.extendClass( ve.ce.DocumentNode, ve.ce.BranchNode );
|