brutaldon-interfaccia-web-m.../brutaldon/static/js/jquery.p2r.min.js

1 line
5.5 KiB
JavaScript

+function(t,e){"use strict";var o=function(e,o){this.$element=t(e),this.options=t.extend({},self.DEFAULTS,o),this.$scroll=t(o.scroll),this.flags={prevented:!1,moving:!1,touched:!1,isTouch:!1,refreshed:!1},this.positions={startY:0,startX:0,currentY:0,currentX:0,lastStep:0}};o.key="pulltorefresh",o.DEFAULTS={orientation:"down",sensibility:5,refresh:200,lockRefresh:!1,resetRefresh:!0,autoInit:!0,resetSpeed:"100ms",simulateTouch:!0,threshold:20,scroll:e},o.namespace=function(t){return[t,o.key].join(".")},o.support={touch:window.Modernizr&&Modernizr.touch===!0||function(){return!!("ontouchstart"in window||window.DocumentTouch&&e instanceof DocumentTouch)}()},o.events=function(){if(o.support.touch)return{start:o.namespace("touchstart"),move:o.namespace("touchmove"),end:o.namespace("touchend")};var t={start:o.namespace("mousedown"),move:o.namespace("mousemove"),end:o.namespace("mouseup")};return window.navigator.msPointerEnabled&&(t={start:o.namespace("MSPointerDown"),move:o.namespace("MSPointerMove"),end:o.namespace("MSPointerUp")}),window.navigator.pointerEnabled&&(t={start:o.namespace("pointerdown"),move:o.namespace("pointermove"),end:o.namespace("pointerup")}),t}(),o.prototype.construct=function(){var n=this;n.$element.on(o.events.start,n.proxy(n.onTouchStart,n)).on(o.events.move,n.proxy(n.onTouchMove,n)).on(o.events.end,n.proxy(n.onTouchEnd,n)),n.options.simulateTouch&&(n.$element.on(o.namespace("mousedown"),n.proxy(n.onTouchStart,n)),t(e).on(o.namespace("mousemove"),n.$element,n.proxy(n.onTouchMove,n)).on(o.namespace("mouseup"),n.$element,n.proxy(n.onTouchEnd,n)))},o.prototype.destroy=function(){this.remove_transition(this.$element[0].style),this.remove_transform(this.$element[0].style),t(e).off(o.namespace("")),this.$element.off(o.namespace("")),this.$element.removeData("pulltorefresh")},o.prototype.proxy=function(){var e=!!Function.prototype.bind;return e?function(t,e){return t.bind(e)}:t.proxy?t.proxy:function(t,e){var o,n,s;return"string"==typeof e&&(o=t[e],e=t,t=o),"function"!=typeof t?(n=Array.prototype.slice.call(arguments,2),s=function(){return t.apply(e||this,n.concat(slice.call(arguments)))},s.guid=t.guid=t.guid||jQuery.guid++,s):void 0}}(),o.prototype.transform=function(t,e){t.webkitTransform="translate(0, "+e+"px) translateZ(0)",t.msTransform=t.MsTransform=t.MozTransform=t.OTransform=t.transform="translateY("+e+"px)"},o.prototype.transition=function(t,e){t.webkitTransitionDuration=t.MozTransitionDuration=t.msTransitionDuration=t.OTransitionDuration=t.transitionDuration=e},o.prototype.remove_transition=function(t){t.webkitTransitionDuration=t.MozTransitionDuration=t.msTransitionDuration=t.OTransitionDuration=t.transitionDuration=null},o.prototype.remove_transform=function(t){t.webkitTransform=t.msTransform=t.MsTransform=t.MozTransform=t.OTransform=t.transform=null},o.prototype.getAxis=function(t,e){return{x:e?(t.targetTouches||t.originalEvent.targetTouches)[0].pageX:t.pageX||t.clientX,y:e?(t.targetTouches||t.originalEvent.targetTouches)[0].pageY:t.pageY||t.clientY}},o.prototype.onTouchStart=function(t){var e="touchstart"===t.type,n=this.getAxis(t,e);return this.$scroll.scrollTop()>0?!0:void((e||1===t.which)&&(this.flags.touched=!0,this.flags.refreshed=!1,this.flags.isTouch=e,this.positions.startY=n.y,this.positions.startX=n.x,this.positions.currentY=n.y,this.positions.currentX=n.x,this.$element.trigger(o.namespace("start"),[n.y]),this.transition(this.$element[0].style,"0ms")))},o.prototype.onTouchMove=function(e){var n,s,r,i,a="touchmove"===e.type;if(this.flags.touched&&(!this.flags.isTouch||"mousemove"!==e.type)){if(!this.flags.prevented&&e.target&&(e.target.click||e.target.onclick)&&(t(e.target).off("click"),setTimeout(function(){t(e.target).on("click")},0),this.flags.prevented=!0),i=this.getAxis(e,a),this.positions.currentY=i.y,this.positions.currentX=i.x,n=i.y-this.positions.startY,Math.abs(i.x-this.positions.startX)>this.options.threshold)return void this.reset();if(!(0>n&&"down"==this.options.orientation||n>=0&&"up"==this.options.orientation))return(0>n?-1*n:n)>=this.options.refresh&&!this.flags.refreshed&&(this.$element.trigger(o.namespace("refresh"),[i.y]),this.flags.refreshed=!0,this.options.resetRefresh)?void this.reset():void(this.flags.refreshed&&this.options.lockRefresh||(s=parseInt(n/this.options.sensibility,10),this.positions.lastStep!=s&&(r=parseInt(100*n/this.options.refresh,10),this.$element.trigger(o.namespace("move"),r),this.positions.lastStep=s),this.transform(this.$element[0].style,n),e.stopPropagation(),e.preventDefault()))}},o.prototype.reset=function(){this.transition(this.$element[0].style,this.options.resetSpeed),this.transform(this.$element[0].style,0),this.flags.touched=!1,this.flags.isTouch=!1,this.flags.refreshed=!1,this.positions.startY=!1},o.prototype.onTouchEnd=function(t){if(this.flags.touched){this.flags.prevented=!1;var e=this.positions.currentY-this.positions.startY;e>20?(console.log("onTouchEnd detected dragging. Reset."),this.positions.startY=0,this.positions.startX=0,this.reset(),this.$element.trigger(o.namespace("end")),t.stopPropagation(),t.preventDefault()):console.log("onTouchEnd detected no dragging. Allow click.")}};var n=t.fn.pullToRefresh;t.fn.pullToRefresh=function(e){return this.each(function(){var n=t(this),s=n.data(o.key),r=t.extend({},o.DEFAULTS,n.data(),"object"==typeof e&&e);return s||"destroy"!=e?(s||(n.data(o.key,s=new o(this,r)),r.autoInit&&s.construct()),void("string"==typeof e&&s[e].apply(s))):o.destroy()})},t.fn.pullToRefresh.Constructor=o,t.fn.pullToRefresh.noConflict=function(){return t.fn.pullToRefresh=n,this}}(window.jQuery||window.Zepto,document);