88 * - test CustomEffect
99 */
1010 ( function ( ) {
11- /* utils */
12- var mixinProps = function ( inObject , inProps ) {
13- if ( inProps ) {
14- Object . keys ( inProps ) . forEach ( function ( key ) {
15- inObject [ key ] = inProps [ key ] ;
16- } ) ;
17- }
18- }
19-
20- var invoke = function ( inObject , inEventName /* args */ ) {
21- var fn = inObject [ inEventName ] ;
22- if ( fn ) {
23- var args = Array . prototype . slice . call ( arguments , 2 ) ;
24- fn . apply ( inObject . context || window , args ) ;
25- }
26- }
27-
2811 var clamp = function ( inValue , inMin , inMax ) {
2912 return Math . max ( inMin , Math . min ( inValue , inMax ) ) ;
3013 }
3114
32- /* Scrubbed Animation */
33- var Scrub = function ( inProps ) {
34- // fallback to scrubbing x if zooming not available.
35- if ( inProps . scrubType ) {
36- if ( ! ( 'ontouchstart' in window ) && ( inProps . scrubType == 'zoom' ) ) {
37- inProps . scrubType = 'x' ;
38- }
39- this . scrubType = inProps . scrubType ;
40- }
41- mixinProps ( this , inProps ) ;
42- if ( ! this . snapPoints ) {
43- this . snapPoints = [ ] ;
44- }
45- if ( this . animation ) {
46- // create a player and pause the animation
47- document . timeline . play ( this . animation ) . paused = true ;
48- if ( this . startSnap ) {
49- this . currentTime = this . startSnap * this . duration ;
50- }
51- } else {
52- console . warn ( 'No animation set for scrub' ) ;
53- }
54- } ;
55-
56- Scrub . prototype = {
15+ Polymer ( 'polymer-scrub' , {
16+ target : null ,
17+ animation : null ,
5718 scale : 1 ,
5819 scrubType : 'x' ,
59- wrap : false ,
6020 nudgeTime : 1e-6 ,
61- get node ( ) {
21+ snapPoints : null ,
22+ startSnap : 0 ,
23+ snapThreshold : 0 ,
24+ wrap : false ,
25+ observe : {
26+ target : 'makeScrub' ,
27+ animation : 'makeScrub' ,
28+ scale : 'makeScrub' ,
29+ scrubType : 'makeScrub' ,
30+ nudgeTime : 'makeScrub' ,
31+ snapPoints : 'makeScrub' ,
32+ startSnap : 'makeScrub' ,
33+ snapThreshold : 'makeScrub' ,
34+ wrap : 'makeScrub'
35+ } ,
36+ get node ( ) {
6237 return this . _node ;
6338 } ,
6439 set node ( inNode ) {
165140 this . scrubEvent = e ;
166141 var d = this . calcDirection ( e ) ;
167142 this . forward = d < 0 ;
168- invoke ( this , "onStartScrub" , this ) ;
143+ // invoke(this, "onStartScrub", this);
169144 var length = this . node [ this . scrubType == 'y' ?
170145 'offsetHeight' : 'offsetWidth' ] ;
171146 if ( ! this . scrubbingStopped ) {
200175 this . scrubAnimation ( ) ;
201176 this . forward = 1 ;
202177 this . scrubEvent = e ;
203- invoke ( this , "onStartScrub" , this ) ;
178+ // invoke(this, "onStartScrub", this);
204179 if ( ! this . scrubbingStopped ) {
205180 this . playTo ( 3 ) ;
206181 }
336311 } ,
337312 get maxTime ( ) {
338313 return this . duration - ( this . wrap ? 0 : this . nudgeTime ) ;
339- }
340- } ;
341-
342- Polymer ( 'polymer-scrub' , {
343- target : null ,
344- animation : null ,
345- scale : 1 ,
346- scrubType : 'x' ,
347- nudgeTime : 1e-6 ,
348- snapPoints : null ,
349- startSnap : 0 ,
350- snapThreshold : 0 ,
351- observe : {
352- target : 'makeScrub' ,
353- animation : 'makeScrub' ,
354- scale : 'makeScrub' ,
355- scrubType : 'makeScrub' ,
356- nudgeTime : 'makeScrub' ,
357- snapPoints : 'makeScrub' ,
358- startSnap : 'makeScrub' ,
359- snapThreshold : 'makeScrub'
360314 } ,
361315 makeScrub : function ( ) {
362- if ( this . scrub ) {
363- this . scrub . destroy ( ) ;
364- this . scrub = null ;
365- }
316+ this . destroy ( ) ;
366317 if ( this . target && this . animation ) {
367- this . scrub = new Scrub ( {
368- node : this . target ,
369- animation : this . animation ,
370- scale : this . scale ,
371- scrubType : this . scrubType ,
372- nudgeTime : this . nudgeTime ,
373- snapPoints : this . snapPoints ,
374- snapThreshold : this . snapThreshold ,
375- startSnap : this . startSnap
376- } ) ;
318+ // fallback to scrubbing x if zooming not available.
319+ if ( this . scrubType ) {
320+ if ( ! ( 'ontouchstart' in window ) && ( this . scrubType == 'zoom' ) ) {
321+ this . scrubType = 'x' ;
322+ }
323+ }
324+ if ( ! this . snapPoints ) {
325+ this . snapPoints = [ ] ;
326+ }
327+ if ( this . animation ) {
328+ // create a player and pause the animation
329+ document . timeline . play ( this . animation ) . paused = true ;
330+ if ( this . startSnap ) {
331+ this . currentTime = this . startSnap * this . duration ;
332+ }
333+ } else {
334+ console . warn ( 'No animation set for scrub' ) ;
335+ }
336+ this . node = this . target ;
377337 }
378338 }
379- } )
339+ } ) ;
380340 } ) ( ) ;
381341 </ script >
382342</ polymer-element >
0 commit comments