diff --git a/build/scooch.min.js b/build/scooch.min.js index d65bd15..88a691d 100644 --- a/build/scooch.min.js +++ b/build/scooch.min.js @@ -1,2 +1,2 @@ -/*! scooch 0.3.4 2014-08-26 */ +/*! scooch 0.4.0 2014-09-02 */ (function(t){if("function"==typeof define&&define.amd)define(["$"],t);else{var e=window.Mobify&&window.Mobify.$||window.Zepto||window.jQuery;t(e)}})(function(t){var e=function(t){var e={},i=navigator.userAgent,n=t.support=t.support||{};t.extend(t.support,{touch:"ontouchend"in document}),e.events=n.touch?{down:"touchstart",move:"touchmove",up:"touchend"}:{down:"mousedown",move:"mousemove",up:"mouseup"},e.getCursorPosition=n.touch?function(t){return t=t.originalEvent||t,{x:t.touches[0].clientX,y:t.touches[0].clientY}}:function(t){return{x:t.clientX,y:t.clientY}},e.getProperty=function(t){for(var e=["Webkit","Moz","O","ms",""],i=document.createElement("div").style,n=0;e.length>n;++n)if(void 0!==i[e[n]+t])return e[n]+t},t.extend(n,{transform:!!e.getProperty("Transform"),transform3d:!(!(window.WebKitCSSMatrix&&"m11"in new WebKitCSSMatrix)||/android\s+[1-2]/i.test(i))});var s=e.getProperty("Transform");e.translateX=n.transform3d?function(t,e){"number"==typeof e&&(e+="px"),t.style[s]="translate3d("+e+",0,0)"}:n.transform?function(t,e){"number"==typeof e&&(e+="px"),t.style[s]="translate("+e+",0)"}:function(t,e){"number"==typeof e&&(e+="px"),t.style.left=e};var o=(e.getProperty("Transition"),e.getProperty("TransitionDuration"));return e.setTransitions=function(t,e){t.style[o]=e?"":"0s"},e.requestAnimationFrame=function(){var t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},e=function(){t.apply(window,arguments)};return e}(),e}(t),i=function(t,e){var i={dragRadius:10,moveRadius:20,animate:!0,classPrefix:"m-",classNames:{outer:"scooch",inner:"scooch-inner",item:"item",center:"center",touch:"has-touch",dragging:"dragging",active:"active",fluid:"fluid"}},n=t.support,s=function(t,e){this.setOptions(e),this.initElements(t),this.initOffsets(),this.initAnimation(),this.bind(),this._updateCallbacks=[]};return s.defaults=i,s.prototype.setOptions=function(e){var n=this.options||t.extend({},i,e);n.classNames=t.extend({},n.classNames,e.classNames||{}),this.options=n},s.prototype.initElements=function(e){this._index=1,this.element=e,this.$element=t(e),this.$inner=this.$element.find("."+this._getClass("inner")),this.$items=this.$inner.children(),this.$start=this.$items.eq(0),this.$sec=this.$items.eq(1),this.$current=this.$items.eq(this._index-1),this._length=this.$items.length,this._alignment=this.$element.hasClass(this._getClass("center"))?.5:0,this._isFluid=this.$element.hasClass(this._getClass("fluid"))},s.prototype.initOffsets=function(){this._offsetDrag=0},s.prototype.initAnimation=function(){this.animating=!1,this.dragging=!1,this._needsUpdate=!1,this._enableAnimation()},s.prototype._getClass=function(t){return this.options.classPrefix+this.options.classNames[t]},s.prototype._enableAnimation=function(){this.animating||(e.setTransitions(this.$inner[0],!0),this.$inner.removeClass(this._getClass("dragging")),this.animating=!0)},s.prototype._disableAnimation=function(){this.animating&&(e.setTransitions(this.$inner[0],!1),this.$inner.addClass(this._getClass("dragging")),this.animating=!1)},s.prototype.refresh=function(){this.$items=this.$inner.children("."+this._getClass("item")),this.$start=this.$items.eq(0),this.$sec=this.$items.eq(1),this._length=this.$items.length,this.update()},s.prototype.update=function(t){if(t!==void 0&&this._updateCallbacks.push(t),!this._needsUpdate){this._needsUpdate=!0;var i=this;e.requestAnimationFrame(function(){i._update(),setTimeout(function(){for(var t=0,e=i._updateCallbacks.length;e>t;t++)i._updateCallbacks[t].call(i);i._updateCallbacks=[]},10)})}},s.prototype._update=function(){if(this._needsUpdate){var t=this.$current,i=this.$start,n=t.prop("offsetLeft")+t.prop("clientWidth")*this._alignment,s=i.prop("offsetLeft")+i.prop("clientWidth")*this._alignment,o=Math.round(-(n-s)+this._offsetDrag);e.translateX(this.$inner[0],o),this._needsUpdate=!1}},s.prototype.bind=function(){function i(t){n.touch||t.preventDefault(),c=!0,m=!1,r=e.getCursorPosition(t),h=0,u=0,d=!1,p._disableAnimation(),$=1==p._index,y=p._index==p._length}function s(t){if(c&&!m){var i=e.getCursorPosition(t),n=p.$element.width();h=r.x-i.x,u=r.y-i.y,d||l(h)>l(u)&&l(h)>f?(d=!0,t.preventDefault(),$&&0>h?h=h*-n/(h-n):y&&h>0&&(h=h*n/(h+n)),p._offsetDrag=-h,p.update()):l(u)>l(h)&&l(u)>f&&(m=!0)}}function o(){c&&(c=!1,p._enableAnimation(),!m&&l(h)>v.moveRadius?h>0?p.next():p.prev():(p._offsetDrag=0,p.update()))}function a(t){d&&t.preventDefault()}var r,h,u,d,l=Math.abs,c=!1,m=!1,f=this.options.dragRadius,p=this,g=this.$element,_=this.$inner,v=this.options,$=!1,y=!1,w=t(window).width();_.on(e.events.down+".scooch",i).on(e.events.move+".scooch",s).on(e.events.up+".scooch",o).on("click.scooch",a).on("mouseout.scooch",o),g.on("click","[data-m-slide]",function(e){e.preventDefault();var i=t(this).attr("data-m-slide"),n=parseInt(i,10);isNaN(n)?p[i]():p.move(n)}),g.on("afterSlide",function(t,e,i){p.$items.eq(e-1).removeClass(p._getClass("active")),p.$items.eq(i-1).addClass(p._getClass("active")),p.$element.find("[data-m-slide='"+e+"']").removeClass(p._getClass("active")),p.$element.find("[data-m-slide='"+i+"']").addClass(p._getClass("active"))}),t(window).on("resize orientationchange",function(){w!=t(window).width()&&(p._disableAnimation(),w=t(window).width(),p.update())}),g.trigger("beforeSlide",[1,1]),g.trigger("afterSlide",[1,1]),p.update()},s.prototype.unbind=function(){this.$inner.off()},s.prototype.destroy=function(){this.unbind(),this.$element.trigger("destroy"),this.$element.remove(),this.$element=null,this.$inner=null,this.$start=null,this.$current=null},s.prototype.move=function(e,i){var n=this.$element,s=(this.$inner,this.$items),o=(this.$start,this.$current),a=this._length,r=this._index;i=t.extend({},this.options,i),1>e?e=1:e>this._length&&(e=a),e==this._index,i.animate?this._enableAnimation():this._disableAnimation(),n.trigger("beforeSlide",[r,e]),this.$current=o=s.eq(e-1),this._offsetDrag=0,this._index=e,i.animate?this.update():this.update(function(){this._enableAnimation()}),n.trigger("afterSlide",[r,e])},s.prototype.next=function(){this.move(this._index+1)},s.prototype.prev=function(){this.move(this._index-1)},s}(t,e);t.fn.scooch=function(e,n){var s=t.extend({},t.fn.scooch.defaults);return"object"==typeof e&&(t.extend(s,e,!0),n=null,e=null),n=Array.prototype.slice.apply(arguments),this.each(function(){var o=(t(this),this._scooch);o||(o=new i(this,s)),e&&(o[e].apply(o,n.slice(1)),"destroy"===e&&(o=null)),this._scooch=o}),this},t.fn.scooch.defaults={}}); \ No newline at end of file