r97874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97873‎ | r97874 | r97875 >
Date:00:36, 23 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Very basic version of selection and more blocks in demo
Modified paths:
  • /trunk/parsers/wikidom/demos/synth/es.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ContentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js
@@ -21,6 +21,7 @@
2222 es.ListBlockView.prototype.getOffsetFromPosition = function( position ) {
2323 var contentOffset;
2424 var itemHeight;
 25+ var offset = 0;
2526 for ( var i = 0; i < this.items.length; i++ ) {
2627 contentOffset = this.items[i].$content.offset();
2728 if ( position.top >= contentOffset.top ) {
@@ -28,9 +29,10 @@
2930 if ( position.top < contentOffset.top + itemHeight ) {
3031 position.left -= contentOffset.left;
3132 position.top -= contentOffset.top;
32 - return this.items[i].contentView.getOffset( position );
 33+ return offset + this.items[i].contentView.getOffset( position );
3334 }
3435 }
 36+ offset += this.items[i].getLength() + 1;
3537 }
3638
3739 while(!documentView.list) {
Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js
@@ -34,6 +34,9 @@
3535 }
3636 };
3737
 38+ this.selecting = false;
 39+ this.from = this.to = 0;
 40+
3841 // Cursor
3942 this.blinkInterval = null;
4043 this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ );
@@ -237,15 +240,30 @@
238241 es.SurfaceView.prototype.onMouseDown = function( e ) {
239242 var position = es.Position.newFromEventPagePosition( e );
240243 var offset = this.documentView.getOffsetFromPosition( position );
241 - console.log( offset );
 244+ this.from = offset;
 245+ this.selecting = true;
 246+
 247+ console.log(offset);
 248+
 249+ if ( !this.$input.is(':focus') ) {
 250+ this.$input.focus().select();
 251+ }
 252+
242253 return false;
243254 };
244255
245256 es.SurfaceView.prototype.onMouseMove = function( e ) {
 257+ if (this.selecting ) {
 258+ var position = es.Position.newFromEventPagePosition( e );
 259+ var offset = this.documentView.getOffsetFromPosition( position );
 260+ this.to = offset;
 261+ this.documentView.drawSelection( new es.Range( this.from, this.to ) );
 262+ }
246263 // TODO: Respond to mouse move event, updating selection while painting
247264 };
248265
249266 es.SurfaceView.prototype.onMouseUp = function( e ) {
 267+ this.selecting = false;
250268 // TODO: Respond to mouse up event, possibly ending selection painting
251269 };
252270
Index: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js
@@ -126,7 +126,8 @@
127127 '\'': '&#039;',
128128 '"': '&quot;',
129129 '\n': '<span class="editSurface-whitespace">&#182;</span>',
130 - '\t': '<span class="editSurface-whitespace">&#8702;</span>'
 130+ '\t': '<span class="editSurface-whitespace">&#8702;</span>',
 131+ ' ': '&nbsp;'
131132 };
132133
133134 /* Static Methods */
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js
@@ -17,15 +17,17 @@
1818 es.TableBlockRowView.prototype.getOffsetFromPosition = function( position ) {
1919 var cellOffset;
2020 var itemWidth;
 21+ var offset = 0;
2122
2223 for ( var i = 0; i < this.items.length; i++ ) {
2324 cellOffset = this.items[i].$.offset();
2425 if ( position.left >= cellOffset.left ) {
2526 itemWidth = this.items[i].$.width();
2627 if ( position.left < cellOffset.left + itemWidth ) {
27 - return this.items[i].getOffsetFromPosition( position );
 28+ return offset + this.items[i].getOffsetFromPosition( position );
2829 }
2930 }
 31+ offset += this.items[i].getLength() + 1;
3032 }
3133 };
3234
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
@@ -16,16 +16,23 @@
1717 if ( this.items.length === 0 ) {
1818 return 0;
1919 }
 20+
 21+ var blockView = this.items[0],
 22+ blockLength = 0,
 23+ offset = 0;
2024
21 - var blockView = this.items[0];
2225 for ( var i = 0; i < this.items.length; i++ ) {
2326 if ( this.items[i].$.offset().top >= position.top ) {
2427 break;
2528 }
2629 blockView = this.items[i];
 30+ blockLength = blockView.getLength();
 31+ offset += blockLength + 1;
2732 }
2833
29 - return blockView.getOffsetFromPosition( position );
 34+ offset -= blockLength + 1;
 35+
 36+ return offset + blockView.getOffsetFromPosition( position );
