diff --git a/dist/mde-swipe-to-refresh.js b/dist/mde-swipe-to-refresh.js index 4abca39..422d1b7 100644 --- a/dist/mde-swipe-to-refresh.js +++ b/dist/mde-swipe-to-refresh.js @@ -4,8 +4,6 @@ * https://github.com/alirezamirian/angular-material-swipe-to-refresh */ - - (function(angular){ "use strict"; angular.module("mde.swipeToRefresh", []) @@ -42,6 +40,13 @@ link: linkFn }; + function getEvent(event) { + if (angular.isDefined(event.originalEvent)) { + return event.originalEvent; + } + return event; + } + function linkFn(scope, elem, attrs, mdeSwipeToRefreshScrollHost){ elem.bind("touchstart", touchStart); var scrollHost, startY; @@ -75,7 +80,7 @@ if(scope.state != State.None){ return; } - startY = event.touches[0].pageY; + startY = getEvent(event).touches[0].pageY; elem.one("touchend", touchEnd); elem.bind("touchmove", touchMove); @@ -90,10 +95,10 @@ if(scrollHost[0].scrollTop > 0){ return; } - var movement = event.touches[0].pageY - startY; + var movement = getEvent(event).touches[0].pageY - startY; if(movement > 0 && scope.state != State.Pulling){ - startY = event.touches[0].pageY; + startY = getEvent(event).touches[0].pageY; movement = 0; scope.state = State.Pulling; } @@ -142,8 +147,7 @@ } } function calculateMovement(movement, activationThreshold) { - - return 2 * activationThreshold * log10((movement + activationThreshold) / activationThreshold); + return 2 * activationThreshold * log10((movement + activationThreshold) / activationThreshold); } function log10(x){ return Math.log(x)/Math.LN10; @@ -151,7 +155,6 @@ } })(angular); - (function(angular){ "use strict"; angular.module('mde.swipeToRefresh') @@ -175,8 +178,6 @@ })(angular); - - // source: https://developer.mozilla.org/en-US/docs/Web/API/Element/matches if (!Element.prototype.matches) { Element.prototype.matches = diff --git a/dist/mde-swipe-to-refresh.min.js b/dist/mde-swipe-to-refresh.min.js index 027757e..05c36a0 100644 --- a/dist/mde-swipe-to-refresh.min.js +++ b/dist/mde-swipe-to-refresh.min.js @@ -4,4 +4,4 @@ * https://github.com/alirezamirian/angular-material-swipe-to-refresh */ -!function(e){"use strict";e.module("mde.swipeToRefresh",[]).constant("mdeSwipeToRefreshConfig",{threshold:80})}(angular),function(e){"use strict";function t(t,o,s){function i(i,l,m,a){function c(e){i.state==r.None&&(h=e.touches[0].pageY,l.one("touchend",u),l.bind("touchmove",d),0==p[0].scrollTop&&(i.progress=0,i.movement=0,i.$digest()))}function d(e){if(!(p[0].scrollTop>0)){var t=e.touches[0].pageY-h;t>0&&i.state!=r.Pulling&&(h=e.touches[0].pageY,t=0,i.state=r.Pulling),i.state==r.Pulling&&e.preventDefault(),t>0?(i.movement=Math.min(n(t,i.mdeThreshold)),i.progress=Math.min(i.movement/i.mdeThreshold,1),i.$digest()):i.movement>0&&(i.movement=0,i.progress=0,i.$digest())}}function u(n){l.unbind("touchmove",d),i.$apply(function(){1==i.progress?(i.state=r.Updating,i.movement=i.mdeThreshold,t.when((i.mdeOnRefresh||e.noop)())["finally"](function(){i.state=r.None,i.movement=0,i.progress=0})):(i.movement>0&&((i.mdeOnCancel||e.noop)(),i.movement=0,i.progress=0),o(function(){i.state=r.None},100))})}l.bind("touchstart",c);var p,h;if(a)p=a.getElement();else if(i.mdeScrollHostSelector){for(var g=l.parent();g[0]!=document.body;)if(g=g.parent(),g[0].matches(i.mdeScrollHostSelector)){p=g;break}p=p||g}else p=e.element(document.body);i.mdeThreshold=i.mdeThreshold||s.threshold,i.State=r,i.progress=0,i.state=r.None}return{restrict:"A",require:"?^mdeSwipeToRefreshScrollHost",transclude:!0,scope:{mdeOnRefresh:"&?",mdeOnCancel:"&?",mdeScrollHostSelector:"@?",mdeThreshold:"=?"},templateUrl:"swipe-to-refresh/swipe-to-refresh.html",link:i}}function n(e,t){return 2*t*o((e+t)/t)}function o(e){return Math.log(e)/Math.LN10}t.$inject=["$q","$timeout","mdeSwipeToRefreshConfig"],e.module("mde.swipeToRefresh").directive("mdeSwipeToRefresh",t);var r={None:"None",Updating:"Updating",Pulling:"Pulling"}}(angular),function(e){"use strict";function t(){function e(e){function t(){return e}this.getElement=t}return e.$inject=["$element"],{restrict:"A",controller:e}}e.module("mde.swipeToRefresh").directive("mdeSwipeToRefreshScrollHost",t)}(angular),Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),n=t.length;--n>=0&&t.item(n)!==this;);return n>-1}),function(e){try{e=angular.module("mde.swipeToRefresh")}catch(t){e=angular.module("mde.swipeToRefresh",[])}e.run(["$templateCache",function(e){e.put("swipe-to-refresh/swipe-to-refresh.html",'\n \n \n \n \n \n \n \n \n\n
\n')}])}(); \ No newline at end of file +!function(e){"use strict";e.module("mde.swipeToRefresh",[]).constant("mdeSwipeToRefreshConfig",{threshold:80})}(angular),function(e){"use strict";function t(t,o,s){function i(t){return e.isDefined(t.originalEvent)?t.originalEvent:t}function l(l,a,m,c){function d(e){l.state==r.None&&(g=i(e).touches[0].pageY,a.one("touchend",p),a.bind("touchmove",u),0==h[0].scrollTop&&(l.progress=0,l.movement=0,l.$digest()))}function u(e){if(!(h[0].scrollTop>0)){var t=i(e).touches[0].pageY-g;t>0&&l.state!=r.Pulling&&(g=i(e).touches[0].pageY,t=0,l.state=r.Pulling),l.state==r.Pulling&&e.preventDefault(),t>0?(l.movement=Math.min(n(t,l.mdeThreshold)),l.progress=Math.min(l.movement/l.mdeThreshold,1),l.$digest()):l.movement>0&&(l.movement=0,l.progress=0,l.$digest())}}function p(n){a.unbind("touchmove",u),l.$apply(function(){1==l.progress?(l.state=r.Updating,l.movement=l.mdeThreshold,t.when((l.mdeOnRefresh||e.noop)())["finally"](function(){l.state=r.None,l.movement=0,l.progress=0})):(l.movement>0&&((l.mdeOnCancel||e.noop)(),l.movement=0,l.progress=0),o(function(){l.state=r.None},100))})}a.bind("touchstart",d);var h,g;if(c)h=c.getElement();else if(l.mdeScrollHostSelector){for(var f=a.parent();f[0]!=document.body;)if(f=f.parent(),f[0].matches(l.mdeScrollHostSelector)){h=f;break}h=h||f}else h=e.element(document.body);l.mdeThreshold=l.mdeThreshold||s.threshold,l.State=r,l.progress=0,l.state=r.None}return{restrict:"A",require:"?^mdeSwipeToRefreshScrollHost",transclude:!0,scope:{mdeOnRefresh:"&?",mdeOnCancel:"&?",mdeScrollHostSelector:"@?",mdeThreshold:"=?"},templateUrl:"swipe-to-refresh/swipe-to-refresh.html",link:l}}function n(e,t){return 2*t*o((e+t)/t)}function o(e){return Math.log(e)/Math.LN10}t.$inject=["$q","$timeout","mdeSwipeToRefreshConfig"],e.module("mde.swipeToRefresh").directive("mdeSwipeToRefresh",t);var r={None:"None",Updating:"Updating",Pulling:"Pulling"}}(angular),function(e){"use strict";function t(){function e(e){function t(){return e}this.getElement=t}return e.$inject=["$element"],{restrict:"A",controller:e}}e.module("mde.swipeToRefresh").directive("mdeSwipeToRefreshScrollHost",t)}(angular),Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),n=t.length;--n>=0&&t.item(n)!==this;);return n>-1}),function(e){try{e=angular.module("mde.swipeToRefresh")}catch(t){e=angular.module("mde.swipeToRefresh",[])}e.run(["$templateCache",function(e){e.put("swipe-to-refresh/swipe-to-refresh.html",'\n \n \n \n \n \n \n \n \n\n
\n')}])}(); \ No newline at end of file diff --git a/src/swipe-to-refresh/swipe-to-refresh.directive.js b/src/swipe-to-refresh/swipe-to-refresh.directive.js index 46251c4..86b32ef 100644 --- a/src/swipe-to-refresh/swipe-to-refresh.directive.js +++ b/src/swipe-to-refresh/swipe-to-refresh.directive.js @@ -25,6 +25,13 @@ link: linkFn }; + function getEvent(event) { + if (angular.isDefined(event.originalEvent)) { + return event.originalEvent; + } + return event; + } + function linkFn(scope, elem, attrs, mdeSwipeToRefreshScrollHost){ elem.bind("touchstart", touchStart); var scrollHost, startY; @@ -58,7 +65,7 @@ if(scope.state != State.None){ return; } - startY = event.originalEvent.touches[0].pageY; + startY = getEvent(event).touches[0].pageY; elem.one("touchend", touchEnd); elem.bind("touchmove", touchMove); @@ -73,10 +80,10 @@ if(scrollHost[0].scrollTop > 0){ return; } - var movement = event.originalEvent.touches[0].pageY - startY; + var movement = getEvent(event).touches[0].pageY - startY; if(movement > 0 && scope.state != State.Pulling){ - startY = event.originalEvent.touches[0].pageY; + startY = getEvent(event).touches[0].pageY; movement = 0; scope.state = State.Pulling; }