Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js |
— | — | @@ -4,11 +4,15 @@ |
5 | 5 | * @class |
6 | 6 | * @constructor |
7 | 7 | */ |
8 | | -es.SurfaceView = function( $container, surfaceModel ) { |
| 8 | +es.SurfaceView = function( $container, model ) { |
9 | 9 | this.$ = $container.addClass( 'editSurface' ); |
10 | | - this.model = surfaceModel; |
| 10 | + this.model = model; |
| 11 | + |
| 12 | + // Initialize document view |
11 | 13 | this.documentView = new es.DocumentView( this.model.getDocument() ); |
12 | 14 | this.$.append( this.documentView.$ ); |
| 15 | + |
| 16 | + // Interaction state |
13 | 17 | this.width = null; |
14 | 18 | this.mouse = { |
15 | 19 | 'selecting': false, |
— | — | @@ -30,25 +34,13 @@ |
31 | 35 | } |
32 | 36 | }; |
33 | 37 | |
34 | | - // Selection |
35 | | - this.$ranges = $( '<div class="editSurface-ranges"></div>' ).prependTo( this.$ ); |
36 | | - this.$rangeStart = $( '<div class="editSurface-range"></div>' ).appendTo( this.$ranges ); |
37 | | - this.$rangeFill = $( '<div class="editSurface-range"></div>' ).appendTo( this.$ranges ); |
38 | | - this.$rangeEnd = $( '<div class="editSurface-range"></div>' ).appendTo( this.$ranges ); |
39 | | - |
40 | 38 | // Cursor |
41 | 39 | this.blinkInterval = null; |
42 | 40 | this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ ); |
43 | 41 | |
44 | | - // Resize |
45 | | - var surfaceView = this; |
46 | | - $(window).resize( function() { |
47 | | - var width = surfaceView.$.width(); |
48 | | - if ( surfaceView.width !== width ) { |
49 | | - surfaceView.width = width; |
50 | | - surfaceView.documentView.renderContent(); |
51 | | - } |
52 | | - } ); |
| 42 | + // References for use in closures |
| 43 | + var surfaceView = this, |
| 44 | + $document = $(document); |
53 | 45 | |
54 | 46 | // MouseDown on surface |
55 | 47 | this.$.bind( { |
— | — | @@ -58,12 +50,11 @@ |
59 | 51 | } ); |
60 | 52 | |
61 | 53 | // Hidden input |
62 | | - var $document = $(document); |
63 | 54 | this.$input = $( '<input class="editSurface-input" />' ) |
64 | 55 | .prependTo( this.$ ) |
65 | 56 | .bind( { |
66 | 57 | 'focus' : function() { |
67 | | - $(document).bind({ |
| 58 | + $document.bind({ |
68 | 59 | 'mousemove.editSurface' : function(e) { |
69 | 60 | return surfaceView.onMouseMove( e ); |
70 | 61 | }, |
— | — | @@ -93,9 +84,14 @@ |
94 | 85 | } |
95 | 86 | } ); |
96 | 87 | |
| 88 | + // Re-render when resizing horizontally |
97 | 89 | $(window).resize( function() { |
98 | | - surfaceView.view.hideCursor(); |
99 | | - surfaceView.view.renderContent(); |
| 90 | + surfaceView.hideCursor(); |
| 91 | + var width = surfaceView.$.width(); |
| 92 | + if ( surfaceView.width !== width ) { |
| 93 | + surfaceView.width = width; |
| 94 | + surfaceView.documentView.renderContent(); |
| 95 | + } |
100 | 96 | } ); |
101 | 97 | |
102 | 98 | // First render |