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

Revision: 97874
Author:   inez
Date:     2011-09-23 00:36:31 +0000 (Fri, 23 Sep 2011)
Log Message:
-----------
Very basic version of selection and more blocks in demo

Modified Paths:
--------------
    trunk/parsers/wikidom/demos/synth/es.js
    trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
    trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
    trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js
    trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
    trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js
    trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js
    trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js

Modified: trunk/parsers/wikidom/demos/synth/es.js
===================================================================
--- trunk/parsers/wikidom/demos/synth/es.js     2011-09-23 00:27:41 UTC (rev 
97873)
+++ trunk/parsers/wikidom/demos/synth/es.js     2011-09-23 00:36:31 UTC (rev 
97874)
@@ -83,6 +83,56 @@
                                                                        
'content': { 'text': 'row 2 & cell 2' }
                                                                },
                                                                {
+                                                                       'type': 
'table',
+                                                                       
'attributes': { 'style': 'width: 150px; border: solid 1px;' },
+                                                                       'rows': 
[
+                                                                               
{
+                                                                               
        'cells': [
+                                                                               
                {
+                                                                               
                        'attributes': { 'style': 'border: solid 1px;' },
+                                                                               
                        'blocks': [
+                                                                               
                                {
+                                                                               
                                        'type': 'paragraph',
+                                                                               
                                        'content': { 'text': '#1 #1 #1' }
+                                                                               
                                }
+                                                                               
                        ]
+                                                                               
                },
+                                                                               
                {
+                                                                               
                        'attributes': { 'style': 'border: solid 1px;' },
+                                                                               
                        'blocks': [
+                                                                               
                                {
+                                                                               
                                        'type': 'paragraph',
+                                                                               
                                        'content': { 'text': '#2 #2 #2' }
+                                                                               
                                }
+                                                                               
                        ]
+                                                                               
                }
+                                                                               
        ]
+                                                                               
},
+                                                                               
{
+                                                                               
        'cells': [
+                                                                               
                {
+                                                                               
                        'attributes': { 'style': 'border: solid 1px;' },
+                                                                               
                        'blocks': [
+                                                                               
                                {
+                                                                               
                                        'type': 'paragraph',
+                                                                               
                                        'content': { 'text': '#3 #3 #3' }
+                                                                               
                                }
+                                                                               
                        ]
+                                                                               
                },
+                                                                               
                {
+                                                                               
                        'attributes': { 'style': 'border: solid 1px;' },
+                                                                               
                        'blocks': [
+                                                                               
                                {
+                                                                               
                                        'type': 'paragraph',
+                                                                               
                                        'content': { 'text': '#4 #4 #4' }
+                                                                               
                                }                                               
                
+                                                                               
                        ]
+                                                                               
                }
+                                                                               
        ]
+                                                                               
}
+                                                                       ]
+                                                               },
+                                                               {
                                                                        'type': 
'list',
                                                                        
'style': 'number',
                                                                        
'items': [

Modified: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.ContentView.js     2011-09-23 
00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.ContentView.js     2011-09-23 
00:36:31 UTC (rev 97874)
@@ -126,7 +126,8 @@
        '\'': ''',
        '"': '"',
        '\n': '<span class="editSurface-whitespace">&#182;</span>',
-       '\t': '<span class="editSurface-whitespace">&#8702;</span>'
+       '\t': '<span class="editSurface-whitespace">&#8702;</span>',
+       ' ': '&nbsp;'
 };
 
 /* Static Methods */

Modified: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js    2011-09-23 
00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js    2011-09-23 
00:36:31 UTC (rev 97874)
@@ -16,16 +16,23 @@
        if ( this.items.length === 0 ) {
                return 0;
        }
+
+       var blockView = this.items[0],
+               blockLength = 0,
+               offset = 0;
        
-       var blockView = this.items[0];
        for ( var i = 0; i < this.items.length; i++ ) {
                if ( this.items[i].$.offset().top >= position.top ) {
                        break;
                }
                blockView = this.items[i];
+               blockLength = blockView.getLength();
+               offset += blockLength + 1;
        }
 
-       return blockView.getOffsetFromPosition( position );
+       offset -= blockLength + 1;
+
+       return offset + blockView.getOffsetFromPosition( position );
 };
 
 /**

Modified: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js   2011-09-23 
00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js   2011-09-23 
00:36:31 UTC (rev 97874)
@@ -21,6 +21,7 @@
 es.ListBlockView.prototype.getOffsetFromPosition = function( position ) {
        var contentOffset;
        var itemHeight;
+       var offset = 0;
        for ( var i = 0; i < this.items.length; i++ ) {
                contentOffset = this.items[i].$content.offset();
                if ( position.top >= contentOffset.top ) {
@@ -28,9 +29,10 @@
                        if ( position.top < contentOffset.top + itemHeight ) {
                                position.left -= contentOffset.left;
                                position.top -= contentOffset.top;
-                               return this.items[i].contentView.getOffset( 
position );
+                               return offset + 
this.items[i].contentView.getOffset( position );
                        }
                }
+               offset += this.items[i].getLength() + 1;
        }
        
        while(!documentView.list) {

Modified: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-23 
00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js     2011-09-23 
00:36:31 UTC (rev 97874)
@@ -34,6 +34,9 @@
                }
        };
        
+       this.selecting = false;
+       this.from = this.to = 0;
+       
        // Cursor
        this.blinkInterval = null;
        this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( 
this.$ );
@@ -237,15 +240,30 @@
 es.SurfaceView.prototype.onMouseDown = function( e ) {
        var position = es.Position.newFromEventPagePosition( e );
        var offset = this.documentView.getOffsetFromPosition( position );
-       console.log( offset );
+       this.from = offset;
+       this.selecting = true;
+
+       console.log(offset);
+
+       if ( !this.$input.is(':focus') ) {
+               this.$input.focus().select();
+       }
+
        return false;
 };
 
 es.SurfaceView.prototype.onMouseMove = function( e ) {
+       if (this.selecting ) {
+               var position = es.Position.newFromEventPagePosition( e );
+               var offset = this.documentView.getOffsetFromPosition( position 
);
+               this.to = offset;
+               this.documentView.drawSelection( new es.Range( this.from, 
this.to ) );
+       }
        // TODO: Respond to mouse move event, updating selection while painting
 };
 
 es.SurfaceView.prototype.onMouseUp = function( e ) {
+       this.selecting = false;
        // TODO: Respond to mouse up event, possibly ending selection painting
 };
 

Modified: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js      
2011-09-23 00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js      
2011-09-23 00:36:31 UTC (rev 97874)
@@ -16,18 +16,29 @@
 es.TableBlockCellView.prototype.getOffsetFromPosition = function( position ) {
        var blockOffset;
        var itemHeight;
+       var offset = 0;
        
        for ( var i = 0; i < this.items.length; i++ ) {
                blockOffset = this.items[i].$.offset();
                if ( position.top >= blockOffset.top ) {
                        itemHeight = this.items[i].$.height();
                        if ( position.top < blockOffset.top + itemHeight ) {
-                               return this.items[i].getOffsetFromPosition( 
position );
+                               return offset + 
this.items[i].getOffsetFromPosition( position );
                        }
                }
+               offset += this.items[i].getLength() + 1;
        }
 };
 
+/**
+ * Gets length of contents.
+ * 
+ * @method
+ * @returns {Integer} Length of content, including any virtual spaces within 
the block
+ */
+es.TableBlockCellView.prototype.getLength = function() {
+       return this.items.getLengthOfItems();
+};
 
 /**
  * Render content.
@@ -69,19 +80,16 @@
  * @param range {es.Range} Range of content to draw selection around
  */
 es.TableBlockCellView.prototype.drawSelection = function( range ) {
-       this.documentView.drawSelection( range );
+       var selectedViews = this.items.select( range );
+       for ( var i = 0; i < selectedViews.length; i++ ) {
+               selectedViews[i].item.drawSelection(
+                       new es.Range( selectedViews[i].from, 
selectedViews[i].to )
+               );
+       }
 };
 
-/**
- * Gets length of contents.
- * 
- * @method
- * @returns {Integer} Length of content, including any virtual spaces within 
the block
- */
-es.TableBlockCellView.prototype.getLength = function() {
-       return this.documentView.getLength();
-};
 
+
 /**
  * Gets HTML rendering of block.
  * 

Modified: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js       
2011-09-23 00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js       
2011-09-23 00:36:31 UTC (rev 97874)
@@ -17,15 +17,17 @@
 es.TableBlockRowView.prototype.getOffsetFromPosition = function( position ) {
        var cellOffset;
        var itemWidth;
+       var offset = 0;
        
        for ( var i = 0; i < this.items.length; i++ ) {
                cellOffset = this.items[i].$.offset();
                if ( position.left >= cellOffset.left ) {
                        itemWidth = this.items[i].$.width();
                        if ( position.left < cellOffset.left + itemWidth ) {
-                               return this.items[i].getOffsetFromPosition( 
position );
+                               return offset + 
this.items[i].getOffsetFromPosition( position );
                        }
                }
+               offset += this.items[i].getLength() + 1;
        }
 };
 

Modified: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js  2011-09-23 
00:27:41 UTC (rev 97873)
+++ trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js  2011-09-23 
00:36:31 UTC (rev 97874)
@@ -18,15 +18,17 @@
 es.TableBlockView.prototype.getOffsetFromPosition = function( position ) {
        var rowOffset;
        var itemHeight;
+       var offset = 0;
 
        for ( var i = 0; i < this.items.length; i++ ) {
                rowOffset = this.items[i].$.offset();
                if ( position.top >= rowOffset.top ) {
                        itemHeight = this.items[i].$.height();
                        if ( position.top < rowOffset.top + itemHeight ) {
-                               return this.items[i].getOffsetFromPosition( 
position );
+                               return offset + 
this.items[i].getOffsetFromPosition( position );
                        }
                }
+               offset += this.items[i].getLength() + 1;
        }
 };
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to