Template:Team:HokkaidoU Japan/JS
From 2014.igem.org
(Difference between revisions)
Line 3: | Line 3: | ||
<script src="//ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.7.2.js"></script> | <script src="//ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.7.2.js"></script> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
+ | |||
+ | function and(a, b) { | ||
+ | if ( a ) { | ||
+ | return b; | ||
+ | } else { | ||
+ | return a; | ||
+ | } | ||
+ | } | ||
(function() { | (function() { | ||
Line 51: | Line 59: | ||
} | } | ||
}; | }; | ||
- | |||
- | |||
/** | /** | ||
Line 120: | Line 126: | ||
return event.handled; | return event.handled; | ||
}; | }; | ||
- | |||
- | |||
/** | /** | ||
* Only attaches one event handler for all types ... | * Only attaches one event handler for all types ... | ||
Line 183: | Line 187: | ||
(function($){ | (function($){ | ||
var isPhantom = /Phantom/.test(navigator.userAgent), | var isPhantom = /Phantom/.test(navigator.userAgent), | ||
- | supportTouch = !isPhantom | + | supportTouch =and( !isPhantom , "ontouchend" in document,) |
scrollEvent = "touchmove scroll", | scrollEvent = "touchmove scroll", | ||
// Use touch events or map it to mouse events | // Use touch events or map it to mouse events | ||
Line 276: | Line 280: | ||
$(this).unbind( touchMoveEvent, moveHandler); | $(this).unbind( touchMoveEvent, moveHandler); | ||
// if start and stop contain data figure out if we have a swipe event | // if start and stop contain data figure out if we have a swipe event | ||
- | if ( | + | if ( and(start , stop ) { |
// calculate the distance between start and stop data | // calculate the distance between start and stop data | ||
var deltaX = Math.abs(start.coords[0] - stop.coords[0]), | var deltaX = Math.abs(start.coords[0] - stop.coords[0]), | ||
deltaY = Math.abs(start.coords[1] - stop.coords[1]), | deltaY = Math.abs(start.coords[1] - stop.coords[1]), | ||
- | distance = Math.sqrt(deltaX*deltaX+deltaY*deltaY); | + | distance = Math.sqrt(deltaX*deltaX+deltaY*deltaY); |
// check if the delay and distance are matched | // check if the delay and distance are matched | ||
- | if ( stop.time - start.time < swipe.delay | + | if ( and(stop.time - start.time < swipe.delay , distance >= swipe.min) ) { |
var events = ['swipe']; | var events = ['swipe']; | ||
// check if we moved horizontally | // check if we moved horizontally | ||
- | if( deltaX >= swipe.min | + | if( and(deltaX >= swipe.min , deltaY < swipe.min)) { |
// based on the x coordinate check if we moved left or right | // based on the x coordinate check if we moved left or right | ||
events.push( start.coords[0] > stop.coords[0] ? "swipeleft" : "swiperight" ); | events.push( start.coords[0] > stop.coords[0] ? "swipeleft" : "swiperight" ); | ||
- | + | } else | |
// check if we moved vertically | // check if we moved vertically | ||
- | if(deltaY >= swipe.min | + | if(and(deltaY >= swipe.min , deltaX < swipe.min)){ |
// based on the y coordinate check if we moved up or down | // based on the y coordinate check if we moved up or down | ||
events.push( start.coords[1] < stop.coords[1] ? "swipedown" : "swipeup" ); | events.push( start.coords[1] < stop.coords[1] ? "swipedown" : "swipeup" ); | ||
- | + | } | |
- | + | ||
// trigger swipe events on this guy | // trigger swipe events on this guy | ||
Line 310: | Line 313: | ||
})(jQuery) | })(jQuery) | ||
+ | |||
+ | |||
+ | |||
</script> | </script> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
- | |||
/** | /** | ||
Line 347: | Line 352: | ||
return (computedStyle === val); | return (computedStyle === val); | ||
}); | }); | ||
- | + | ||
- | + | ||
/* | /* | ||
* debouncedresize: special jQuery event that happens once after a window resize | * debouncedresize: special jQuery event that happens once after a window resize | ||
Line 463: | Line 467: | ||
}; | }; | ||
this.transEndEventName = transEndEventNames[Modernizr.prefixed( 'transition' )] + '.bookblock'; | this.transEndEventName = transEndEventNames[Modernizr.prefixed( 'transition' )] + '.bookblock'; | ||
- | // support css 3d transforms && css transitions && Modernizr.csstransformspreserve3d | + | // support css 3d transforms && css transitions && Modernizr.csstransformspreserve3d This is just comment |
- | this.support = Modernizr.csstransitions | + | this.support = and( Modernizr.csstransitions , and (Modernizr.csstransforms3d , Modernizr.csstransformspreserve3d)); |
// initialize/bind some events | // initialize/bind some events | ||
this._initEvents(); | this._initEvents(); | ||
Line 511: | Line 515: | ||
this.current = page; | this.current = page; | ||
} | } | ||
- | else if ( dir === 'next' | + | else if ( and (dir === 'next' , this.options.direction === 'ltr' )|| and(dir === 'prev' , this.options.direction === 'rtl' )) { |
- | if ( !this.options.circular | + | if ( !this.options.circular && this.current === this.itemsCount - 1 ) { |
this.end = true; | this.end = true; | ||
- | + | } | |
else { | else { | ||
this.previous = this.current; | this.previous = this.current; | ||
this.current = this.current < this.itemsCount - 1 ? this.current + 1 : 0; | this.current = this.current < this.itemsCount - 1 ? this.current + 1 : 0; | ||
} | } | ||
- | + | } | |
- | else if ( dir === 'prev' | + | else if ( and(dir === 'prev' , this.options.direction === 'ltr') || and(dir === 'next' , this.options.direction === 'rtl' )) { |
- | if ( !this.options.circular | + | if (and( !this.options.circular , this.current === 0 )) { |
this.end = true; | this.end = true; | ||
- | + | } | |
else { | else { | ||
this.previous = this.current; | this.previous = this.current; | ||
this.current = this.current > 0 ? this.current - 1 : this.itemsCount - 1; | this.current = this.current > 0 ? this.current - 1 : this.itemsCount - 1; | ||
} | } | ||
- | + | } | |
- | this.$nextItem = !this.options.circular | + | this.$nextItem = and( !this.options.circular , this.end) ? this.$current : this.$items.eq( this.current ); |
if ( !this.support ) { | if ( !this.support ) { | ||
Line 544: | Line 548: | ||
this.end = false; | this.end = false; | ||
this.isAnimating = false; | this.isAnimating = false; | ||
- | var isLimit = dir === 'next' | + | var isLimit = and (dir === 'next' , this.current === this.itemsCount - 1) || and( dir === 'prev' , this.current === 0); |
// callback trigger | // callback trigger | ||
this.options.onEndFlip( this.previous, this.current, isLimit ); | this.options.onEndFlip( this.previous, this.current, isLimit ); | ||
Line 577: | Line 581: | ||
self.end = false; | self.end = false; | ||
self.isAnimating = false; | self.isAnimating = false; | ||
- | var isLimit = dir === 'next' | + | var isLimit = and( dir === 'next' , self.current === self.itemsCount - 1) || and(dir === 'prev' , self.current === 0); |
// callback trigger | // callback trigger | ||
self.options.onEndFlip( self.previous, self.current, isLimit ); | self.options.onEndFlip( self.previous, self.current, isLimit ); | ||
Line 588: | Line 592: | ||
// overlays | // overlays | ||
- | if (this.options.shadows | + | if (and(this.options.shadows , !this.end)) { |
var o_left_style = (dir === 'next') ? { | var o_left_style = (dir === 'next') ? { | ||
Line 620: | Line 624: | ||
$o_right.css(o_right_style); | $o_right.css(o_right_style); | ||
- | + | } | |
setTimeout( function() { | setTimeout( function() { | ||
Line 627: | Line 631: | ||
// overlays | // overlays | ||
- | if ( self.options.shadows | + | if (and( self.options.shadows , !self.end) ) { |
$o_middle_f.css({ | $o_middle_f.css({ | ||
Line 645: | Line 649: | ||
}); | }); | ||
- | + | } | |
}, 25 ); | }, 25 ); | ||
}, | }, | ||
Line 837: | Line 841: | ||
} )( jQuery, window ); | } )( jQuery, window ); | ||
+ | |||
+ | |||
</script> | </script> |
Revision as of 03:40, 14 September 2014