https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113189
Revision: 113189
Author: inez
Date: 2012-03-06 22:31:44 +0000 (Tue, 06 Mar 2012)
Log Message:
-----------
Copy files from ve/es to ve/ce and update references
Modified Paths:
--------------
trunk/extensions/VisualEditor/demos/ce/index.php
Added Paths:
-----------
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.HeadingNode.js
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListItemNode.js
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListNode.js
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.PreNode.js
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableCellNode.js
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableNode.js
trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableRowNode.js
trunk/extensions/VisualEditor/modules/ve/ce/ve.es.BranchNode.js
trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Node.js
trunk/extensions/VisualEditor/modules/ve/ce/ve.es.js
Modified: trunk/extensions/VisualEditor/demos/ce/index.php
===================================================================
--- trunk/extensions/VisualEditor/demos/ce/index.php 2012-03-06 22:26:09 UTC
(rev 113188)
+++ trunk/extensions/VisualEditor/demos/ce/index.php 2012-03-06 22:31:44 UTC
(rev 113189)
@@ -119,22 +119,22 @@
<!-- es -->
<script src="../../modules/ve/ce/ve.ce.js"></script>
- <script src="../../modules/ve/es/ve.es.js"></script>
- <script src="../../modules/ve/es/ve.es.Node.js"></script>
- <script src="../../modules/ve/es/ve.es.BranchNode.js"></script>
+ <script src="../../modules/ve/ce/ve.es.js"></script>
+ <script src="../../modules/ve/ce/ve.es.Node.js"></script>
+ <script src="../../modules/ve/ce/ve.es.BranchNode.js"></script>
<script src="../../modules/ve/ce/ve.es.LeafNode.js"></script>
<script src="../../modules/ve/ce/ve.es.Content.js"></script>
<script src="../../modules/ve/ce/ve.es.Surface.js"></script>
<script
src="../../modules/ve/ce/nodes/ve.es.DocumentNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.HeadingNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.HeadingNode.js"></script>
<script
src="../../modules/ve/ce/nodes/ve.es.ParagraphNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.PreNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.ListItemNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.ListNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.TableCellNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.TableNode.js"></script>
- <script
src="../../modules/ve/es/nodes/ve.es.TableRowNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.PreNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.ListItemNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.ListNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.TableCellNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.TableNode.js"></script>
+ <script
src="../../modules/ve/ce/nodes/ve.es.TableRowNode.js"></script>
<!-- ui -->
<script src="../../modules/ve/ui/ve.ui.js"></script>
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.HeadingNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.HeadingNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.HeadingNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,53 @@
+/**
+ * Creates an ve.es.HeadingNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.LeafNode}
+ * @param {ve.dm.HeadingNode} model Heading model to view
+ */
+ve.es.HeadingNode = function( model ) {
+ // Inheritance
+ ve.es.LeafNode.call( this, model );
+
+ // Properties
+ this.currentLevelHash = null;
+
+ // DOM Changes
+ this.$.addClass( 'es-headingView' );
+
+ // Events
+ var _this = this;
+ this.model.on( 'update', function() {
+ _this.setClasses();
+ } );
+
+ // Initialization
+ this.setClasses();
+};
+
+/* Methods */
+
+ve.es.HeadingNode.prototype.setClasses = function() {
+ 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 );
+ }
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.heading = {
+ 'self': true,
+ 'children': null
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.HeadingNode, ve.es.LeafNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListItemNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListItemNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListItemNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,62 @@
+/**
+ * Creates an ve.es.ListItemNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.LeafNode}
+ * @param {ve.dm.ListItemNode} model List item model to view
+ */
+ve.es.ListItemNode = function( model ) {
+ // Inheritance
+ ve.es.BranchNode.call( this, model );
+
+ // Properties
+ this.$icon = $( '<div class="es-listItemView-icon"></div>' ).prependTo(
this.$ );
+ this.currentStylesHash = null;
+
+ // DOM Changes
+ this.$.addClass( 'es-listItemView' );
+
+ // Events
+ var _this = this;
+ this.model.on( 'update', function() {
+ _this.setClasses();
+ } );
+
+ // Initialization
+ this.setClasses();
+};
+
+/* Methods */
+
+ve.es.ListItemNode.prototype.setClasses = function() {
+ var styles = this.model.getElementAttribute( 'styles' ),
+ stylesHash = styles.join( '|' );
+ if ( this.currentStylesHash !== stylesHash ) {
+ this.currentStylesHash = stylesHash;
+ var classes = this.$.attr( 'class' );
+ this.$
+ // Remove any existing level classes
+ .attr(
+ 'class',
+ classes
+ .replace( /
?es-listItemView-level[0-9]+/, '' )
+ .replace( /
?es-listItemView-(bullet|number|term|definition)/, '' )
+ )
+ // Set the list style class from the style on top of
the stack
+ .addClass( 'es-listItemView-' + styles[styles.length -
1] )
+ // Set the list level class from the length of the stack
+ .addClass( 'es-listItemView-level' + ( styles.length -
1 ) );
+ }
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.listItem = {
+ 'self': true,
+ 'children': false
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.ListItemNode, ve.es.BranchNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.ListNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,62 @@
+/**
+ * Creates an ve.es.ListNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.BranchNode}
+ * @param {ve.dm.ListNode} model List model to view
+ */
+ve.es.ListNode = function( model ) {
+ // Inheritance
+ ve.es.BranchNode.call( this, model );
+
+ // DOM Changes
+ this.$.addClass( 'es-listView' );
+
+ // Events
+ var _this = this;
+ this.model.on( 'update', function() {
+ _this.enumerate();
+ } );
+
+ // Initialization
+ this.enumerate();
+};
+
+/* Methods */
+
+/**
+ * Set the number labels of all ordered list items.
+ *
+ * @method
+ */
+ve.es.ListNode.prototype.enumerate = function() {
+ var styles,
+ levels = [];
+ for ( var i = 0; i < this.children.length; i++ ) {
+ styles = this.children[i].model.getElementAttribute( 'styles' );
+ levels = levels.slice( 0, styles.length );
+ if ( styles[styles.length - 1] === 'number' ) {
+ if ( !levels[styles.length - 1] ) {
+ levels[styles.length - 1] = 0;
+ }
+ this.children[i].$icon.text( ++levels[styles.length -
1] + '.' );
+ } else {
+ this.children[i].$icon.text( '' );
+ if ( levels[styles.length - 1] ) {
+ levels[styles.length - 1] = 0;
+ }
+ }
+ }
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.list = {
+ 'self': false,
+ 'children': true
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.ListNode, ve.es.BranchNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.PreNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.PreNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.PreNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,26 @@
+/**
+ * Creates an ve.es.PreNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.LeafNode}
+ * @param {ve.dm.PreNode} model Pre model to view
+ */
+ve.es.PreNode = function( model ) {
+ // Inheritance
+ ve.es.LeafNode.call( this, model, undefined, { 'pre': true } );
+
+ // DOM Changes
+ this.$.addClass( 'es-preView' );
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.pre = {
+ 'self': true,
+ 'children': null
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.PreNode, ve.es.LeafNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableCellNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableCellNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableCellNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,28 @@
+/**
+ * Creates an ve.es.TableCellNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.BranchNode}
+ * @param {ve.dm.TableCellNode} model Table cell model to view
+ */
+ve.es.TableCellNode = function( model ) {
+ // Inheritance
+ ve.es.BranchNode.call( this, model, $( '<td>' ) );
+
+ // DOM Changes
+ this.$
+ .attr( 'style', model.getElementAttribute( 'html/style' ) )
+ .addClass( 'es-tableCellView' );
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.tableCell = {
+ 'self': false,
+ 'children': true
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.TableCellNode, ve.es.BranchNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,28 @@
+/**
+ * Creates an ve.es.TableNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.BranchNode}
+ * @param {ve.dm.TableNode} model Table model to view
+ */
+ve.es.TableNode = function( model ) {
+ // Inheritance
+ ve.es.BranchNode.call( this, model, $( '<table>' ) );
+
+ // DOM Changes
+ this.$
+ .attr( 'style', model.getElementAttribute( 'html/style' ) )
+ .addClass( 'es-tableView' );
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.table = {
+ 'self': false,
+ 'children': false
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.TableNode, ve.es.BranchNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableRowNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableRowNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/nodes/ve.es.TableRowNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,28 @@
+/**
+ * Creates an ve.es.TableRowNode object.
+ *
+ * @class
+ * @constructor
+ * @extends {ve.es.BranchNode}
+ * @param {ve.dm.TableRowNode} model Table row model to view
+ */
+ve.es.TableRowNode = function( model ) {
+ // Inheritance
+ ve.es.BranchNode.call( this, model, $( '<tr>' ), true );
+
+ // DOM Changes
+ this.$
+ .attr( 'style', model.getElementAttribute( 'html/style' ) )
+ .addClass( 'es-tableRowView' );
+};
+
+/* Registration */
+
+ve.es.DocumentNode.splitRules.tableRow = {
+ 'self': false,
+ 'children': false
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.TableRowNode, ve.es.BranchNode );
Added: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.BranchNode.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/ve.es.BranchNode.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/ve.es.BranchNode.js
2012-03-06 22:31:44 UTC (rev 113189)
@@ -0,0 +1,272 @@
+/**
+ * Creates an ve.es.BranchNode object.
+ *
+ * @class
+ * @abstract
+ * @constructor
+ * @extends {ve.BranchNode}
+ * @extends {ve.es.Node}
+ * @param model {ve.ModelNode} Model to observe
+ * @param {jQuery} [$element] Element to use as a container
+ */
+ve.es.BranchNode = function( model, $element, horizontal ) {
+ // Inheritance
+ ve.BranchNode.call( this );
+ ve.es.Node.call( this, model, $element );
+
+ // Properties
+ this.horizontal = horizontal || false;
+
+ if ( model ) {
+ // Append existing model children
+ var childModels = model.getChildren();
+ for ( var i = 0; i < childModels.length; i++ ) {
+ this.onAfterPush( childModels[i] );
+ }
+
+ // Observe and mimic changes on model
+ this.model.addListenerMethods( this, {
+ 'afterPush': 'onAfterPush',
+ 'afterUnshift': 'onAfterUnshift',
+ 'afterPop': 'onAfterPop',
+ 'afterShift': 'onAfterShift',
+ 'afterSplice': 'onAfterSplice',
+ 'afterSort': 'onAfterSort',
+ 'afterReverse': 'onAfterReverse'
+ } );
+ }
+};
+
+/* Methods */
+
+ve.es.BranchNode.prototype.onAfterPush = function( childModel ) {
+ var childView = childModel.createView();
+ this.emit( 'beforePush', childView );
+ childView.attach( this );
+ childView.on( 'update', this.emitUpdate );
+ // Update children
+ this.children.push( childView );
+ // Update DOM
+ this.$.append( childView.$ );
+ // TODO: adding and deleting classes has to be implemented for unshift,
shift, splice, sort
+ // and reverse as well
+ if ( this.children.length === 1 ) {
+ childView.$.addClass('es-viewBranchNode-firstChild');
+ }
+ this.emit( 'afterPush', childView );
+ this.emit( 'update' );
+};
+
+ve.es.BranchNode.prototype.onAfterUnshift = function( childModel ) {
+ var childView = childModel.createView();
+ this.emit( 'beforeUnshift', childView );
+ childView.attach( this );
+ childView.on( 'update', this.emitUpdate );
+ // Update children
+ this.children.unshift( childView );
+ // Update DOM
+ this.$.prepend( childView.$ );
+ this.emit( 'afterUnshift', childView );
+ this.emit( 'update' );
+};
+
+ve.es.BranchNode.prototype.onAfterPop = function() {
+ this.emit( 'beforePop' );
+ // Update children
+ var childView = this.children.pop();
+ childView.detach();
+ childView.removeEventListener( 'update', this.emitUpdate );
+ // Update DOM
+ childView.$.detach();
+ this.emit( 'afterPop' );
+ this.emit( 'update' );
+};
+
+ve.es.BranchNode.prototype.onAfterShift = function() {
+ this.emit( 'beforeShift' );
+ // Update children
+ var childView = this.children.shift();
+ childView.detach();
+ childView.removeEventListener( 'update', this.emitUpdate );
+ // Update DOM
+ childView.$.detach();
+ this.emit( 'afterShift' );
+ this.emit( 'update' );
+};
+
+ve.es.BranchNode.prototype.onAfterSplice = function( index, howmany ) {
+ var i,
+ length,
+ args = Array.prototype.slice.call( arguments, 0 );
+ // Convert models to views and attach them to this node
+ if ( args.length >= 3 ) {
+ for ( i = 2, length = args.length; i < length; i++ ) {
+ args[i] = args[i].createView();
+ }
+ }
+ this.emit.apply( this, ['beforeSplice'].concat( args ) );
+ var removals = this.children.splice.apply( this.children, args );
+ for ( i = 0, length = removals.length; i < length; i++ ) {
+ removals[i].detach();
+ removals[i].removeListener( 'update', this.emitUpdate );
+ // Update DOM
+ removals[i].$.detach();
+ }
+ if ( args.length >= 3 ) {
+ var $target;
+ if ( index ) {
+ // Get the element before the insertion point
+ $anchor = this.$.children().eq( index - 1 );
+ }
+ for ( i = args.length - 1; i >= 2; i-- ) {
+ args[i].attach( this );
+ args[i].on( 'update', this.emitUpdate );
+ if ( index ) {
+ $anchor.after( args[i].$ );
+ } else {
+ this.$.prepend( args[i].$ );
+ }
+ }
+ }
+ this.emit.apply( this, ['afterSplice'].concat( args ) );
+ if ( args.length >= 3 ) {
+ for ( i = 2, length = args.length; i < length; i++ ) {
+ args[i].renderContent();
+ }
+ }
+ this.emit( 'update' );
+};
+
+ve.es.BranchNode.prototype.onAfterSort = function() {
+ this.emit( 'beforeSort' );
+ var childModels = this.model.getChildren();
+ for ( var i = 0; i < childModels.length; i++ ) {
+ for ( var j = 0; j < this.children.length; j++ ) {
+ if ( this.children[j].getModel() === childModels[i] ) {
+ var childView = this.children[j];
+ // Update children
+ this.children.splice( j, 1 );
+ this.children.push( childView );
+ // Update DOM
+ this.$.append( childView.$ );
+ }
+ }
+ }
+ this.emit( 'afterSort' );
+ this.emit( 'update' );
+ this.renderContent();
+};
+
+ve.es.BranchNode.prototype.onAfterReverse = function() {
+ this.emit( 'beforeReverse' );
+ // Update children
+ this.reverse();
+ // Update DOM
+ this.$.children().each( function() {
+ $(this).prependTo( $(this).parent() );
+ } );
+ this.emit( 'afterReverse' );
+ this.emit( 'update' );
+ this.renderContent();
+};
+
+/**
+ * Render content.
+ *
+ * @method
+ */
+ve.es.BranchNode.prototype.renderContent = function() {
+ for ( var i = 0; i < this.children.length; i++ ) {
+ this.children[i].renderContent();
+ }
+};
+
+/**
+ * Draw selection around a given range.
+ *
+ * @method
+ * @param {ve.Range} range Range of content to draw selection around
+ */
+ve.es.BranchNode.prototype.drawSelection = function( range ) {
+ var selectedNodes = this.selectNodes( range, true );
+ for ( var i = 0; i < this.children.length; i++ ) {
+ if ( selectedNodes.length && this.children[i] ===
selectedNodes[0].node ) {
+ for ( var j = 0; j < selectedNodes.length; j++ ) {
+ selectedNodes[j].node.drawSelection(
selectedNodes[j].range );
+ }
+ i += selectedNodes.length - 1;
+ } else {
+ this.children[i].clearSelection();
+ }
+ }
+};
+
+/**
+ * Clear selection.
+ *
+ * @method
+ */
+ve.es.BranchNode.prototype.clearSelection = function() {
+ for ( var i = 0; i < this.children.length; i++ ) {
+ this.children[i].clearSelection();
+ }
+};
+
+/**
+ * Gets the nearest offset of a rendered position.
+ *
+ * @method
+ * @param {ve.Position} position Position to get offset for
+ * @returns {Integer} Offset of position
+ */
+ve.es.BranchNode.prototype.getOffsetFromRenderedPosition = function( position
) {
+ if ( this.children.length === 0 ) {
+ return 0;
+ }
+ var node = this.children[0];
+ for ( var i = 1; i < this.children.length; i++ ) {
+ if ( this.horizontal && this.children[i].$.offset().left >
position.left ) {
+ break;
+ } else if ( !this.horizontal && this.children[i].$.offset().top
> position.top ) {
+ break;
+ }
+ node = this.children[i];
+ }
+ return node.getParent().getOffsetFromNode( node, true ) +
+ node.getOffsetFromRenderedPosition( position ) + 1;
+};
+
+/**
+ * Gets rendered position of offset within content.
+ *
+ * @method
+ * @param {Integer} offset Offset to get position for
+ * @returns {ve.Position} Position of offset
+ */
+ve.es.BranchNode.prototype.getRenderedPositionFromOffset = function( offset,
leftBias ) {
+ var node = this.getNodeFromOffset( offset, true );
+ if ( node !== null ) {
+ return node.getRenderedPositionFromOffset(
+ offset - this.getOffsetFromNode( node, true ) - 1,
+ leftBias
+ );
+ }
+ return null;
+};
+
+ve.es.BranchNode.prototype.getRenderedLineRangeFromOffset = function( offset )
{
+ var node = this.getNodeFromOffset( offset, true );
+ if ( node !== null ) {
+ var nodeOffset = this.getOffsetFromNode( node, true );
+ return ve.Range.newFromTranslatedRange(
+ node.getRenderedLineRangeFromOffset( offset -
nodeOffset - 1 ),
+ nodeOffset + 1
+ );
+ }
+ return null;
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.BranchNode, ve.BranchNode );
+ve.extendClass( ve.es.BranchNode, ve.es.Node );
Added: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Node.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Node.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Node.js 2012-03-06
22:31:44 UTC (rev 113189)
@@ -0,0 +1,107 @@
+/**
+ * Creates an ve.es.Node object.
+ *
+ * @class
+ * @abstract
+ * @constructor
+ * @extends {ve.Node}
+ * @param {ve.dm.Node} model Model to observe
+ * @param {jQuery} [$element=$( '<div></div>' )] Element to use as a container
+ */
+ve.es.Node = function( model, $element ) {
+ // Inheritance
+ ve.Node.call( this );
+
+ // Properties
+ this.model = model;
+ this.parent = null;
+ this.$ = $element || $( '<div/>' );
+};
+
+/* Methods */
+
+/**
+ * Gets the length of the element in the model.
+ *
+ * @method
+ * @see {ve.Node.prototype.getElementLength}
+ * @returns {Integer} Length of content
+ */
+ve.es.Node.prototype.getElementLength = function() {
+ return this.model.getElementLength();
+};
+
+/**
+ * Gets the length of the content in the model.
+ *
+ * @method
+ * @see {ve.Node.prototype.getContentLength}
+ * @returns {Integer} Length of content
+ */
+ve.es.Node.prototype.getContentLength = function() {
+ return this.model.getContentLength();
+};
+
+/**
+ * Attaches node as a child to another node.
+ *
+ * @method
+ * @param {ve.es.Node} parent Node to attach to
+ * @emits attach (parent)
+ */
+ve.es.Node.prototype.attach = function( parent ) {
+ this.parent = parent;
+ this.emit( 'attach', parent );
+};
+
+/**
+ * Detaches node from it's parent.
+ *
+ * @method
+ * @emits detach (parent)
+ */
+ve.es.Node.prototype.detach = function() {
+ var parent = this.parent;
+ this.parent = null;
+ this.emit( 'detach', parent );
+};
+
+/**
+ * Gets a reference to this node's parent.
+ *
+ * @method
+ * @returns {ve.es.Node} Reference to this node's parent
+ */
+ve.es.Node.prototype.getParent = function() {
+ return this.parent;
+};
+
+/**
+ * Gets a reference to the model this node observes.
+ *
+ * @method
+ * @returns {ve.dm.Node} Reference to the model this node observes
+ */
+ve.es.Node.prototype.getModel = function() {
+ return this.model;
+};
+
+ve.es.Node.getSplitableNode = function( node ) {
+ var splitableNode = null;
+
+ ve.Node.traverseUpstream( node, function( node ) {
+ var elementType = node.model.getElementType();
+ if (
+ splitableNode !== null &&
+ ve.es.DocumentNode.splitRules[ elementType ].children
=== true
+ ) {
+ return false;
+ }
+ splitableNode = ve.es.DocumentNode.splitRules[ elementType
].self ? node : null;
+ } );
+ return splitableNode;
+};
+
+/* Inheritance */
+
+ve.extendClass( ve.es.Node, ve.Node );
Added: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/ve.es.js
(rev 0)
+++ trunk/extensions/VisualEditor/modules/ve/ce/ve.es.js 2012-03-06
22:31:44 UTC (rev 113189)
@@ -0,0 +1,8 @@
+/**
+ * VisualEditor EditSurface namespace.
+ *
+ * All classes and functions will be attached to this object to keep the
global namespace clean.
+ */
+ve.es = {
+
+};
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs