@@ -12,8 +12,6 @@ var Zoomer = function(model, zoomer_ele)
1212
1313var ZoomerPrototype = function ( )
1414{
15- var UPDATE_THRESHOLD = 50 ;
16-
1715 this . _init = function ( model , zoomer_ele )
1816 {
1917 /**
@@ -58,19 +56,20 @@ var ZoomerPrototype = function()
5856 */
5957 this . _last_update = 0 ;
6058
61- this . _zoomer_ele_onmousemove_bound = this . zoomer_ele_onmousemove . bind ( this ) ;
62- this . _zoomer_ele_onmouseup_bound = this . zoomer_ele_onmouseup . bind ( this ) ;
63- this . _zoomer_ele_onmousewheel_bound = this . zoomer_ele_onmousewheel . bind ( this ) ;
64- this . _overlay_ele_onmousedown_bound = this . overlay_ele_onmousedown . bind ( this ) ;
65- this . _overlay_ele_onmousemove_bound = this . overlay_ele_onmousemove . bind ( this ) ;
66- this . _overlay_ele_onmouseup_bound = this . overlay_ele_onmouseup . bind ( this ) ;
67- this . _overlay_ele_onmousewheel_bound = this . overlay_ele_onmousewheel . bind ( this ) ;
68- this . _overlay_ele_onkeydown_bound = this . overlay_ele_onkeydown . bind ( this ) ;
69- this . _overlay_ele_ondblclick_bound = this . overlay_ele_ondblclick . bind ( this ) ;
70- this . _handle_ele_onmousedown_bound = this . handle_ele_onmousedown . bind ( this ) ;
71- this . _handle_ele_onmousemove_bound = this . handle_ele_onmousemove . bind ( this ) ;
72- this . _handle_ele_onmouseup_bound = this . handle_ele_onmouseup . bind ( this ) ;
73- this . _handle_ele_onkeydown_bound = this . handle_ele_onkeydown . bind ( this ) ;
59+ this . _zoomer_ele_onmousedown_bound = this . _zoomer_ele_onmousedown . bind ( this ) ;
60+ this . _zoomer_ele_onmousemove_bound = this . _zoomer_ele_onmousemove . bind ( this ) ;
61+ this . _zoomer_ele_onmouseup_bound = this . _zoomer_ele_onmouseup . bind ( this ) ;
62+ this . _zoomer_ele_onmousewheel_bound = this . _zoomer_ele_onmousewheel . bind ( this ) ;
63+ this . _overlay_ele_onmousedown_bound = this . _overlay_ele_onmousedown . bind ( this ) ;
64+ this . _overlay_ele_onmousemove_bound = this . _overlay_ele_onmousemove . bind ( this ) ;
65+ this . _overlay_ele_onmouseup_bound = this . _overlay_ele_onmouseup . bind ( this ) ;
66+ this . _overlay_ele_onmousewheel_bound = this . _overlay_ele_onmousewheel . bind ( this ) ;
67+ this . _overlay_ele_onkeydown_bound = this . _overlay_ele_onkeydown . bind ( this ) ;
68+ this . _overlay_ele_ondblclick_bound = this . _overlay_ele_ondblclick . bind ( this ) ;
69+ this . _handle_ele_onmousedown_bound = this . _handle_ele_onmousedown . bind ( this ) ;
70+ this . _handle_ele_onmousemove_bound = this . _handle_ele_onmousemove . bind ( this ) ;
71+ this . _handle_ele_onmouseup_bound = this . _handle_ele_onmouseup . bind ( this ) ;
72+ this . _handle_ele_onkeydown_bound = this . _handle_ele_onkeydown . bind ( this ) ;
7473
7574 this . _update_bound = this . _update . bind ( this ) ;
7675
@@ -88,7 +87,7 @@ var ZoomerPrototype = function()
8887 this . _zoomer_ele_dims = this . _zoomer_ele . getBoundingClientRect ( ) ;
8988 this . _zoomer_ele_left = this . _zoomer_ele_dims . left ;
9089 this . _zoomer_ele_width = this . _zoomer_ele_dims . width - zoomer_ele_hor_borders ;
91- this . _zoomer_ele . addEventListener ( "mousedown" , this . zoomer_ele_onmousedown . bind ( this ) ) ;
90+ this . _zoomer_ele . addEventListener ( "mousedown" , this . _zoomer_ele_onmousedown_bound ) ;
9291 } ;
9392
9493 this . _set_up_overlay_ele = function ( )
@@ -117,7 +116,7 @@ var ZoomerPrototype = function()
117116 // Zoomer element event handlers
118117 //
119118
120- this . zoomer_ele_onmousedown = function ( event )
119+ this . _zoomer_ele_onmousedown = function ( event )
121120 {
122121 if ( event . which != 1 )
123122 return ;
@@ -131,7 +130,7 @@ var ZoomerPrototype = function()
131130 // TODO: need to remove e.g. mousehweel event handlers here
132131 } ;
133132
134- this . zoomer_ele_onmousemove = function ( event )
133+ this . _zoomer_ele_onmousemove = function ( event )
135134 {
136135 document . documentElement . classList . add ( "overlay-size-change" ) ;
137136 var mouse_x = event . clientX - this . _zoomer_ele_left ;
@@ -149,7 +148,7 @@ var ZoomerPrototype = function()
149148 }
150149 } ;
151150
152- this . zoomer_ele_onmousewheel = function ( event )
151+ this . _zoomer_ele_onmousewheel = function ( event )
153152 {
154153 var mouse_x = event . clientX - this . _zoomer_ele_left ;
155154 var diff = ( mouse_x < this . _overlay_left ) ? 5 : - 5 ;
@@ -158,7 +157,7 @@ var ZoomerPrototype = function()
158157 event . stopPropagation ( ) ;
159158 } ;
160159
161- this . zoomer_ele_onmouseup = function ( event )
160+ this . _zoomer_ele_onmouseup = function ( event )
162161 {
163162 document . documentElement . classList . remove ( "overlay-size-change" ) ;
164163 document . removeEventListener ( "mousemove" , this . _zoomer_ele_onmousemove_bound ) ;
@@ -174,7 +173,7 @@ var ZoomerPrototype = function()
174173 // Overlay element event handlers
175174 //
176175
177- this . overlay_ele_onmousedown = function ( event )
176+ this . _overlay_ele_onmousedown = function ( event )
178177 {
179178 if ( event . which != 1 )
180179 return ;
@@ -188,22 +187,22 @@ var ZoomerPrototype = function()
188187 event . preventDefault ( ) ;
189188 } ;
190189
191- this . overlay_ele_onmousemove = function ( event )
190+ this . _overlay_ele_onmousemove = function ( event )
192191 {
193192 var mouse_x = event . clientX - this . _zoomer_ele_left ;
194193 var mouse_to_handle_diff = this . _mouse_drag_start_x - this . _overlay_start_left ;
195194 var diff = mouse_x - this . _overlay_left - mouse_to_handle_diff ;
196195 this . move_overlay ( diff ) ;
197196 } ;
198197
199- this . overlay_ele_onmousewheel = function ( event )
198+ this . _overlay_ele_onmousewheel = function ( event )
200199 {
201200 var diff = ( event . wheelDelta < 0 ) ? 5 : - 5 ;
202201 this . change_overlay_size ( diff , - diff ) ;
203202 event . stopPropagation ( ) ;
204203 } ;
205204
206- this . overlay_ele_onkeydown = function ( event )
205+ this . _overlay_ele_onkeydown = function ( event )
207206 {
208207 var width = this . _to_right_x ( this . _overlay_right ) - this . _overlay_left ;
209208 var diff = {
@@ -218,12 +217,12 @@ var ZoomerPrototype = function()
218217 event . stopPropagation ( ) ;
219218 } ;
220219
221- this . overlay_ele_ondblclick = function ( event )
220+ this . _overlay_ele_ondblclick = function ( event )
222221 {
223222 this . reset ( ) ;
224223 } ;
225224
226- this . overlay_ele_onmouseup = function ( event )
225+ this . _overlay_ele_onmouseup = function ( event )
227226 {
228227 document . documentElement . classList . remove ( "overlay-drag" ) ;
229228 document . removeEventListener ( "mousemove" , this . _overlay_ele_onmousemove_bound ) ;
@@ -235,7 +234,7 @@ var ZoomerPrototype = function()
235234 // Overlay handle element event handlers
236235 //
237236
238- this . handle_ele_onmousedown = function ( event )
237+ this . _handle_ele_onmousedown = function ( event )
239238 {
240239 if ( event . which != 1 )
241240 return ;
@@ -251,7 +250,7 @@ var ZoomerPrototype = function()
251250 event . preventDefault ( ) ;
252251 } ;
253252
254- this . handle_ele_onmousemove = function ( event )
253+ this . _handle_ele_onmousemove = function ( event )
255254 {
256255 var mouse_x = event . clientX - this . _zoomer_ele_left ;
257256 var is_left_handle = this . _handle_ele == this . _handle_left_ele ;
@@ -267,17 +266,17 @@ var ZoomerPrototype = function()
267266 if ( resize_left )
268267 {
269268 var diff = mouse_x - this . _overlay_left - mouse_to_handle_diff ;
270- this . set_overlay_position ( this . _overlay_left + diff , static_pos ) ;
269+ this . _set_overlay_position ( this . _overlay_left + diff , static_pos ) ;
271270 }
272271 else
273272 {
274273 var diff = mouse_x - this . _to_right_x ( this . _overlay_right ) - mouse_to_handle_diff ;
275- this . set_overlay_position ( static_pos , this . _to_right_x ( this . _overlay_right ) + diff ) ;
274+ this . _set_overlay_position ( static_pos , this . _to_right_x ( this . _overlay_right ) + diff ) ;
276275 }
277276 this . _request_update ( ) ;
278277 } ;
279278
280- this . handle_ele_onkeydown = function ( event )
279+ this . _handle_ele_onkeydown = function ( event )
281280 {
282281 var diff = {
283282 37 : - 1 , // Arrow left
@@ -293,14 +292,13 @@ var ZoomerPrototype = function()
293292 }
294293 else
295294 {
296- // TODO: check this calculation
297295 if ( this . _overlay_left - diff < this . _to_right_x ( this . _overlay_right ) )
298296 this . change_overlay_size ( 0 , diff ) ;
299297 }
300298 event . stopPropagation ( ) ;
301299 } ;
302300
303- this . handle_ele_onmouseup = function ( event )
301+ this . _handle_ele_onmouseup = function ( event )
304302 {
305303 document . documentElement . classList . remove ( "overlay-size-change" ) ;
306304 document . removeEventListener ( "mousemove" , this . _handle_ele_onmousemove_bound ) ;
@@ -338,6 +336,20 @@ var ZoomerPrototype = function()
338336 this . _overlay_ele . style . right = this . _overlay_right + "px" ;
339337 } ;
340338
339+ /**
340+ * Sets the left and right position of the overlay internally. To change
341+ * the element position, _update() has to be called.
342+ */
343+ this . _set_overlay_position = function ( left , right )
344+ {
345+ if ( left == null )
346+ left = 0 ;
347+ else if ( right == null )
348+ right = 0 ;
349+ this . _overlay_left = Math . max ( 0 , Math . min ( left , right ) ) ;
350+ this . _overlay_right = Math . max ( 0 , this . _to_right_x ( Math . max ( left , right ) ) ) ;
351+ } ;
352+
341353 /**
342354 * Sets the model area.
343355 */
@@ -370,8 +382,12 @@ var ZoomerPrototype = function()
370382 this . _handle_right_ele . addEventListener ( "mousedown" , this . _handle_ele_onmousedown_bound ) ;
371383 } ;
372384
385+ //
386+ // Public
387+ //
388+
373389 /**
374- * Resets the state of the overlay.
390+ * Reset the state of the overlay.
375391 */
376392 this . reset = function ( )
377393 {
@@ -401,15 +417,15 @@ var ZoomerPrototype = function()
401417 } ;
402418
403419 /**
404- * Sets the current state of the zoomer.
420+ * Set the current state of the zoomer.
405421 */
406422 this . set_current_area = function ( )
407423 {
408424 if ( ! this . _zoomer_ele . parentNode )
409425 this . _zoomer_ele . appendChild ( this . _overlay_ele ) ;
410426 var ms_unit = this . _model . get_model_element_width ( ) / this . _model . get_duration ( ) ;
411427 var area = this . _model . get_current_area ( ) ;
412- this . set_overlay_position ( Math . floor ( area . x0 * ms_unit ) , Math . ceil ( area . x1 * ms_unit ) ) ;
428+ this . _set_overlay_position ( Math . floor ( area . x0 * ms_unit ) , Math . ceil ( area . x1 * ms_unit ) ) ;
413429 this . _update_overlay_position ( ) ;
414430 this . _model . set_area ( area . x0 , area . x1 ) ;
415431 this . _finalize ( ) ;
@@ -421,7 +437,7 @@ var ZoomerPrototype = function()
421437 */
422438 this . move_overlay = function ( diff )
423439 {
424- if ( diff == null )
440+ if ( ! diff )
425441 return ;
426442
427443 if ( diff < 0 )
@@ -432,7 +448,7 @@ var ZoomerPrototype = function()
432448 } ;
433449
434450 /**
435- * Changes the size of the overlay.
451+ * Change the size of the overlay.
436452 */
437453 this . change_overlay_size = function ( left_diff , right_diff )
438454 {
@@ -442,26 +458,21 @@ var ZoomerPrototype = function()
442458 right_diff = 0 ;
443459 var left = this . _overlay_left + left_diff ;
444460 var right = this . _overlay_right - right_diff ;
445- this . set_overlay_position ( left , this . _to_right_x ( right ) ) ;
461+ this . _set_overlay_position ( left , this . _to_right_x ( right ) ) ;
446462 this . _request_update ( ) ;
447463 } ;
448464
449465 /**
450- * Sets the left and right position of the overlay internally. To change
451- * the element position, _update_overlay_position has to be called.
466+ * Set the position of the overlay.
452467 */
453468 this . set_overlay_position = function ( left , right )
454469 {
455- if ( left == null )
456- left = 0 ;
457- else if ( right == null )
458- right = 0 ;
459- this . _overlay_left = Math . max ( 0 , Math . min ( left , right ) ) ;
460- this . _overlay_right = Math . max ( 0 , this . _to_right_x ( Math . max ( left , right ) ) ) ;
470+ this . _set_overlay_position ( left , right ) ;
471+ this . _request_update ( ) ;
461472 } ;
462473
463474 /**
464- * Sets the zoomer element.
475+ * Set the zoomer element.
465476 */
466477 this . set_zoomer_element = function ( ele )
467478 {
0 commit comments