Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -15,33 +15,28 @@ |
16 | 16 | /** |
17 | 17 | * |
18 | 18 | * @param $container |
19 | | - * @param document |
| 19 | + * @param doc |
20 | 20 | * @returns {Surface} |
21 | 21 | */ |
22 | | -function Surface( $container, document ) { |
| 22 | +function Surface( $container, doc ) { |
23 | 23 | var surface = this; |
24 | 24 | |
25 | 25 | this.$ = $container.addClass( 'editSurface' ); |
26 | | - this.document = document; |
| 26 | + this.doc = doc; |
27 | 27 | this.rendered = false; |
28 | 28 | this.location = null; |
29 | 29 | this.selection = new Selection(); |
30 | 30 | this.selecting = false; |
31 | 31 | this.keydownTimeout = null; |
32 | 32 | this.initialHorizontalCursorPosition = null; |
33 | | - |
| 33 | + |
| 34 | + // MouseDown on surface |
34 | 35 | this.$.bind({ |
35 | 36 | 'mousedown' : function(e) { |
36 | 37 | return surface.onMouseDown( e ); |
37 | | - }, |
38 | | - 'mousemove' : function(e) { |
39 | | - return surface.onMouseMove( e ); |
40 | | - }, |
41 | | - 'mouseup' : function(e) { |
42 | | - return surface.onMouseUp( e ); |
43 | 38 | } |
44 | 39 | }); |
45 | | - |
| 40 | + |
46 | 41 | // Selection |
47 | 42 | this.$ranges = $( '<div class="editSurface-ranges"></div>' ).prependTo( this.$ ); |
48 | 43 | this.$rangeStart = $( '<div class="editSurface-range"></div>' ).appendTo( this.$ranges ); |
— | — | @@ -51,7 +46,7 @@ |
52 | 47 | // Cursor |
53 | 48 | this.cursor = new Cursor(); |
54 | 49 | this.$.after( this.cursor.$ ); |
55 | | - |
| 50 | + |
56 | 51 | // Hidden input |
57 | 52 | this.$input = $( '<input class="editSurface-input" />' ) |
58 | 53 | .prependTo( this.$ ) |
— | — | @@ -62,11 +57,23 @@ |
63 | 58 | 'keyup' : function( e ) { |
64 | 59 | return surface.onKeyUp( e ); |
65 | 60 | }, |
| 61 | + 'focus' : function() { |
| 62 | + $(document).bind({ |
| 63 | + 'mousemove.es' : function(e) { |
| 64 | + return surface.onMouseMove( e ); |
| 65 | + }, |
| 66 | + 'mouseup.es' : function(e) { |
| 67 | + return surface.onMouseUp( e ); |
| 68 | + } |
| 69 | + }); |
| 70 | + }, |
66 | 71 | 'blur': function( e ) { |
| 72 | + $(document).unbind('mousemove.es'); |
| 73 | + $(document).unbind('mouseup.es'); |
67 | 74 | surface.cursor.hide(); |
68 | 75 | } |
69 | 76 | }); |
70 | | - |
| 77 | + |
71 | 78 | // First render |
72 | 79 | this.render(); |
73 | 80 | } |
— | — | @@ -425,10 +432,10 @@ |
426 | 433 | Surface.prototype.render = function( from ) { |
427 | 434 | if ( !this.rendered ) { |
428 | 435 | this.rendered = true; |
429 | | - this.$.append( this.document.$ ); |
430 | | - this.document.renderBlocks(); |
| 436 | + this.$.append( this.doc.$ ); |
| 437 | + this.doc.renderBlocks(); |
431 | 438 | } else { |
432 | | - this.document.updateBlocks(); |
| 439 | + this.doc.updateBlocks(); |
433 | 440 | } |
434 | 441 | }; |
435 | 442 | |
— | — | @@ -455,7 +462,7 @@ |
456 | 463 | } else { |
457 | 464 | // Multiple block annotation |
458 | 465 | for ( var i = from.block.getIndex(), end = to.block.getIndex(); i <= end; i++ ) { |
459 | | - var block = this.document.blocks[i]; |
| 466 | + var block = this.doc.blocks[i]; |
460 | 467 | if ( block === from.block ) { |
461 | 468 | // From offset to length |
462 | 469 | block.annotateContent( annotation, from.offset, block.getLength() ); |