-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-photo-swiper.min.js
1 lines (1 loc) · 2.46 KB
/
react-photo-swiper.min.js
1
"use strict";!function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t(require("react/addons"),require("swiper")):e.ReactPhotoSwiper=t(e.React,e.Swiper)}(this,function(e,t){var n={container:{},wrapper:{alignItems:"center"},child:{}},s={screenHeight:1080,threshold:300,minSpeed:.5},o=e.createClass({propTypes:{simulateTouch:e.PropTypes.bool,initialSlide:e.PropTypes.number,preloadImages:e.PropTypes.bool,lazyLoading:e.PropTypes.bool,lazyLoadingInPrevNext:e.PropTypes.bool,lazyLoadingOnTransitionStart:e.PropTypes.bool},componentDidMount:function(){if(this.isMounted()){var e=t(this.getDOMNode(),{direction:"vertical"});this.swiper=t(".swiper-container-h",this.props),this.bindSwiperEvents(e)}},componentWillUnmount:function(){this.swiper.destroy(),delete this.swiper},shouldComponentUpdate:function(e){return"undefined"!=typeof this.props.shouldUpdate&&this.props.shouldUpdate(e)},render:function(){return e.createElement("div",{className:"swiper-container swiper-container-v"},e.createElement("div",{className:"swiper-wrapper"},e.createElement("div",{className:"swiper-slide"},e.createElement("div",e.__spread({},this.props,{style:n.container,className:"swiper-container swiper-container-h"}),e.createElement("div",{style:n.wrapper,className:"swiper-wrapper"},e.Children.map(this.props.children,function(t){return e.addons.cloneWithProps(t,{style:n.child,className:"swiper-slide"})}))))))},bindSwiperEvents:function(e){var t=null,n=!1,o=0,i=!1,r=!1;e.on("touchStart",function(e,n){t=this.getPointFromEvent(n),o=n.timeStamp,i=!0}.bind(this)),e.on("touchMove",function(e,o){if(i){var a=this.getPointFromEvent(o);if(r||(n=this.detectCloseMove(t,a),r=!0),n&&this.props.onclosemove){var p=Math.abs(a.y-t.y),c=screen?screen.height:s.screenHeight;this.props.onclosemove(p/c)}}}.bind(this)),e.on("touchEnd",function(e,s){if(this.props.onclosemove&&this.props.onclosemove(0),this.props.onclose&&n){var a=this.getPointFromEvent(s),p=s.timeStamp;this.detectCloseGesture(t,a,o,p)&&this.props.onclose(),n=!1,i=!1,r=!1}}.bind(this))},detectCloseGesture:function(e,t,n,o){var i=screen?screen.height/2:s.threshold,r=t.x-e.x,a=t.y-e.y,p=o-n,c=Math.abs(a)/p;return Math.abs(a)>Math.abs(r)&&(Math.abs(a)>i||c>s.minSpeed)},detectCloseMove:function(e,t){var n=t.x-e.x,s=t.y-e.y;return Math.abs(s)>Math.abs(n)},getPointFromEvent:function(e){var t=null,n=null;return e instanceof MouseEvent?(t=e.screenX,n=e.screenY):e instanceof TouchEvent&&(t=e.changedTouches[0].screenX,n=e.changedTouches[0].screenY),{x:t,y:n}}});return o});