Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentViewLeafNode.js |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | * @returns {Integer} Offset of position |
58 | 58 | */ |
59 | 59 | es.DocumentViewLeafNode.prototype.getOffsetFromRenderedPosition = function( position ) { |
60 | | - return this.contentView.getOffsetFromRenderedPosition( offset ); |
| 60 | + return this.contentView.getOffsetFromRenderedPosition( position ); |
61 | 61 | }; |
62 | 62 | |
63 | 63 | /** |
Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentViewBranchNode.js |
— | — | @@ -72,10 +72,10 @@ |
73 | 73 | if ( this[i].$.offset().top > position.top ) { |
74 | 74 | break; |
75 | 75 | } |
76 | | - node = this.items[i]; |
| 76 | + node = this[i]; |
77 | 77 | } |
78 | 78 | return node.getParent().getOffsetFromNode( node, true ) + |
79 | | - node.getOffsetFromPosition( position ); |
| 79 | + node.getOffsetFromRenderedPosition( position ); |
80 | 80 | }; |
81 | 81 | |
82 | 82 | /** |
Index: trunk/parsers/wikidom/lib/hype/views/es.ParagraphView.js |
— | — | @@ -11,3 +11,12 @@ |
12 | 12 | view.$.addClass( 'editSurface-paragraphBlock' ); |
13 | 13 | return view; |
14 | 14 | }; |
| 15 | + |
| 16 | +es.ParagraphView.prototype.getRenderedPositionFromOffset = function( offset ) { |
| 17 | + var position = this.contentView.getRenderedPositionFromOffset( offset ), |
| 18 | + offset = this.$content.offset(); |
| 19 | + position.top += offset.top; |
| 20 | + position.left += offset.left; |
| 21 | + position.bottom += offset.top; |
| 22 | + return position; |
| 23 | +}; |
Index: trunk/parsers/wikidom/lib/hype/views/es.SurfaceView.js |
— | — | @@ -6,7 +6,35 @@ |
7 | 7 | // Initialize document view |
8 | 8 | this.documentView = new es.DocumentView( this.model.getDocument(), this ); |
9 | 9 | this.$.append( this.documentView.$ ); |
| 10 | + |
| 11 | + this.cursor = { |
| 12 | + $: $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ ), |
| 13 | + interval: null, |
| 14 | + offset: null, |
| 15 | + initialLeft: null |
| 16 | + }; |
| 17 | + |
| 18 | + // References for use in closures |
| 19 | + var surfaceView = this; |
10 | 20 | |
| 21 | + // MouseDown on surface |
| 22 | + this.$.bind( { |
| 23 | + 'mousedown' : function(e) { |
| 24 | + return surfaceView.onMouseDown( e ); |
| 25 | + } |
| 26 | + } ); |
| 27 | + |
11 | 28 | // First render |
12 | 29 | this.documentView.renderContent(); |
13 | | -}; |
\ No newline at end of file |
| 30 | +}; |
| 31 | + |
| 32 | +es.SurfaceView.prototype.onMouseDown = function( e ) { |
| 33 | + var offset = this.documentView.getOffsetFromEvent( e ); |
| 34 | + var position = this.documentView.getRenderedPositionFromOffset( offset ); |
| 35 | + |
| 36 | + this.cursor.$.css( { |
| 37 | + 'left': position.left, |
| 38 | + 'top': position.top, |
| 39 | + 'height': position.bottom - position.top |
| 40 | + } ).show(); |
| 41 | +}; |
Index: trunk/parsers/wikidom/lib/hype/views/es.DocumentView.js |
— | — | @@ -3,4 +3,16 @@ |
4 | 4 | node.$.addClass( 'editSurface-document' ); |
5 | 5 | node.surfaceView = surfaceView; |
6 | 6 | return node; |
| 7 | +}; |
| 8 | + |
| 9 | +/** |
| 10 | + * Get the document offset of a position created from passed DOM event |
| 11 | + * |
| 12 | + * @method |
| 13 | + * @param e {Event} Event to create es.Position from |
| 14 | + * @returns {Integer} Document offset |
| 15 | + */ |
| 16 | +es.DocumentView.prototype.getOffsetFromEvent = function( e ) { |
| 17 | + var position = es.Position.newFromEventPagePosition( e ); |
| 18 | + return this.getOffsetFromRenderedPosition( position ); |
7 | 19 | }; |
\ No newline at end of file |
Index: trunk/parsers/wikidom/lib/hype/views/es.HeadingView.js |
— | — | @@ -11,3 +11,12 @@ |
12 | 12 | view.$.addClass( 'editSurface-headingBlock' ); |
13 | 13 | return view; |
14 | 14 | }; |
| 15 | + |
| 16 | +es.HeadingView.prototype.getRenderedPositionFromOffset = function( offset ) { |
| 17 | + var position = this.contentView.getRenderedPositionFromOffset( offset ), |
| 18 | + offset = this.$content.offset(); |
| 19 | + position.top += offset.top; |
| 20 | + position.left += offset.left; |
| 21 | + position.bottom += offset.top; |
| 22 | + return position; |
| 23 | +}; |
\ No newline at end of file |
Index: trunk/parsers/wikidom/demos/hype/index.html |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | <script src="../../lib/hype/es.js"></script> |
59 | 59 | <script src="../../lib/hype/es.Range.js"></script> |
60 | 60 | <script src="../../lib/hype/es.Transaction.js"></script> |
| 61 | + <script src="../../lib/hype/es.Position.js"></script> |
61 | 62 | |
62 | 63 | <!-- Bases --> |
63 | 64 | <script src="../../lib/hype/bases/es.EventEmitter.js"></script> |