@@ -73,7 +73,7 @@ var ZoomerPrototype = function()
7373 this . _handle_ele_onmouseup_bound = this . handle_ele_onmouseup . bind ( this ) ;
7474 this . _handle_ele_onkeydown_bound = this . handle_ele_onkeydown . bind ( this ) ;
7575
76- this . _update_overlay_position_bound = this . _update_overlay_position . bind ( this ) ;
76+ this . _update_bound = this . _update . bind ( this ) ;
7777
7878 if ( zoomer_ele )
7979 this . set_zoomer_element ( zoomer_ele ) ;
@@ -123,13 +123,13 @@ var ZoomerPrototype = function()
123123 if ( event . which != 1 )
124124 return ;
125125 document . addEventListener ( "mousemove" , this . _zoomer_ele_onmousemove_bound ) ;
126- document . addEventListener ( "mousemove" , this . _zoomer_ele_onmousemove_once_bound )
127126 document . addEventListener ( "mouseup" , this . _zoomer_ele_onmouseup_bound ) ;
128127 var mouse_x = event . clientX - this . _zoomer_ele_left ;
129128 this . _overlay_left = mouse_x ;
130129 this . _overlay_right = this . _to_right_x ( mouse_x ) ;
131130 this . _mouse_drag_start_x = mouse_x ;
132131 event . preventDefault ( ) ;
132+ // TODO: need to remove e.g. mousehweel event handlers here
133133 } ;
134134
135135 this . zoomer_ele_onmousemove = function ( event )
@@ -148,7 +148,6 @@ var ZoomerPrototype = function()
148148 this . _overlay_left = this . _mouse_drag_start_x ;
149149 this . change_overlay_size ( 0 , diff ) ;
150150 }
151- this . _set_model_area ( ) ;
152151 } ;
153152
154153 this . zoomer_ele_onmousewheel = function ( event )
@@ -157,15 +156,13 @@ var ZoomerPrototype = function()
157156 var diff = ( mouse_x < this . _overlay_left ) ? 5 : - 5 ;
158157 diff *= ( event . wheelDelta > 0 ) ? 1 : - 1 ;
159158 this . move_overlay ( diff ) ;
160- this . _set_model_area ( ) ;
161159 event . stopPropagation ( ) ;
162160 } ;
163161
164162 this . zoomer_ele_onmouseup = function ( event )
165163 {
166164 document . documentElement . classList . remove ( "overlay-size-change" ) ;
167165 document . removeEventListener ( "mousemove" , this . _zoomer_ele_onmousemove_bound ) ;
168- document . removeEventListener ( "mousemove" , this . _zoomer_ele_onmousemove_once_bound )
169166 document . removeEventListener ( "mouseup" , this . _zoomer_ele_onmouseup_bound ) ;
170167 var mouse_x = event . clientX - this . _zoomer_ele_left ;
171168 if ( this . _mouse_drag_start_x == mouse_x )
@@ -198,14 +195,12 @@ var ZoomerPrototype = function()
198195 var mouse_to_handle_diff = this . _mouse_drag_start_x - this . _overlay_start_left ;
199196 var diff = mouse_x - this . _overlay_left - mouse_to_handle_diff ;
200197 this . move_overlay ( diff ) ;
201- this . _set_model_area ( ) ;
202198 } ;
203199
204200 this . overlay_ele_onmousewheel = function ( event )
205201 {
206202 var diff = ( event . wheelDelta < 0 ) ? 5 : - 5 ;
207203 this . change_overlay_size ( diff , - diff ) ;
208- this . _set_model_area ( ) ;
209204 event . stopPropagation ( ) ;
210205 } ;
211206
@@ -221,7 +216,6 @@ var ZoomerPrototype = function()
221216 if ( ! diff )
222217 return ;
223218 this . move_overlay ( diff ) ;
224- this . _set_model_area ( ) ;
225219 event . stopPropagation ( ) ;
226220 } ;
227221
@@ -281,7 +275,6 @@ var ZoomerPrototype = function()
281275 var diff = mouse_x - this . _to_right_x ( this . _overlay_right ) - mouse_to_handle_diff ;
282276 this . set_overlay_position ( static_pos , this . _to_right_x ( this . _overlay_right ) + diff ) ;
283277 }
284- this . _set_model_area ( ) ;
285278 } ;
286279
287280 this . handle_ele_onkeydown = function ( event )
@@ -304,7 +297,6 @@ var ZoomerPrototype = function()
304297 if ( this . _overlay_left - diff < this . _to_right_x ( this . _overlay_right ) )
305298 this . change_overlay_size ( 0 , diff ) ;
306299 }
307- this . _set_model_area ( ) ;
308300 event . stopPropagation ( ) ;
309301 } ;
310302
@@ -317,46 +309,18 @@ var ZoomerPrototype = function()
317309 this . _handle_ele = null ;
318310 } ;
319311
320- // TODO: very temporary
321- this . fast_throttle = true ;
322- this . _set_model_area = function ( )
312+ /**
313+ * Request update of the overlay position.
314+ */
315+ this . _request_update = function ( )
323316 {
324- // TODO: very temporary
325- if ( this . fast_throttle )
326- {
327- window . clearTimeout ( this . _update_timeout ) ;
328- var now = Date . now ( ) ;
329- var time_since_last_update = now - this . _last_update ;
330- if ( time_since_last_update > UPDATE_THRESHOLD )
331- {
332- var ms_unit = this . _model . get_duration ( ) / this . _model . get_model_element_width ( ) ;
333- var x0 = this . _overlay_left * ms_unit ;
334- var x1 = this . _to_right_x ( this . _overlay_right ) * ms_unit ;
335- this . _model . set_area ( x0 , x1 ) ;
336- this . _last_update = now ;
337- }
338-
339- // Set a timeout to set the area. This makes sure that the last update
340- // always happens, even if it was within the UPDATE_THRESHOLD.
341- this . _update_timeout = window . setTimeout ( function ( ) {
342- var ms_unit = this . _model . get_duration ( ) / this . _model . get_model_element_width ( ) ;
343- var x0 = this . _overlay_left * ms_unit ;
344- var x1 = this . _to_right_x ( this . _overlay_right ) * ms_unit ;
345- this . _model . set_area ( x0 , x1 ) ;
346- } . bind ( this ) , UPDATE_THRESHOLD ) ;
347- }
348- else
349- {
350- window . clearTimeout ( this . _update_timeout ) ;
351- // Set a timeout to set the area. This makes sure that the last update
352- // always happens, even if it was within the UPDATE_THRESHOLD.
353- this . _update_timeout = window . setTimeout ( function ( ) {
354- var ms_unit = this . _model . get_duration ( ) / this . _model . get_model_element_width ( ) ;
355- var x0 = this . _overlay_left * ms_unit ;
356- var x1 = this . _to_right_x ( this . _overlay_right ) * ms_unit ;
357- this . _model . set_area ( x0 , x1 ) ;
358- } . bind ( this ) , UPDATE_THRESHOLD ) ;
359- }
317+ window . requestAnimationFrame ( this . _update_bound ) ;
318+ } ;
319+
320+ this . _update = function ( )
321+ {
322+ this . _update_overlay_position ( ) ;
323+ this . _set_model_area ( ) ;
360324 } ;
361325
362326 /**
@@ -366,18 +330,17 @@ var ZoomerPrototype = function()
366330 {
367331 if ( ! this . _overlay_ele )
368332 return ;
369- // TODO: no need to set this all the time
370333 this . _overlay_ele . style . display = "block" ;
371334 this . _overlay_ele . style . left = this . _overlay_left + "px" ;
372335 this . _overlay_ele . style . right = this . _overlay_right + "px" ;
373336 } ;
374337
375- /**
376- * Request update of the overlay position.
377- */
378- this . _request_update_overlay_position = function ( )
338+ this . _set_model_area = function ( )
379339 {
380- window . requestAnimationFrame ( this . _update_overlay_position_bound ) ;
340+ var ms_unit = this . _model . get_duration ( ) / this . _model . get_model_element_width ( ) ;
341+ var x0 = this . _overlay_left * ms_unit ;
342+ var x1 = this . _to_right_x ( this . _overlay_right ) * ms_unit ;
343+ this . _model . set_area ( x0 , x1 ) ;
381344 } ;
382345
383346 /**
@@ -445,8 +408,9 @@ var ZoomerPrototype = function()
445408 this . move_overlay = function ( diff )
446409 {
447410 if ( diff == null )
448- diff = 0 ;
449- else if ( diff < 0 )
411+ return ;
412+
413+ if ( diff < 0 )
450414 diff = Math . max ( this . _overlay_left + diff , 0 ) - this . _overlay_left ;
451415 else
452416 diff = Math . min ( diff , this . _overlay_right ) ;
@@ -479,9 +443,9 @@ var ZoomerPrototype = function()
479443 this . _overlay_left = Math . max ( 0 , Math . min ( left , right ) ) ;
480444 this . _overlay_right = Math . max ( 0 , this . _to_right_x ( Math . max ( left , right ) ) ) ;
481445 if ( ! immediate )
482- this . _request_update_overlay_position ( ) ;
446+ this . _request_update ( ) ;
483447 else
484- this . _update_overlay_position ( ) ;
448+ this . _update ( ) ;
485449 } ;
486450
487451 /**
0 commit comments