http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98810

Revision: 98810
Author:   tparscal
Date:     2011-10-03 21:47:45 +0000 (Mon, 03 Oct 2011)
Log Message:
-----------
Cleanup of extension and inheritance

Modified Paths:
--------------
    trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js
    trunk/parsers/wikidom/lib/hype/bases/es.EventEmitter.js
    trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js
    trunk/parsers/wikidom/lib/hype/bases/es.ViewNode.js
    trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
    trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js
    trunk/parsers/wikidom/lib/hype/models/es.ListModel.js
    trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js
    trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js
    trunk/parsers/wikidom/lib/hype/models/es.TableModel.js
    trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js
    trunk/parsers/wikidom/tests/hype/es.ModelNode.test.js
    trunk/parsers/wikidom/tests/hype/index.html

Added Paths:
-----------
    trunk/parsers/wikidom/lib/hype/es.Range.js

Modified: trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js        
2011-10-03 21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js        
2011-10-03 21:47:45 UTC (rev 98810)
@@ -10,15 +10,55 @@
  * @property {Integer} contentLength Length of content
  */
 es.DocumentModelNode = function( contentLength ) {
-       // Inheritance
-       es.ModelNode.call( this );
+       // Extension
+       var node = $.extend( new es.ModelNode(), this );
        
        // Properties
-       this.contentLength = contentLength || 0;
+       node.contentLength = contentLength || 0;
+       
+       // Observe add and remove operations to keep lengths up to date
+       node.addListenerMethods( node, {
+               'beforePush': 'onBeforePush',
+               'beforeUnshift': 'onBeforeUnshift',
+               'beforePop': 'onBeforePop',
+               'beforeShift': 'onBeforeShift',
+               'beforeSplice': 'onBeforeSplice'
+       } );
+       
+       return node;
 };
 
 /* Methods */
 
+es.DocumentModelNode.prototype.onBeforePush = function( childModel ) {
+       this.adjustContentLength( childModel.getElementLength() );
+};
+
+es.DocumentModelNode.prototype.onBeforeUnshift = function( childModel ) {
+       this.adjustContentLength( childModel.getElementLength() );
+};
+
+es.DocumentModelNode.prototype.onBeforePop = function() {
+       this.adjustContentLength( -this[this.length - 1].getElementLength() );
+};
+
+es.DocumentModelNode.prototype.onBeforeShift = function() {
+       this.adjustContentLength( -this[0].getElementLength() );
+};
+
+es.DocumentModelNode.prototype.onBeforeSplice = function( index, howmany ) {
+       var diff = 0,
+               removed = this.slice( index, index + howmany ),
+               added = Array.prototype.slice.call( arguments, 2 );
+       for ( var i = 0; i < removed.length; i++ ) {
+               diff -= removed[i].getElementLength();
+       }
+       for ( var i = 0; i < added.length; i++ ) {
+               diff += added[i].getElementLength();
+       }
+       this.adjustContentLength( diff );
+};
+
 /**
  * Sets the content length.
  * 
@@ -26,7 +66,7 @@
  * @param {Integer} contentLength Length of content
  * @throws Invalid content length error if contentLength is less than 0
  */