3037 };
3138
3239 /**
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js
@@ -16,18 +16,29 @@
1717 es.TableBlockCellView.prototype.getOffsetFromPosition = function( position ) {
1818 var blockOffset;
1919 var itemHeight;
 20+ var offset = 0;
2021
2122 for ( var i = 0; i < this.items.length; i++ ) {
2223 blockOffset = this.items[i].$.offset();
2324 if ( position.top >= blockOffset.top ) {
2425 itemHeight = this.items[i].$.height();
2526 if ( position.top < blockOffset.top + itemHeight ) {
26 - return this.items[i].getOffsetFromPosition( position );
 27+ return offset + this.items[i].getOffsetFromPosition( position );
2728 }
2829 }
 30+ offset += this.items[i].getLength() + 1;
2931 }
3032 };
3133
 34+/**
 35+ * Gets length of contents.
 36+ *
 37+ * @method
 38+ * @returns {Integer} Length of content, including any virtual spaces within the block
 39+ */
 40+es.TableBlockCellView.prototype.getLength = function() {
 41+ return this.items.getLengthOfItems();
 42+};
3243
3344 /**
3445 * Render content.
@@ -69,19 +80,16 @@
7081 * @param range {es.Range} Range of content to draw selection around
7182 */
7283 es.TableBlockCellView.prototype.drawSelection = function( range ) {
73 - this.documentView.drawSelection( range );
 84+ var selectedViews = this.items.select( range );
 85+ for ( var i = 0; i < selectedViews.length; i++ ) {
 86+ selectedViews[i].item.drawSelection(
 87+ new es.Range( selectedViews[i].from, selectedViews[i].to )
 88+ );
 89+ }
7490 };
7591
76 -/**
77 - * Gets length of contents.
78 - *
79 - * @method
80 - * @returns {Integer} Length of content, including any virtual spaces within the block
81 - */
82 -es.TableBlockCellView.prototype.getLength = function() {
83 - return this.documentView.getLength();
84 -};
8592
 93+
8694 /**
8795 * Gets HTML rendering of block.
8896 *
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js
@@ -18,15 +18,17 @@
1919 es.TableBlockView.prototype.getOffsetFromPosition = function( position ) {
2020 var rowOffset;
2121 var itemHeight;
 22+ var offset = 0;
2223
2324 for ( var i = 0; i < this.items.length; i++ ) {
2425 rowOffset = this.items[i].$.offset();
2526 if ( position.top >= rowOffset.top ) {
2627 itemHeight = this.items[i].$.height();
2728 if ( position.top < rowOffset.top + itemHeight ) {
28 - return this.items[i].getOffsetFromPosition( position );
 29+ return offset + this.items[i].getOffsetFromPosition( position );
2930 }
3031 }
 32+ offset += this.items[i].getLength() + 1;
3133 }
3234 };
3335
Index: trunk/parsers/wikidom/demos/synth/es.js
@@ -83,6 +83,56 @@
8484 'content': { 'text': 'row 2 & cell 2' }
8585 },
8686 {
 87+ 'type': 'table',
 88+ 'attributes': { 'style': 'width: 150px; border: solid 1px;' },
 89+ 'rows': [
 90+ {
 91+ 'cells': [
 92+ {
 93+ 'attributes': { 'style': 'border: solid 1px;' },
 94+ 'blocks': [
 95+ {
 96+ 'type': 'paragraph',
 97+ 'content': { 'text': '#1 #1 #1' }
 98+ }
 99+ ]
 100+ },
 101+ {
 102+ 'attributes': { 'style': 'border: solid 1px;' },
 103+ 'blocks': [
 104+ {
 105+ 'type': 'paragraph',
 106+ 'content': { 'text': '#2 #2 #2' }
 107+ }
 108+ ]
 109+ }
 110+ ]
 111+ },
 112+ {
 113+ 'cells': [
 114+ {
 115+ 'attributes': { 'style': 'border: solid 1px;' },
 116+ 'blocks': [
 117+ {
 118+ 'type': 'paragraph',
 119+ 'content': { 'text': '#3 #3 #3' }
 120+ }
 121+ ]
 122+ },
 123+ {
 124+ 'attributes': { 'style': 'border: solid 1px;' },
 125+ 'blocks': [
 126+ {
 127+ 'type': 'paragraph',
 128+ 'content': { 'text': '#4 #4 #4' }
 129+ }
 130+ ]
 131+ }
 132+ ]
 133+ }
 134+ ]
 135+ },
 136+ {
87137 'type': 'list',
88138 'style': 'number',
89139 'items': [

Status & tagging log