Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js |
— | — | @@ -18,10 +18,22 @@ |
19 | 19 | |
20 | 20 | /* Methods */ |
21 | 21 | |
| 22 | +/** |
| 23 | + * Gets the offset of a position. |
| 24 | + * |
| 25 | + * @method |
| 26 | + * @param position {es.Position} Position to translate |
| 27 | + * @returns {Integer} Offset nearest to position |
| 28 | + */ |
22 | 29 | es.ListBlockView.prototype.getOffsetFromPosition = function( position ) { |
23 | | - var contentOffset; |
24 | | - var itemHeight; |
25 | | - var offset = 0; |
| 30 | + if ( this.items.length === 0 ) { |
| 31 | + return 0; |
| 32 | + } |
| 33 | + |
| 34 | + var contentOffset, |
| 35 | + itemHeight, |
| 36 | + offset = 0; |
| 37 | + |
26 | 38 | for ( var i = 0; i < this.items.length; i++ ) { |
27 | 39 | contentOffset = this.items[i].$content.offset(); |
28 | 40 | if ( position.top >= contentOffset.top ) { |
— | — | @@ -29,14 +41,27 @@ |
30 | 42 | if ( position.top < contentOffset.top + itemHeight ) { |
31 | 43 | position.left -= contentOffset.left; |
32 | 44 | position.top -= contentOffset.top; |
33 | | - return offset + this.items[i].contentView.getOffset( position ); |
| 45 | + return offset + this.items[i].getContentOffset( position ); |
34 | 46 | } |
35 | 47 | } |
36 | 48 | offset += this.items[i].getLength() + 1; |
37 | 49 | } |
38 | 50 | |
39 | | - while(!documentView.list) { |
40 | | - |
| 51 | + throw 'Position coordinates are outside of the view.'; |
| 52 | +}; |
| 53 | + |
| 54 | +/** |
| 55 | + * Draw selection around a given range. |
| 56 | + * |
| 57 | + * @method |
| 58 | + * @param range {es.Range} Range of content to draw selection around |
| 59 | + */ |
| 60 | +es.ListBlockView.prototype.drawSelection = function( range ) { |
| 61 | + var selectedItems = this.items.select( range ); |
| 62 | + for ( var i = 0; i < selectedItems.length; i++ ) { |
| 63 | + selectedItems[i].item.drawSelection( |
| 64 | + new es.Range( selectedItems[i].from, selectedItems[i].to ) |
| 65 | + ); |
41 | 66 | } |
42 | 67 | }; |
43 | 68 | |
— | — | @@ -74,21 +99,6 @@ |
75 | 100 | }; |
76 | 101 | |
77 | 102 | /** |
78 | | - * Draw selection around a given range. |
79 | | - * |
80 | | - * @method |
81 | | - * @param range {es.Range} Range of content to draw selection around |
82 | | - */ |
83 | | -es.ListBlockView.prototype.drawSelection = function( 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 | | - } |
90 | | -}; |
91 | | - |
92 | | -/** |
93 | 103 | * Gets length of contents. |
94 | 104 | * |
95 | 105 | * @method |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js |
— | — | @@ -14,11 +14,18 @@ |
15 | 15 | |
16 | 16 | /* Methods */ |
17 | 17 | |
| 18 | +/** |
| 19 | + * Gets the offset of a position. |
| 20 | + * |
| 21 | + * @method |
| 22 | + * @param position {es.Position} Position to translate |
| 23 | + * @returns {Integer} Offset nearest to position |
| 24 | + */ |
18 | 25 | es.TableBlockRowView.prototype.getOffsetFromPosition = function( position ) { |
19 | | - var cellOffset; |
20 | | - var itemWidth; |
21 | | - var offset = 0; |
22 | | - |
| 26 | + var cellOffset, |
| 27 | + itemWidth, |
| 28 | + offset = 0; |
| 29 | + |
23 | 30 | for ( var i = 0; i < this.items.length; i++ ) { |
24 | 31 | cellOffset = this.items[i].$.offset(); |
25 | 32 | if ( position.left >= cellOffset.left ) { |
— | — | @@ -29,6 +36,8 @@ |
30 | 37 | } |
31 | 38 | offset += this.items[i].getLength() + 1; |
32 | 39 | } |
| 40 | + |
| 41 | + throw 'Position coordinates are outside of the view.'; |
33 | 42 | }; |
34 | 43 | |
35 | 44 | /** |
Index: trunk/parsers/wikidom/lib/synth/views/es.ParagraphBlockView.js |
— | — | @@ -17,6 +17,13 @@ |
18 | 18 | |
19 | 19 | /* Methods */ |
20 | 20 | |
| 21 | +/** |
| 22 | + * Gets the offset of a position. |
| 23 | + * |
| 24 | + * @method |
| 25 | + * @param position {es.Position} Position to translate |
| 26 | + * @returns {Integer} Offset nearest to position |
| 27 | + */ |
21 | 28 | es.ParagraphBlockView.prototype.getOffsetFromPosition = function( position ) { |
22 | 29 | var blockPosition = this.$.offset(); |
23 | 30 | position.left -= blockPosition.left; |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js |
— | — | @@ -13,10 +13,17 @@ |
14 | 14 | |
15 | 15 | /* Methods */ |
16 | 16 | |
| 17 | +/** |
| 18 | + * Gets the offset of a position. |
| 19 | + * |
| 20 | + * @method |
| 21 | + * @param position {es.Position} Position to translate |
| 22 | + * @returns {Integer} Offset nearest to position |
| 23 | + */ |
17 | 24 | es.TableBlockCellView.prototype.getOffsetFromPosition = function( position ) { |
18 | | - var blockOffset; |
19 | | - var itemHeight; |
20 | | - var offset = 0; |
| 25 | + var blockOffset, |
| 26 | + itemHeight, |
| 27 | + offset = 0; |
21 | 28 | |
22 | 29 | for ( var i = 0; i < this.items.length; i++ ) { |
23 | 30 | blockOffset = this.items[i].$.offset(); |
— | — | @@ -28,6 +35,8 @@ |
29 | 36 | } |
30 | 37 | offset += this.items[i].getLength() + 1; |
31 | 38 | } |
| 39 | + |
| 40 | + throw 'Position coordinates are outside of the view.'; |
32 | 41 | }; |
33 | 42 | |
34 | 43 | /** |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js |
— | — | @@ -15,10 +15,21 @@ |
16 | 16 | |
17 | 17 | /* Methods */ |
18 | 18 | |
| 19 | +/** |
| 20 | + * Gets the offset of a position. |
| 21 | + * |
| 22 | + * @method |
| 23 | + * @param position {es.Position} Position to translate |
| 24 | + * @returns {Integer} Offset nearest to position |
| 25 | + */ |
19 | 26 | es.TableBlockView.prototype.getOffsetFromPosition = function( position ) { |
20 | | - var rowOffset; |
21 | | - var itemHeight; |
22 | | - var offset = 0; |
| 27 | + if ( this.items.length === 0 ) { |
| 28 | + return 0; |
| 29 | + } |
| 30 | + |
| 31 | + var rowOffset, |
| 32 | + itemHeight, |
| 33 | + offset = 0; |
23 | 34 | |
24 | 35 | for ( var i = 0; i < this.items.length; i++ ) { |
25 | 36 | rowOffset = this.items[i].$.offset(); |
— | — | @@ -30,6 +41,8 @@ |
31 | 42 | } |
32 | 43 | offset += this.items[i].getLength() + 1; |
33 | 44 | } |
| 45 | + |
| 46 | + throw 'Position coordinates are outside of the view.'; |
34 | 47 | }; |
35 | 48 | |
36 | 49 | /** |