-es.DocumentModelNode.setContentLength = function( contentLength ) {
+es.DocumentModelNode.prototype.setContentLength = function( contentLength ) {
        if ( contentLength < 0 ) {
                throw 'Invalid content length error. Content length can not be 
less than 0.';
        }
@@ -44,7 +84,7 @@
  * @param {Integer} adjustment Amount to adjust content length by
  * @throws Invalid adjustment error if resulting length is less than 0
  */
-es.DocumentModelNode.adjustContentLength = function( adjustment ) {
+es.DocumentModelNode.prototype.adjustContentLength = function( adjustment ) {
        this.contentLength += adjustment;
        // Make sure the adjustment was sane
        if ( this.contentLength < 0 ) {
@@ -61,13 +101,23 @@
 /**
  * Gets the content length.
  * 
+ * If the content length has not been set or evaluated yet, this will cause it 
to be evaluated.
+ * 
  * @method
  * @returns {Integer} Length of content
  */
-es.DocumentModelNode.getContentLength = function() {
+es.DocumentModelNode.prototype.getContentLength = function() {
        return this.contentLength;
 };
 
-/* Inheritance */
-
-es.extend( es.DocumentModelNode, es.ModelNode );
+/**
+ * Gets the element length.
+ * 
+ * If the content length has not been set or evaluated yet, this will cause it 
to be evaluated.
+ * 
+ * @method
+ * @returns {Integer} Length of element
+ */
+es.DocumentModelNode.prototype.getElementLength = function() {
+       return this.contentLength + 2;
+};

Modified: trunk/parsers/wikidom/lib/hype/bases/es.EventEmitter.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/bases/es.EventEmitter.js     2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/bases/es.EventEmitter.js     2011-10-03 
21:47:45 UTC (rev 98810)
@@ -81,7 +81,11 @@
 es.EventEmitter.prototype.addListenerMethods = function( context, methods ) {
        for ( var event in methods ) {
                this.addListener( event, function() {
-                       context[methods[event]].apply( context, 
Array.prototype.slice( arguments, 1 ) );
+                       if ( methods[event] in context ) {
+                               context[methods[event]].apply( context, 
Array.prototype.slice( arguments, 1 ) );
+                       } else {
+                               throw 'Listener method error. Context has no 
such method: ' + methods[event];
+                       }
                } );
        }
        return this;

Modified: trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js        2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js        2011-10-03 
21:47:45 UTC (rev 98810)
@@ -14,15 +14,16 @@
 es.ModelNode = function( children ) {
        // Inheritance
        es.EventEmitter.call( this );
-       var node = $.isArray( children ) ? children : [];
        
+       // Extension
+       var node = $.extend( $.isArray( children ) ? children : [], this )
+       
        // Reusable function for passing update events upstream
-       this.emitUpdate = function() {
+       node.emitUpdate = function() {
                node.emit( 'update' );
        };
        
-       // Extend native array with method and properties of this
-       return $.extend( node, this );
+       return node;
 };
 
 /* Methods */
@@ -33,14 +34,16 @@
  * @method
  * @param {es.ModelItem} childModel Item to add
  * @returns {Integer} New number of children
- * @emits push (childModel)
+ * @emits beforePush (childModel)
+ * @emits afterPush (childModel)
  * @emits update
  */
 es.ModelNode.prototype.push = function( childModel ) {
+       this.emit( 'beforePush', childModel );
        childModel.attach( this );
        childModel.on( 'update', this.emitUpdate );
        Array.prototype.push.call( this, childModel );
-       this.emit( 'push', childModel );
+       this.emit( 'afterPush', childModel );
        this.emit( 'update' );
        return this.length;
 };
@@ -51,14 +54,16 @@
  * @method
  * @param {es.ModelItem} childModel Item to add
  * @returns {Integer} New number of children
- * @emits unshift (childModel)
+ * @emits beforeUnshift (childModel)
+ * @emits afterUnshift (childModel)
  * @emits update
  */
 es.ModelNode.prototype.unshift = function( childModel ) {
+       this.emit( 'beforeUnshift', childModel );
        childModel.attach( this );
        childModel.on( 'update', this.emitUpdate );
        Array.prototype.unshift.call( this, childModel );
-       this.emit( 'unshift', childModel );
+       this.emit( 'afterUnshift', childModel );
        this.emit( 'update' );
        return this.length;
 };
@@ -68,16 +73,18 @@
  * 
  * @method
  * @returns {Integer} Removed childModel
- * @emits pop
+ * @emits beforePop
+ * @emits afterPop
  * @emits update
  */
 es.ModelNode.prototype.pop = function() {
        if ( this.length ) {
+               this.emit( 'beforePop' );
                var childModel = this[this.length - 1];
                childModel.detach();
                childModel.removeListener( 'update', this.emitUpdate );
                Array.prototype.pop.call( this, childModel );
-               this.emit( 'pop' );
+               this.emit( 'afterPop' );
                this.emit( 'update' );
                return childModel;
        }
@@ -88,16 +95,18 @@
  * 
  * @method
  * @returns {Integer} Removed childModel
- * @emits shift
+ * @emits beforeShift
+ * @emits afterShift
  * @emits update
  */
 es.ModelNode.prototype.shift = function() {
        if ( this.length ) {
+               this.emit( 'beforeShift' );
                var childModel = this[0];
                childModel.detach();
                childModel.removeListener( 'update', this.emitUpdate );
                Array.prototype.shift.call( this, childModel );
-               this.emit( 'shift' );
+               this.emit( 'afterShift' );
                this.emit( 'update' );
                return childModel;
        }
@@ -111,11 +120,13 @@
  * @param {Integer} howmany Number of nodes to remove
  * @param {es.ModelItem} [...] Variadic list of nodes to insert
  * @returns {es.ModelItem[]} Removed nodes
- * @emits splice (index, howmany, [...])
+ * @emits beforeSplice (index, howmany, [...])
+ * @emits afterSplice (index, howmany, [...])
  * @emits update
  */
 es.ModelNode.prototype.splice = function( index, howmany ) {
        var args = Array.prototype.slice.call( arguments, 0 );
+       this.emit.apply( this, ['beforeSplice'].concat( args ) );
        if ( args.length >= 3 ) {
                for ( var i = 2; i < args.length; i++ ) {
                        args[i].attach( this );
@@ -126,7 +137,7 @@
                removed[i].detach();
                removed[i].removeListener( 'update', this.emitUpdate );
        }
-       this.emit.apply( this, ['splice'].concat( args ) );
+       this.emit.apply( this, ['afterSplice'].concat( args ) );
        this.emit( 'update' );
        return removed;
 };
@@ -136,26 +147,30 @@
  * 
  * @method
  * @param {Function} sortfunc Function to use when sorting
- * @emits sort
+ * @emits beforeSort (sortfunc)
+ * @emits afterSort (sortfunc)
  * @emits update
  */
 es.ModelNode.prototype.sort = function( sortfunc ) {
-       this.emit( 'sort' );
+       this.emit( 'beforeSort', sortfunc );
+       Array.prototype.sort.call( this );
+       this.emit( 'afterSort', sortfunc );
        this.emit( 'update' );
-       Array.prototype.sort.call( this );
 };
 
 /**
  * Reverses the order of this node's children.
  * 
  * @method
- * @emits reverse
+ * @emits beforeReverse
+ * @emits afterReverse
  * @emits update
  */
 es.ModelNode.prototype.reverse = function() {
-       this.emit( 'reverse' );
+       this.emit( 'beforeReverse' );
+       Array.prototype.reverse.call( this );
+       this.emit( 'afterReverse' );
        this.emit( 'update' );
-       Array.prototype.reverse.call( this );
 };
 
 /**
@@ -176,8 +191,9 @@
  * @emits attach (parent)
  */
 es.ModelNode.prototype.attach = function( parent ) {
+       this.emit( 'beforeAttach', parent );
        this.parent = parent;
-       this.emit( 'attach', parent );
+       this.emit( 'afterAttach', parent );
 };
 
 /**
@@ -187,9 +203,10 @@
  * @emits detach (parent)
  */
 es.ModelNode.prototype.detach = function() {
+       this.emit( 'beforeDetach' );
        var parent = this.parent;
        this.parent = null;
-       this.emit( 'detach', parent );
+       this.emit( 'afterDetach' );
 };
 
 /**

Modified: trunk/parsers/wikidom/lib/hype/bases/es.ViewNode.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/bases/es.ViewNode.js 2011-10-03 21:31:14 UTC 
(rev 98809)
+++ trunk/parsers/wikidom/lib/hype/bases/es.ViewNode.js 2011-10-03 21:47:45 UTC 
(rev 98810)
@@ -19,94 +19,102 @@
 es.ViewNode = function( model, $element ) {
        // Inheritance
        es.EventEmitter.call( this );
-       var node = [];
-       
+
        // Extending this class will initialize it without any arguments, 
exiting early if no model
        // was given will prevent clogging up subclass prototypes with array 
methods
        if ( !model ) {
                return this;
        }
        
-       this.model = model;
-       this.$ = $element || $( '<div/>' );
+       // Extension
+       var node = $.extend( [], this )
        
+       // Properties
+       node.model = model;
+       node.$ = $element || $( '<div/>' );
+       
        // Reusable function for passing update events upstream
-       this.emitUpdate = function() {
+       node.emitUpdate = function() {
                node.emit( 'update' );
        };
        
        // Append existing model children
        for ( var i = 0; i < model.length; i++ ) {
-               this.onPush( model[i] );
+               node.onPush( model[i] );
        }
        
        // Observe and mimic changes on model
-       this.addListenerMethods( node, {
-               'push': 'onPush',
-               'unshift': 'onUnshift',
-               'pop': 'onPop',
-               'shift': 'onShift',
-               'splice': 'onSplice',
-               'sort': 'onSort',
-               'reverse': 'onReverse'
+       node.addListenerMethods( node, {
+               'afterPush': 'onAfterPush',
+               'afterUnshift': 'onAfterUnshift',
+               'afterPop': 'onAfterPop',
+               'afterShift': 'onAfterShift',
+               'afterSplice': 'onAfterSplice',
+               'afterSort': 'onAfterSort',
+               'afterReverse': 'onAfterReverse'
        } );
        
-       // Extend native array with method and properties of this
-       return $.extend( node, this );
+       return node;
 };
 
-es.ViewNode.onPush = function( childModel ) {
+es.ViewNode.onAfterPush = function( childModel ) {
        var childView = childModel.createView();
+       this.emit( 'beforePush', childView );
        childView.attach( this );
        childView.on( 'update', this.emitUpdate );
        this.push( childView );
        this.$.append( childView.$ );
-       this.emit( 'push', childView );
+       this.emit( 'afterPush', childView );
        this.emit( 'update' );
 };
 
-es.ViewNode.onUnshift = function( childModel ) {
+es.ViewNode.onAfterUnshift = function( childModel ) {
        var childView = childModel.createView();
+       this.emit( 'beforeUnshift', childView );
        childView.attach( this );
        childView.on( 'update', this.emitUpdate );
        this.unshift( childView );
        this.$.prepend( childView.$ );
-       this.emit( 'unshift', childView );
+       this.emit( 'afterUnshift', childView );
        this.emit( 'update' );
 };
 
-es.ViewNode.onPop = function() {
+es.ViewNode.onAfterPop = function() {
+       this.emit( 'beforePop' );
        var childView = this.pop();
        childView.detach();
        childView.removeEventListener( 'update', this.emitUpdate );
        childView.$.detach();
-       this.emit( 'pop' );
+       this.emit( 'afterPop' );
        this.emit( 'update' );
 };
 
-es.ViewNode.onShift = function() {
+es.ViewNode.onAfterShift = function() {
+       this.emit( 'beforeShift' );
        var childView = this.shift();
        childView.detach();
        childView.removeEventListener( 'update', this.emitUpdate );
        childView.$.detach();
-       this.emit( 'shift' );
+       this.emit( 'afterShift' );
        this.emit( 'update' );
 };
 
-es.ViewNode.onSplice = function( index, howmany ) {
-       var args = Array.prototype.slice( arguments, 0 ),
-               added = args.slice( 2 ),
-               removed = this.splice.apply( this, args );
-       this.$.children().slice( index, index + howmany ).detach();
-       var $added = $.map( added, function( childView ) {
-               return childView.$;
-       } );
-       this.$.children().get( index ).after( $added );
-       this.emit.apply( ['splice'].concat( args ) );
+es.ViewNode.onAfterSplice = function( index, howmany ) {
+       var args = Array.prototype.slice( arguments, 0 );
+       this.emit.apply( ['beforeSplice'].concat( args ) );
+       this.$.children()
+               // Removals
+               .slice( index, index + howmany ).detach()
+               // Insertions
+               .get( index ).after( $.map( args.slice( 2 ), function( 
childView ) {
+                       return childView.$;
+               } ) );
+       this.emit.apply( ['afterSplice'].concat( args ) );
        this.emit( 'update' );
 };
 
-es.ViewNode.onSort = function() {
+es.ViewNode.onAfterSort = function() {
+       this.emit( 'beforeSort' );
        for ( var i = 0; i < this.model.length; i++ ) {
                for ( var j = 0; j < this.length; j++ ) {
                        if ( this[j].getModel() === this.model[i] ) {
@@ -117,20 +125,20 @@
                        }
                }
        }
-       this.emit( 'sort' );
+       this.emit( 'afterSort' );
        this.emit( 'update' );
 };
 
-es.ViewNode.onReverse = function() {
+es.ViewNode.onAfterReverse = function() {
+       this.emit( 'beforeReverse' );
        this.reverse();
        this.$.children().each( function() {
                $(this).prependTo( $(this).parent() );
        } );
-       this.emit( 'reverse' );
+       this.emit( 'afterReverse' );
        this.emit( 'update' );
 };
 
-
 /**
  * Gets a reference to the model this node observes.
  * 

Added: trunk/parsers/wikidom/lib/hype/es.Range.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/es.Range.js                          (rev 0)
+++ trunk/parsers/wikidom/lib/hype/es.Range.js  2011-10-03 21:47:45 UTC (rev 
98810)
@@ -0,0 +1,59 @@
+/**
+ * Range of content.
+ * 
+ * @class
+ * @constructor
+ * @param from {Integer} Starting offset
+ * @param to {Integer} Ending offset
+ * @property from {Integer} Starting offset
+ * @property to {Integer} Ending offset
+ * @property start {Integer} Normalized starting offset
+ * @property end {Integer} Normalized ending offset
+ */
+es.Range = function( from, to ) {
+       this.from = from || 0;
+       this.to = typeof to === 'undefined' ? this.from : to;
+       this.normalize();
+};
+
+/* Methods */
+
+/**
+ * Checks if an offset is within this range.
+ * 
+ * @method
+ * @param offset {Integer} Offset to check
+ * @returns {Boolean} If offset is within this range
+ */
+es.Range.prototype.containsOffset = function( offset ) {
+       this.normalize();
+       return offset >= this.start && offset < this.end;
+};
+
+/**
+ * Gets the length of the range.
+ * 
+ * @method
+ * @returns {Integer} Length of range
+ */
+es.Range.prototype.getLength = function() {
+       return Math.abs( this.from - this.to );
+};
+
+/**
+ * Sets start and end properties, ensuring start is always before end.
+ * 
+ * This should always be called before using the start or end properties. Do 
not call this unless
+ * you are about to use these properties.
+ * 
+ * @method
+ */
+es.Range.prototype.normalize = function() {
+       if ( this.from < this.to ) {
+               this.start = this.from;
+               this.end = this.to;
+       } else {
+               this.start = this.to;
+               this.end = this.from;
+       }
+};

Modified: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js   2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js   2011-10-03 
21:47:45 UTC (rev 98810)
@@ -11,14 +11,16 @@
  */
 es.DocumentModel = function( data, attributes ) {
        // Inheritance
-       es.DocumentModelNode.call( this, length );
+       var node = $.extend( new es.DocumentModelNode( length ), this );
        
        // Properties
-       this.data = $.isArray( data ) ? data : [];
-       this.attributes = $.isPlainObject( attributes ) ? attributes : {};
+       node.data = $.isArray( data ) ? data : [];
+       node.attributes = $.isPlainObject( attributes ) ? attributes : {};
        
        // Initialization
-       this.rebuildChildNodes();
+       node.rebuildChildNodes();
+       
+       return node;
 };
 
 /* Static Members */
@@ -180,6 +182,7 @@
 /**
  * Creates a document view for this model.
  * 
+ * @method
  * @returns {es.DocumentView}
  */
 es.DocumentModel.prototype.createView = function() {
@@ -188,16 +191,23 @@
 
 /**
  * Regenerates child nodes from content data.
+ * 
+ * @method
  */
 es.DocumentModel.prototype.rebuildChildNodes = function() {
        // Remove child nodes
        this.splice( 0, this.length );
        // Build a tree of models, which is a space partitioning data structure
-       for ( var i = 0; i < this.data.length; i++ ) {
+       var currentNode = this;
+       for ( var i = 0, length = this.data.length; i < length; i++ ) {
                if ( this.data[i].type !== undefined ) {
                        // It's an element
+                       if ( this.data[i].type in es.DocumentModel.nodeModels ) 
{
+                               var node = new 
es.DocumentModel.nodeModels[this.data[i].type]();
+                               //this.push(  );
+                       }
                } else {
-                       // It's content
+                       // It's content - there are no child elements
                }
        }
 };
@@ -306,6 +316,7 @@
 
 /**
  * 
+ * @method
  * @returns {es.Transaction}
  */
 es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, 
annotation ) {
@@ -314,6 +325,7 @@
 
 /**
  * 
+ * @method
  * @returns {es.Transaction}
  */
 es.DocumentModel.prototype.prepareElementAttributeChange = function( index, 
method, annotation ) {
@@ -322,6 +334,8 @@
 
 /**
  * 
+ * @method
+ * @param {es.Transaction}
  */
 es.DocumentModel.prototype.commit = function( transaction ) {
        //
@@ -329,6 +343,8 @@
 
 /**
  * 
+ * @method
+ * @param {es.Transaction}
  */
 es.DocumentModel.prototype.rollback = function( transaction ) {
        //

Modified: trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js   2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js   2011-10-03 
21:47:45 UTC (rev 98810)
@@ -5,13 +5,16 @@
  * @constructor
  */
 es.ListItemModel = function( length ) {
-       // Inheritance
-       es.DocumentModelNode.call( this, length );
+       // Extension
+       return $.extend( new es.DocumentModelNode( length ), this );
 };
 
+/* Methods */
+
 /**
  * Creates a list item view for this model.
  * 
+ * @method
  * @returns {es.ListItemView}
  */
 es.ListItemModel.prototype.createView = function() {
@@ -21,7 +24,3 @@
 /* Registration */
 
 es.DocumentModel.nodeModels.listItem = es.ListItemModel;
-
-/* Inheritance */
-
-es.extend( es.ListItemModel, es.DocumentModelNode );

Modified: trunk/parsers/wikidom/lib/hype/models/es.ListModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.ListModel.js       2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.ListModel.js       2011-10-03 
21:47:45 UTC (rev 98810)
@@ -5,13 +5,16 @@
  * @constructor
  */
 es.ListModel = function( length ) {
-       // Inheritance
-       es.DocumentModelNode.call( this, length );
+       // Extension
+       return $.extend( new es.DocumentModelNode( length ), this );
 };
 
+/* Methods */
+
 /**
  * Creates a list view for this model.
  * 
+ * @method
  * @returns {es.ListView}
  */
 es.ListModel.prototype.createView = function() {
@@ -20,8 +23,4 @@
 
 /* Registration */
 
-es.DocumentModel.nodeModels.list = es.listModel;
-
-/* Inheritance */
-
-es.extend( es.ListModel, es.DocumentModelNode );
+es.DocumentModel.nodeModels.list = es.ListModel;

Modified: trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js  2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js  2011-10-03 
21:47:45 UTC (rev 98810)
@@ -5,13 +5,16 @@
  * @constructor
  */
 es.ParagraphModel = function( length ) {
-       // Inheritance
-       es.DocumentModelNode.call( this, length );
+       // Extension
+       return $.extend( new es.DocumentModelNode( length ), this );
 };
 
+/* Methods */
+
 /**
  * Creates a paragraph view for this model.
  * 
+ * @method
  * @returns {es.ParagraphView}
  */
 es.ParagraphModel.prototype.createView = function() {
@@ -21,7 +24,3 @@
 /* Registration */
 
 es.DocumentModel.nodeModels.paragraph = es.ParagraphModel;
-
-/* Inheritance */
-
-es.extend( es.ParagraphModel, es.DocumentModelNode );

Modified: trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js  2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js  2011-10-03 
21:47:45 UTC (rev 98810)
@@ -5,13 +5,16 @@
  * @constructor
  */
 es.TableCellModel = function( length ) {
-       // Inheritance
-       es.DocumentModelNode.call( this, length );
+       // Extension
+       return $.extend( new es.DocumentModelNode( length ), this );
 };
 
+/* Methods */
+
 /**
  * Creates a table cell view for this model.
  * 
+ * @method
  * @returns {es.TableCellView}
  */
 es.TableCellModel.prototype.createView = function() {
@@ -21,7 +24,3 @@
 /* Registration */
 
 es.DocumentModel.nodeModels.tableCell = es.TableCellModel;
-
-/* Inheritance */
-
-es.extend( es.TableCellModel, es.DocumentModelNode );

Modified: trunk/parsers/wikidom/lib/hype/models/es.TableModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.TableModel.js      2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.TableModel.js      2011-10-03 
21:47:45 UTC (rev 98810)
@@ -5,13 +5,16 @@
  * @constructor
  */
 es.TableModel = function( length ) {
-       // Inheritance
-       es.DocumentModelNode.call( this, length );
+       // Extension
+       return $.extend( new es.DocumentModelNode( length ), this );
 };
 
+/* Methods */
+
 /**
  * Creates a table view for this model.
  * 
+ * @method
  * @returns {es.TableView}
  */
 es.TableModel.prototype.createView = function() {
@@ -21,7 +24,3 @@
 /* Registration */
 
 es.DocumentModel.nodeModels.table = es.TableModel;
-
-/* Inheritance */
-
-es.extend( es.TableModel, es.DocumentModelNode );

Modified: trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js
===================================================================
--- trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js   2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js   2011-10-03 
21:47:45 UTC (rev 98810)
@@ -5,8 +5,8 @@
  * @constructor
  */
 es.TableRowModel = function( length ) {
-       // Inheritance
-       es.DocumentModelNode.call( this, length );
+       // Extension
+       return $.extend( new es.DocumentModelNode( length ), this );
 };
 
 /* Methods */
@@ -14,6 +14,7 @@
 /**
  * Creates a table row view for this model.
  * 
+ * @method
  * @returns {es.TableRowView}
  */
 es.TableRowModel.prototype.createView = function() {
@@ -23,7 +24,3 @@
 /* Registration */
 
 es.DocumentModel.nodeModels.tableRow = es.TableRowModel;
-
-/* Inheritance */
-
-es.extend( es.TableRowModel, es.DocumentModelNode );

Modified: trunk/parsers/wikidom/tests/hype/es.ModelNode.test.js
===================================================================
--- trunk/parsers/wikidom/tests/hype/es.ModelNode.test.js       2011-10-03 
21:31:14 UTC (rev 98809)
+++ trunk/parsers/wikidom/tests/hype/es.ModelNode.test.js       2011-10-03 
21:47:45 UTC (rev 98810)
@@ -13,11 +13,11 @@
                updates++;
        } );
        var attaches = 0;
-       modelNode2.on( 'attach', function() {
+       modelNode2.on( 'afterAttach', function() {
                attaches++;
        } );
        var detaches = 0;
-       modelNode2.on( 'detach', function() {
+       modelNode2.on( 'afterDetach', function() {
                detaches++;
        } );
        
@@ -27,7 +27,7 @@
        equal( modelNode1[0], modelNode2, 'es.ModelNode appends node on push' );
        
        /** @covers es.ModelNode.attach */
-       equal( attaches, 1, 'es.ModelNode emits attach events when added to 
another node' );
+       equal( attaches, 1, 'es.ModelNode emits afterAttach events when added 
to another node' );
        
        /** @covers es.ModelNode.unshift */
        modelNode1.unshift( modelNode3 );
@@ -73,7 +73,7 @@
        );
        
        /** @covers es.ModelNode.detach */
-       equal( detaches, 1, 'es.ModelNode emits detach events when removed from 
another node' );
+       equal( detaches, 1, 'es.ModelNode emits afterDetach events when removed 
from another node' );
        
        /** @covers es.ModelNode.getParent */
        strictEqual( modelNode3.getParent(), modelNode1, 'Child nodes have 
correct parent reference' );

Modified: trunk/parsers/wikidom/tests/hype/index.html
===================================================================
--- trunk/parsers/wikidom/tests/hype/index.html 2011-10-03 21:31:14 UTC (rev 
98809)
+++ trunk/parsers/wikidom/tests/hype/index.html 2011-10-03 21:47:45 UTC (rev 
98810)
@@ -13,6 +13,7 @@
                <script src="../../lib/jquery.js"></script>
                <script src="../../lib/qunit.js"></script>
                <script src="../../lib/hype/es.js"></script>
+               <script src="../../lib/hype/es.Range.js"></script>
                <script src="../../lib/hype/bases/es.EventEmitter.js"></script>
                <script src="../../lib/hype/bases/es.ModelNode.js"></script>
                <script src="../../lib/hype/bases/es.ViewNode.js"></script>


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to