Index: trunk/parsers/wikidom/lib/jquery.editSurface.js |
— | — | @@ -11,7 +11,53 @@ |
12 | 12 | .append( '<div class="editSurface-document"></div>' ) |
13 | 13 | .before( '<div class="editSurface-range"></div>' |
14 | 14 | + '<div class="editSurface-range"></div>' |
15 | | - + '<div class="editSurface-range"></div>'); |
| 15 | + + '<div class="editSurface-range"></div>') |
| 16 | + .mousedown( function( e ) { |
| 17 | + var $target = $( e.target ); |
| 18 | + // TODO: If the target is not a line, find the nearest line to the cursor and use it |
| 19 | + if ( $target.is( '.editSurface-line' ) ) { |
| 20 | + e.preventDefault(); |
| 21 | + e.stopPropagation(); |
| 22 | + sel = { |
| 23 | + 'active': true, |
| 24 | + 'from': null, |
| 25 | + 'to': null, |
| 26 | + 'start': getSelection( e ), |
| 27 | + 'end': null |
| 28 | + }; |
| 29 | + drawSelection( $target.parent() ); |
| 30 | + } |
| 31 | + return false; |
| 32 | + } ) |
| 33 | + .mouseup( function( e ) { |
| 34 | + var $target = $( e.target ); |
| 35 | + if ( !$target.is( '.editSurface-line' ) || !sel.from || !sel.to |
| 36 | + || ( sel.from.line === sel.to.line && sel.from.index === sel.to.index ) ) { |
| 37 | + sel.from = null; |
| 38 | + sel.to = null; |
| 39 | + sel.start = null; |
| 40 | + sel.end = null; |
| 41 | + } |
| 42 | + sel.active = false; |
| 43 | + drawSelection( $target.parent() ); |
| 44 | + } ) |
| 45 | + .mousemove( function( e ) { |
| 46 | + var $target = $( e.target ); |
| 47 | + // TODO: If the target is not a line, find the nearest line to the cursor and use it |
| 48 | + if ( $target.is( '.editSurface-line' ) && sel.active ) { |
| 49 | + sel.end = getSelection( e ); |
| 50 | + if ( sel.start.line < sel.end.line |
| 51 | + || ( sel.start.line === sel.end.line |
| 52 | + && sel.start.index < sel.end.index ) ) { |
| 53 | + sel.from = sel.start; |
| 54 | + sel.to = sel.end; |
| 55 | + } else { |
| 56 | + sel.from = sel.end; |
| 57 | + sel.to = sel.start; |
| 58 | + } |
| 59 | + drawSelection( $target.parent() ); |
| 60 | + } |
| 61 | + } ); |
16 | 62 | var ranges = { |
17 | 63 | '$all': $( '.editSurface-range' ), |
18 | 64 | '$first': $( '.editSurface-range:eq(0)' ), |
— | — | @@ -147,50 +193,6 @@ |
148 | 194 | lines.push( paragraph.lines[i].text ); |
149 | 195 | } |
150 | 196 | $paragraph.flow( lines.join( ' ' ) ); |
151 | | - $paragraph |
152 | | - .mousedown( function( e ) { |
153 | | - // TODO: If the target is not a line, find the nearest line to the cursor and use it |
154 | | - if ( $( e.target ).is( '.editSurface-line' ) ) { |
155 | | - e.preventDefault(); |
156 | | - e.stopPropagation(); |
157 | | - sel = { |
158 | | - 'active': true, |
159 | | - 'from': null, |
160 | | - 'to': null, |
161 | | - 'start': getSelection( e ), |
162 | | - 'end': null |
163 | | - }; |
164 | | - drawSelection( $paragraph ); |
165 | | - } |
166 | | - return false; |
167 | | - } ) |
168 | | - .mouseup( function( e ) { |
169 | | - if ( !$( e.target ).is( '.editSurface-line' ) || !sel.from || !sel.to |
170 | | - || ( sel.from.line === sel.to.line && sel.from.index === sel.to.index ) ) { |
171 | | - sel.from = null; |
172 | | - sel.to = null; |
173 | | - sel.start = null; |
174 | | - sel.end = null; |
175 | | - } |
176 | | - sel.active = false; |
177 | | - drawSelection( $paragraph ); |
178 | | - } ) |
179 | | - .mousemove( function( e ) { |
180 | | - // TODO: If the target is not a line, find the nearest line to the cursor and use it |
181 | | - if ( $( e.target ).is( '.editSurface-line' ) && sel.active ) { |
182 | | - sel.end = getSelection( e ); |
183 | | - if ( sel.start.line < sel.end.line |
184 | | - || ( sel.start.line === sel.end.line |
185 | | - && sel.start.index < sel.end.index ) ) { |
186 | | - sel.from = sel.start; |
187 | | - sel.to = sel.end; |
188 | | - } else { |
189 | | - sel.from = sel.end; |
190 | | - sel.to = sel.start; |
191 | | - } |
192 | | - drawSelection( $paragraph ); |
193 | | - } |
194 | | - } ); |
195 | 197 | } |
196 | 198 | |
197 | 199 | function update() { |