From d9ddee26f11571dbe0189d3e2204467d0707062f Mon Sep 17 00:00:00 2001 From: Oleg Korsunsky Date: Fri, 6 Dec 2013 21:11:15 +0400 Subject: [PATCH] event burrito -> subgit --- .gitignore | 3 +- .gitmodules | 3 + Gruntfile.js | 30 +++-- peppermint.js | 11 +- peppermint.min.js | 10 +- src/burrito | 1 + src/eventburrito.js | 191 ---------------------------- test/{bonus_tests.htm => bonus.htm} | 2 +- test/index.htm | 2 +- 9 files changed, 44 insertions(+), 209 deletions(-) create mode 100644 .gitmodules create mode 160000 src/burrito delete mode 100644 src/eventburrito.js rename test/{bonus_tests.htm => bonus.htm} (99%) diff --git a/.gitignore b/.gitignore index b512c09..241a796 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +temp \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b1c198c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/burrito"] + path = src/burrito + url = https://github.com/wilddeer/Event-Burrito.git diff --git a/Gruntfile.js b/Gruntfile.js index 4be02b3..fc307e3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,33 +7,43 @@ module.exports = function(grunt) { banner: '/*!\n * Peppermint touch slider\n * v. <%= pkg.version %> | <%= pkg.homepage %>\n * Copyright <%= pkg.author.name %> | <%= pkg.author.url %>\n *\n * MIT License\n */\n', uglify: { options: { - banner: '<%= banner %>', + preserveComments: 'some', mangle: { - except: ['Peppermint', '$', 'jQuery'] + except: ['Peppermint', '$', 'jQuery', 'eventBurrito'] } }, - dist: { + peppermint: { files: { - 'peppermint.min.js': ['src/peppermint.js','src/eventburrito.js'] + 'temp/peppermint.min.js': ['src/peppermint.js'] } }, - pure: { + burrito: { files: { - 'pure/peppermint.pure.min.js': ['src/peppermint.js'] + 'temp/eventburrito.min.js': ['src/burrito/eventburrito.js'] } } }, + concat: { options: { - banner: '<%= banner %>' + banner: '<%= banner %>', + separator: '\n' }, - dist: { - src: ['src/peppermint.js','src/eventburrito.js'], + full: { + src: ['src/peppermint.js','src/burrito/eventburrito.js'], dest: 'peppermint.js', }, - pure: { + min: { + src: ['temp/peppermint.min.js','temp/eventburrito.min.js'], + dest: 'peppermint.min.js', + }, + pureFull: { src: ['src/peppermint.js'], dest: 'pure/peppermint.pure.js' + }, + pureMin: { + src: ['temp/peppermint.min.js'], + dest: 'pure/peppermint.pure.min.js' } }, diff --git a/peppermint.js b/peppermint.js index 0d62a80..788138c 100644 --- a/peppermint.js +++ b/peppermint.js @@ -475,6 +475,13 @@ if (window.jQuery) { }; })(window.jQuery); } +/*! + * Event Burrito is a touch / mouse / pointer event unifier + * https://github.com/wilddeer/Event-Burrito + * Copyright Oleg Korsunsky | http://wd.dizaina.net/ + * + * MIT License + */ function eventBurrito(_this, options) { var o = options || {}, @@ -604,8 +611,6 @@ function eventBurrito(_this, options) { getDiff(event); - //console.log(speed.x); - if (Math.abs(diff.x) > o.clickTolerance || Math.abs(diff.y) > o.clickTolerance) clicksAllowed = false; //if there was a move -- deny all the clicks before the next touchstart //check whether the user is trying to scroll vertically @@ -622,8 +627,6 @@ function eventBurrito(_this, options) { function tEnd(event) { eventType && getDiff(event); - //console.log(speed.x); - //IE likes to focus the link after touchend. //Since we dont' want to disable the outline completely for accessibility reasons, //we just defocus it after touch and disable the outline for `:active` links in css. diff --git a/peppermint.min.js b/peppermint.min.js index 900faff..98dcaa3 100644 --- a/peppermint.min.js +++ b/peppermint.min.js @@ -5,4 +5,12 @@ * * MIT License */ -function Peppermint(a,b){function c(a){var b=["Webkit","Moz","O","ms"],c=document.createElement("div");if(void 0!==c.style[a])return!0;a=a.charAt(0).toUpperCase()+a.slice(1);for(var d in b)if(void 0!==c.style[b[d]+a])return!0;return!1}function d(a,b){-1===(" "+a.className+" ").indexOf(" "+b+" ")&&(a.className=(a.className+" "+b).replace(/^\s+|\s+$/g,""))}function e(a,b){a.className=(" "+a.className+" ").replace(" "+b+" "," ").replace(/^\s+|\s+$/g,"")}function f(a,b){if(0>a?a=0:a>u-1&&(a=u-1),a!==v){for(var c=D.dots.length-1;c>=0;c--)e(D.dots[c],G.active);d(D.dots[a],G.active),v=a}return g(-a*D.width,void 0===b?C.speed:b),n(),C.onSlideChange&&C.onSlideChange(a),a}function g(a,b){var c=b?b+"ms":"";y.style.webkitTransitionDuration=y.style.MozTransitionDuration=y.style.msTransitionDuration=y.style.OTransitionDuration=y.style.transitionDuration=c,i(a)}function h(a,b){if(B&&clearInterval(B),!b)return i(a),void 0;var c=+new Date,d=D.left;B=setInterval(function(){function e(a,b){return(b-a)*j+a}var f,g,h=+new Date-c,j=h/b,k=[0,.7,1,1];return j>=1?(i(a),clearInterval(B),void 0):(f=a-d,g=e(e(e(k[0],k[1]),e(k[1],k[2])),e(e(k[1],k[2]),e(k[2],k[3]))),i(Math.floor(g*f+d)),void 0)},15)}function i(a){y.style.webkitTransform="translate("+a+"px,0) translateZ(0)",y.style.msTransform=y.style.MozTransform=y.style.OTransform=y.style.transform="translateX("+a+"px)",D.left=a}function j(a){y.style.left=a+"px",D.left=a}function k(){var a=v+1;return a>u-1&&(a=0),f(a)}function l(){var a=v-1;return 0>a&&(a=u-1),f(a)}function m(){A=!0,n()}function n(){A&&(z&&clearTimeout(z),z=setTimeout(function(){k()},C.slideshowInterval))}function o(){z&&clearTimeout(z)}function p(){A=!1,z&&clearTimeout(z)}function q(){D.width=a.offsetWidth,y.style.width=D.width*u+"px";for(var b=0;u>b;b++)D.slides[b].style.width=D.width+"px";g(-v*D.width)}function r(a,b,c,d){b&&(a.addEventListener?a.addEventListener(b,c,!!d):a.attachEvent("on"+b,c))}function s(){eventBurrito(y,{mouse:C.mouseDrag,start:function(){d(a,G.drag)},move:function(a,b,c){o(),c.x=c.x/(!v&&c.x>0||v==u-1&&c.x<0?Math.abs(c.x)/D.width*2+1:1),g(c.x-D.width*v)},end:function(b,c,d){if(d.x){var g=Math.abs(d.x)/D.width,h=Math.floor(g)+(g-Math.floor(g)>.25?1:0),i=d.time(h?-D.width/9:20);h+=i?1:0,d.x<0?f(v+h,C.touchSpeed):f(v-h,C.touchSpeed),C.stopSlideshowAfterInteraction&&p()}e(a,G.drag)}})}function t(){(!H.transforms||window.opera)&&(i=j),(!H.transitions||window.opera)&&(g=h),y=F||document.createElement("div"),d(y,G.slides);for(var b=0,c=C.slidesContainer.children.length;c>b;b++){var k=C.slidesContainer.children[b],l=document.createElement("li");D.slides.push(k),l.setAttribute("tabindex","0"),l.setAttribute("role","button"),l.innerHTML="",r(l,"click",function(a,b){return function(c){0!==c.clientX&&0!==c.clientY&&0!==c.offsetX&&0!==c.offsetY&&b.blur(),f(a),C.stopSlideshowAfterInteraction&&p()}}(b,l)),r(l,"keyup",function(a){return function(b){13==b.keyCode&&(f(a),C.stopSlideshowAfterInteraction&&p())}}(b)),r(k,"focus",k.onfocusin=function(b){return function(){a.scrollLeft=0,setTimeout(function(){a.scrollLeft=0},0),f(b)}}(b),!0),D.dots.push(l)}u=D.slides.length,w=100/u,d(a,G.active),e(a,G.inactive),C.mouseDrag&&d(a,G.mouse),D.width=a.offsetWidth,y.style.width=D.width*u+"px";for(var b=0;u>b;b++)D.slides[b].style.width=D.width+"px",y.appendChild(D.slides[b]);if(F||a.appendChild(y),C.dots){x=document.createElement("ul"),d(x,G.dots);for(var b=0,c=D.dots.length;c>b;b++)x.appendChild(D.dots[b]);C.dotsFirst?a.insertBefore(x,a.firstChild):a.appendChild(x)}r(window,"resize",q),r(window,"orientationchange",q),setTimeout(function(){f(C.startSlide,0)},0),C.slideshow&&m(),s(),setTimeout(function(){C.onSetup&&C.onSetup(u)},0)}var u,v,w,x,y,z,A,B,C=b||{},D={slides:[],dots:[],left:0},E=200,F=C.slidesContainer||!1;C.speed=C.speed||300,C.touchSpeed=C.touchSpeed||300,C.slideshow=C.slideshow||!1,C.slideshowInterval=C.slideshowInterval||4e3,C.stopSlideshowAfterInteraction=C.stopSlideshowAfterInteraction||!1,C.startSlide=C.startSlide||0,C.dots=C.dots||!1,C.dotsFirst=C.dotsFirst||!1,C.mouseDrag=C.mouseDrag||!1,C.cssPrefix=C.cssPrefix||"",C.slidesContainer=C.slidesContainer||a;var G={inactive:C.cssPrefix+"inactive",active:C.cssPrefix+"active",mouse:C.cssPrefix+"mouse",drag:C.cssPrefix+"drag",slides:C.cssPrefix+"slides",dots:C.cssPrefix+"dots"},H={transforms:c("transform"),transitions:c("transition")};return t(),{slideTo:function(a){return f(parseInt(a,10))},next:function(){return k()},prev:function(){return l()},start:function(){m()},stop:function(){p()},pause:function(){o()},getCurrentPos:function(){return v},getSlidesNumber:function(){return u},recalcWidth:function(){q()}}}function eventBurrito(a,b){function c(a,b,c,d){b&&(a.addEventListener?a.addEventListener(b,c,!!d):a.attachEvent("on"+b,c))}function d(a,b,c,d){b&&(a.removeEventListener?a.removeEventListener(b,c,!!d):a.detachEvent("on"+b,c))}function e(a){if(p={x:(m?a.clientX:a.touches[0].clientX)-o.x,y:(m?a.clientY:a.touches[0].clientY)-o.y,time:Number(new Date)-o.time},p.time-r[r.length-1].time){for(var b=0;b80;b++);q={x:(p.x-r[b].x)/(p.time-r[b].time),y:(p.y-r[b].y)/(p.time-r[b].time)},r.length>=5&&r.shift(),r.push({x:p.x,y:p.y,time:p.time})}}function f(a,b){s=!0,m=b,v[m](a)||(c(document,u[m][1],g),c(document,u[m][2],h),c(document,u[m][3],h),m&&(a.preventDefault?a.preventDefault():a.returnValue=!1),o={x:m?a.clientX:a.touches[0].clientX,y:m?a.clientY:a.touches[0].clientY,time:Number(new Date)},l=void 0,p={x:0,y:0,time:0},q={x:0,y:0},r=[{x:0,y:0,time:0}],j.start(a,o))}function g(a){!j.preventScroll&&l||v[m](a)||(e(a),(Math.abs(p.x)>j.clickTolerance||Math.abs(p.y)>j.clickTolerance)&&(s=!1),void 0===l&&3!==m&&(l=Math.abs(p.x)1||a.scale&&1!==a.scale},function(a){return!a.isPrimary||1!==a.buttons||!j.mouse&&"touch"!==a.pointerType&&"pen"!==a.pointerType},function(a){return!a.isPrimary||a.buttons&&1!==a.buttons||!j.mouse&&a.pointerType!==a.MSPOINTER_TYPE_TOUCH&&a.pointerType!==a.MSPOINTER_TYPE_PEN},function(a){return a.buttons&&1!==a.buttons}];return c(a,u[t][0],function(a){f(a,t)}),c(a,"dragstart",function(){event.preventDefault?event.preventDefault():event.returnValue=!1}),j.mouse&&!t&&c(a,u[3][0],function(a){f(a,3)}),c(a,"click",function(a){s?j.click(a):a.preventDefault?a.preventDefault():a.returnValue=!1}),{getClicksAllowed:function(){return s}}}window.jQuery&&!function($){$.fn.Peppermint=function(a){this.each(function(){$(this).data("Peppermint",Peppermint($(this)[0],a))})}}(window.jQuery); \ No newline at end of file +function Peppermint(a,b){function c(a){var b=["Webkit","Moz","O","ms"],c=document.createElement("div");if(void 0!==c.style[a])return!0;a=a.charAt(0).toUpperCase()+a.slice(1);for(var d in b)if(void 0!==c.style[b[d]+a])return!0;return!1}function d(a,b){-1===(" "+a.className+" ").indexOf(" "+b+" ")&&(a.className=(a.className+" "+b).replace(/^\s+|\s+$/g,""))}function e(a,b){a.className=(" "+a.className+" ").replace(" "+b+" "," ").replace(/^\s+|\s+$/g,"")}function f(a,b){if(0>a?a=0:a>u-1&&(a=u-1),a!==v){for(var c=D.dots.length-1;c>=0;c--)e(D.dots[c],G.active);d(D.dots[a],G.active),v=a}return g(-a*D.width,void 0===b?C.speed:b),n(),C.onSlideChange&&C.onSlideChange(a),a}function g(a,b){var c=b?b+"ms":"";y.style.webkitTransitionDuration=y.style.MozTransitionDuration=y.style.msTransitionDuration=y.style.OTransitionDuration=y.style.transitionDuration=c,i(a)}function h(a,b){if(B&&clearInterval(B),!b)return i(a),void 0;var c=+new Date,d=D.left;B=setInterval(function(){function e(a,b){return(b-a)*j+a}var f,g,h=+new Date-c,j=h/b,k=[0,.7,1,1];return j>=1?(i(a),clearInterval(B),void 0):(f=a-d,g=e(e(e(k[0],k[1]),e(k[1],k[2])),e(e(k[1],k[2]),e(k[2],k[3]))),i(Math.floor(g*f+d)),void 0)},15)}function i(a){y.style.webkitTransform="translate("+a+"px,0) translateZ(0)",y.style.msTransform=y.style.MozTransform=y.style.OTransform=y.style.transform="translateX("+a+"px)",D.left=a}function j(a){y.style.left=a+"px",D.left=a}function k(){var a=v+1;return a>u-1&&(a=0),f(a)}function l(){var a=v-1;return 0>a&&(a=u-1),f(a)}function m(){A=!0,n()}function n(){A&&(z&&clearTimeout(z),z=setTimeout(function(){k()},C.slideshowInterval))}function o(){z&&clearTimeout(z)}function p(){A=!1,z&&clearTimeout(z)}function q(){D.width=a.offsetWidth,y.style.width=D.width*u+"px";for(var b=0;u>b;b++)D.slides[b].style.width=D.width+"px";g(-v*D.width)}function r(a,b,c,d){b&&(a.addEventListener?a.addEventListener(b,c,!!d):a.attachEvent("on"+b,c))}function s(){eventBurrito(y,{mouse:C.mouseDrag,start:function(){d(a,G.drag)},move:function(a,b,c){o(),c.x=c.x/(!v&&c.x>0||v==u-1&&c.x<0?Math.abs(c.x)/D.width*2+1:1),g(c.x-D.width*v)},end:function(b,c,d){if(d.x){var g=Math.abs(d.x)/D.width,h=Math.floor(g)+(g-Math.floor(g)>.25?1:0),i=d.time(h?-D.width/9:20);h+=i?1:0,d.x<0?f(v+h,C.touchSpeed):f(v-h,C.touchSpeed),C.stopSlideshowAfterInteraction&&p()}e(a,G.drag)}})}function t(){(!H.transforms||window.opera)&&(i=j),(!H.transitions||window.opera)&&(g=h),y=F||document.createElement("div"),d(y,G.slides);for(var b=0,c=C.slidesContainer.children.length;c>b;b++){var k=C.slidesContainer.children[b],l=document.createElement("li");D.slides.push(k),l.setAttribute("tabindex","0"),l.setAttribute("role","button"),l.innerHTML="",r(l,"click",function(a,b){return function(c){0!==c.clientX&&0!==c.clientY&&0!==c.offsetX&&0!==c.offsetY&&b.blur(),f(a),C.stopSlideshowAfterInteraction&&p()}}(b,l)),r(l,"keyup",function(a){return function(b){13==b.keyCode&&(f(a),C.stopSlideshowAfterInteraction&&p())}}(b)),r(k,"focus",k.onfocusin=function(b){return function(){a.scrollLeft=0,setTimeout(function(){a.scrollLeft=0},0),f(b)}}(b),!0),D.dots.push(l)}u=D.slides.length,w=100/u,d(a,G.active),e(a,G.inactive),C.mouseDrag&&d(a,G.mouse),D.width=a.offsetWidth,y.style.width=D.width*u+"px";for(var b=0;u>b;b++)D.slides[b].style.width=D.width+"px",y.appendChild(D.slides[b]);if(F||a.appendChild(y),C.dots){x=document.createElement("ul"),d(x,G.dots);for(var b=0,c=D.dots.length;c>b;b++)x.appendChild(D.dots[b]);C.dotsFirst?a.insertBefore(x,a.firstChild):a.appendChild(x)}r(window,"resize",q),r(window,"orientationchange",q),setTimeout(function(){f(C.startSlide,0)},0),C.slideshow&&m(),s(),setTimeout(function(){C.onSetup&&C.onSetup(u)},0)}var u,v,w,x,y,z,A,B,C=b||{},D={slides:[],dots:[],left:0},E=200,F=C.slidesContainer||!1;C.speed=C.speed||300,C.touchSpeed=C.touchSpeed||300,C.slideshow=C.slideshow||!1,C.slideshowInterval=C.slideshowInterval||4e3,C.stopSlideshowAfterInteraction=C.stopSlideshowAfterInteraction||!1,C.startSlide=C.startSlide||0,C.dots=C.dots||!1,C.dotsFirst=C.dotsFirst||!1,C.mouseDrag=C.mouseDrag||!1,C.cssPrefix=C.cssPrefix||"",C.slidesContainer=C.slidesContainer||a;var G={inactive:C.cssPrefix+"inactive",active:C.cssPrefix+"active",mouse:C.cssPrefix+"mouse",drag:C.cssPrefix+"drag",slides:C.cssPrefix+"slides",dots:C.cssPrefix+"dots"},H={transforms:c("transform"),transitions:c("transition")};return t(),{slideTo:function(a){return f(parseInt(a,10))},next:function(){return k()},prev:function(){return l()},start:function(){m()},stop:function(){p()},pause:function(){o()},getCurrentPos:function(){return v},getSlidesNumber:function(){return u},recalcWidth:function(){q()}}}window.jQuery&&!function($){$.fn.Peppermint=function(a){this.each(function(){$(this).data("Peppermint",Peppermint($(this)[0],a))})}}(window.jQuery); +/*! + * Event Burrito is a touch / mouse / pointer event unifier + * https://github.com/wilddeer/Event-Burrito + * Copyright Oleg Korsunsky | http://wd.dizaina.net/ + * + * MIT License + */ +function eventBurrito(a,b){function c(a,b,c,d){b&&(a.addEventListener?a.addEventListener(b,c,!!d):a.attachEvent("on"+b,c))}function d(a,b,c,d){b&&(a.removeEventListener?a.removeEventListener(b,c,!!d):a.detachEvent("on"+b,c))}function e(a){if(p={x:(m?a.clientX:a.touches[0].clientX)-o.x,y:(m?a.clientY:a.touches[0].clientY)-o.y,time:Number(new Date)-o.time},p.time-r[r.length-1].time){for(var b=0;b80;b++);q={x:(p.x-r[b].x)/(p.time-r[b].time),y:(p.y-r[b].y)/(p.time-r[b].time)},r.length>=5&&r.shift(),r.push({x:p.x,y:p.y,time:p.time})}}function f(a,b){s=!0,m=b,v[m](a)||(c(document,u[m][1],g),c(document,u[m][2],h),c(document,u[m][3],h),m&&(a.preventDefault?a.preventDefault():a.returnValue=!1),o={x:m?a.clientX:a.touches[0].clientX,y:m?a.clientY:a.touches[0].clientY,time:Number(new Date)},l=void 0,p={x:0,y:0,time:0},q={x:0,y:0},r=[{x:0,y:0,time:0}],j.start(a,o))}function g(a){!j.preventScroll&&l||v[m](a)||(e(a),(Math.abs(p.x)>j.clickTolerance||Math.abs(p.y)>j.clickTolerance)&&(s=!1),void 0===l&&3!==m&&(l=Math.abs(p.x)1||a.scale&&1!==a.scale},function(a){return!a.isPrimary||1!==a.buttons||!j.mouse&&"touch"!==a.pointerType&&"pen"!==a.pointerType},function(a){return!a.isPrimary||a.buttons&&1!==a.buttons||!j.mouse&&a.pointerType!==a.MSPOINTER_TYPE_TOUCH&&a.pointerType!==a.MSPOINTER_TYPE_PEN},function(a){return a.buttons&&1!==a.buttons}];return c(a,u[t][0],function(a){f(a,t)}),c(a,"dragstart",function(){event.preventDefault?event.preventDefault():event.returnValue=!1}),j.mouse&&!t&&c(a,u[3][0],function(a){f(a,3)}),c(a,"click",function(a){s?j.click(a):a.preventDefault?a.preventDefault():a.returnValue=!1}),{getClicksAllowed:function(){return s}}} \ No newline at end of file diff --git a/src/burrito b/src/burrito new file mode 160000 index 0000000..7178a6a --- /dev/null +++ b/src/burrito @@ -0,0 +1 @@ +Subproject commit 7178a6a513818a9afd863aff364809d182817f42 diff --git a/src/eventburrito.js b/src/eventburrito.js deleted file mode 100644 index 2dd06b7..0000000 --- a/src/eventburrito.js +++ /dev/null @@ -1,191 +0,0 @@ -function eventBurrito(_this, options) { - - var o = options || {}, - noop = function() {}; - - o.clickTolerance = o.clickTolerance || 0; - o.preventScroll = o.preventScroll || false; - o.mouse = o.mouse || true; - o.start = o.start || noop; - o.move = o.move || noop; - o.end = o.end || noop; - o.click = o.click || noop; - - var support = { - pointerEvents: !!window.navigator.pointerEnabled, - msPointerEvents: !!window.navigator.msPointerEnabled - }, - start = {}, - diff = {}, - speed = {}, - stack = [], - isScrolling, - eventType, - clicksAllowed = true, //flag allowing default click actions (e.g. links) - eventModel = (support.pointerEvents? 1 : (support.msPointerEvents? 2 : 0)), - events = [ - ['touchstart', 'touchmove', 'touchend', 'touchcancel'], //touch events - ['pointerdown', 'pointermove', 'pointerup', 'pointercancel'], //pointer events - ['MSPointerDown', 'MSPointerMove', 'MSPointerUp', 'MSPointerCancel'], //IE10 pointer events - ['mousedown', 'mousemove', 'mouseup', false] //mouse events - ], - //some checks for different event types - checks = [ - //touch events - function(e) { - //if it's multitouch or pinch move -- skip the event - return (e.touches && e.touches.length > 1) || (e.scale && e.scale !== 1); - }, - //pointer events - function(e) { - //if event is not primary (other pointers during multitouch), - //if left mouse button is not pressed, - //if mouse drag is disabled and event is not touch -- skip it! - return !e.isPrimary || e.buttons !== 1 || (!o.mouse && e.pointerType !== 'touch' && e.pointerType !== 'pen'); - }, - //IE10 pointer events - function(e) { - //same checks as in pointer events - return !e.isPrimary || (e.buttons && e.buttons !== 1) || (!o.mouse && e.pointerType !== e.MSPOINTER_TYPE_TOUCH && e.pointerType !== e.MSPOINTER_TYPE_PEN); - }, - //mouse events - function(e) { - //if left mouse button is not pressed -- skip the event - //in IE7-8 `buttons` is not defined, in IE9 LMB is 0 - return (e.buttons && e.buttons !== 1); - } - ]; - - function addEvent(el, event, func, bool) { - if (!event) return; - - el.addEventListener? el.addEventListener(event, func, !!bool): el.attachEvent('on'+event, func); - } - - function removeEvent(el, event, func, bool) { - if (!event) return; - - el.removeEventListener? el.removeEventListener(event, func, !!bool): el.detachEvent('on'+event, func); - } - - function getDiff(event) { - diff = { - x: (eventType? event.clientX : event.touches[0].clientX) - start.x, - y: (eventType? event.clientY : event.touches[0].clientY) - start.y, - - time: Number(new Date) - start.time - }; - - if (diff.time - stack[stack.length - 1].time) { - for (var i = 0; i < stack.length - 1 && diff.time - stack[i].time > 80; i++); - - speed = { - x: (diff.x - stack[i].x) / (diff.time - stack[i].time), - y: (diff.y - stack[i].y) / (diff.time - stack[i].time) - }; - - if (stack.length >= 5) stack.shift(); - stack.push({x: diff.x, y: diff.y, time: diff.time}); - } - } - - function tStart(event, eType) { - clicksAllowed = true; - eventType = eType; //leak event type - - if (checks[eventType](event)) return; - - //add event listeners to the document, so that the slider - //will continue to recieve events wherever the pointer is - addEvent(document, events[eventType][1], tMove); - addEvent(document, events[eventType][2], tEnd); - addEvent(document, events[eventType][3], tEnd); - - //fixes WebKit's cursor while dragging - if (eventType) event.preventDefault? event.preventDefault() : event.returnValue = false; - - //remember starting time and position - start = { - x: eventType? event.clientX : event.touches[0].clientX, - y: eventType? event.clientY : event.touches[0].clientY, - - time: Number(new Date) - }; - - //reset - isScrolling = undefined; - diff = {x:0, y:0, time: 0}; - speed = {x:0, y:0}; - stack = [{x:0, y:0, time: 0}]; - - o.start(event, start); - } - - function tMove(event) { - //if user is trying to scroll vertically -- do nothing - if ((!o.preventScroll && isScrolling) || checks[eventType](event)) return; - - getDiff(event); - - //console.log(speed.x); - - if (Math.abs(diff.x) > o.clickTolerance || Math.abs(diff.y) > o.clickTolerance) clicksAllowed = false; //if there was a move -- deny all the clicks before the next touchstart - - //check whether the user is trying to scroll vertically - if (isScrolling === undefined && eventType !== 3) { - //assign and check `isScrolling` at the same time - if (isScrolling = (Math.abs(diff.x) < Math.abs(diff.y)) && !o.preventScroll) return; - } - - event.preventDefault? event.preventDefault() : event.returnValue = false; //Prevent scrolling - - o.move(event, start, diff, speed); - } - - function tEnd(event) { - eventType && getDiff(event); - - //console.log(speed.x); - - //IE likes to focus the link after touchend. - //Since we dont' want to disable the outline completely for accessibility reasons, - //we just defocus it after touch and disable the outline for `:active` links in css. - //This way the outline will remain visible when tabbing through the links. - event.target && event.target.blur && event.target.blur(); - - //remove the event listeners - detachEvents(); - - o.end(event, start, diff, speed); - } - - //removes the event listeners from the document - function detachEvents() { - removeEvent(document, events[eventType][1], tMove); - removeEvent(document, events[eventType][2], tEnd); - removeEvent(document, events[eventType][3], tEnd); - } - - //bind the touchstart - addEvent(_this, events[eventModel][0], function(e) {tStart(e, eventModel);}); - //prevent stuff from dragging when using mouse - addEvent(_this, 'dragstart', function(e){ - event.preventDefault? event.preventDefault() : event.returnValue = false; - }); - - //bind mousedown if necessary - if (o.mouse && !eventModel) { - addEvent(_this, events[3][0], function(e) {tStart(e, 3);}); - } - - //No clicking during touch - addEvent(_this, 'click', function(event) { - clicksAllowed? o.click(event): (event.preventDefault? event.preventDefault() : event.returnValue = false); - }); - - return { - getClicksAllowed: function() { - return clicksAllowed; - } - } -} \ No newline at end of file diff --git a/test/bonus_tests.htm b/test/bonus.htm similarity index 99% rename from test/bonus_tests.htm rename to test/bonus.htm index 20694dd..e4e3fea 100644 --- a/test/bonus_tests.htm +++ b/test/bonus.htm @@ -204,7 +204,7 @@

Dots first, start from 3rd slide

- + - +