From 22ce9f3ba268cd8778fd02d3a2b5d1e4b6754e8a Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Sat, 25 Mar 2017 18:31:06 -1000 Subject: [PATCH 1/2] Support start slide on setup This allows you to add slides dynamically, even when moving backward. To add a slide that occurs right before the current first slide write code like the following: var mySwipe = new Swipe(document.getElementById('slider'), {}) $('.swipe-wrap').prepend('
New Slide
'); mySwipe.setup({startSlide: 1}); This fork can be installed via bower with: bower install "swipe-js=https://github.com/axelson/swipe.git#2.2.4" --- bower.json | 2 +- build/swipe.min.js | 2 +- swipe.js | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index fadcd2d..dea0349 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "swipe-js", - "version": "2.2.3", + "version": "2.2.4", "main": [ "./swipe.js" ], diff --git a/build/swipe.min.js b/build/swipe.min.js index 3dc6d04..d81dc94 100644 --- a/build/swipe.min.js +++ b/build/swipe.min.js @@ -5,4 +5,4 @@ * Copyright 2013, MIT License * */ -!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.Swipe=b(),a.Swipe}):"object"==typeof module&&module.exports?module.exports=b():a.Swipe=b()}(this,function(){function Swipe(c,d){"use strict";function e(){E.addEventListener?(J.removeEventListener("touchstart",N,!1),J.removeEventListener("mousedown",N,!1),J.removeEventListener("webkitTransitionEnd",N,!1),J.removeEventListener("msTransitionEnd",N,!1),J.removeEventListener("oTransitionEnd",N,!1),J.removeEventListener("otransitionend",N,!1),J.removeEventListener("transitionend",N,!1),a.removeEventListener("resize",N,!1)):a.onresize=null}function f(){E.addEventListener?(E.touch&&J.addEventListener("touchstart",N,!1),d.draggable&&J.addEventListener("mousedown",N,!1),E.transitions&&(J.addEventListener("webkitTransitionEnd",N,!1),J.addEventListener("msTransitionEnd",N,!1),J.addEventListener("oTransitionEnd",N,!1),J.addEventListener("otransitionend",N,!1),J.addEventListener("transitionend",N,!1)),a.addEventListener("resize",N,!1)):a.onresize=M}function g(){if(F=J.children,I=F.length,F.length<2&&(d.continuous=!1),E.transitions&&d.continuous&&F.length<3){var a=F[0].cloneNode(!0),b=J.children[1].cloneNode(!0);J.appendChild(a),J.appendChild(b),a.setAttribute("data-cloned",!0),b.setAttribute("data-cloned",!0),F=J.children}G=new Array(F.length),H=c.getBoundingClientRect().width||c.offsetWidth,J.style.width=F.length*H*2+"px";for(var g=F.length;g--;){var h=F[g];h.style.width=H+"px",h.setAttribute("data-index",g),E.transitions&&(h.style.left=g*-H+"px",o(g,K>g?-H:K=I&&(a-=I),a}function n(a,b){if(a="number"!=typeof a?parseInt(a,10):a,K!==a){if(E.transitions){var c=Math.abs(K-a)/(K-a);if(d.continuous){var e=c;c=-G[l(a)]/H,c!==e&&(a=-c*F.length+a)}for(var f=Math.abs(K-a)-1;f--;)o(l((a>K?a:K)-f-1),H*c,0);a=l(a),o(K,H*c,b||L),o(a,0,b||L),d.continuous&&o(l(a-c),-(H*c),0)}else a=l(a),q(K*-H,a*-H,b||L);K=a,C(function(){j(m(),F[K],c)})}}function o(a,b,c){p(a,b,c),G[a]=b}function p(a,b,c){var d=F[a],e=d&&d.style;e&&(e.webkitTransitionDuration=e.MozTransitionDuration=e.msTransitionDuration=e.OTransitionDuration=e.transitionDuration=c+"ms",e.webkitTransform="translate("+b+"px,0)translateZ(0)",e.msTransform=e.MozTransform=e.OTransform="translateX("+b+"px)")}function q(a,b,c){if(!c)return void(J.style.left=b+"px");var e=+new Date,f=setInterval(function(){var g=+new Date-e;return g>c?(J.style.left=b+"px",(A||d.autoRestart)&&t(),k(m(),F[K]),void clearInterval(f)):void(J.style.left=(b-a)*(Math.floor(g/c*100)/100)+a+"px")},4)}function r(){x=setTimeout(i,A)}function s(){A=0,clearTimeout(x)}function t(){s(),A=d.auto||0,r()}function u(a){return/^mouse/.test(a.type)}function v(){s(),c.style.visibility="",J.style.width="",J.style.left="";for(var a=F.length;a--;){E.transitions&&p(a,0,0);var b=F[a];if(b.getAttribute("data-cloned")){var d=b.parentElement;d.removeChild(b)}b.style.width="",b.style.left="",b.style.webkitTransitionDuration=b.style.MozTransitionDuration=b.style.msTransitionDuration=b.style.OTransitionDuration=b.style.transitionDuration="",b.style.webkitTransform=b.style.msTransform=b.style.MozTransform=b.style.OTransform=""}e(),M.cancel()}d=d||{};var w,x,y={},z={},A=d.auto||0,B=function(){},C=function(a){setTimeout(a||B,0)},D=function(a,b){function c(){e&&clearTimeout(e)}function d(){var d=this,f=arguments;c(),e=setTimeout(function(){e=null,a.apply(d,f)},b)}b=b||100;var e=null;return d.cancel=c,d},E={addEventListener:!!a.addEventListener,touch:"ontouchstart"in a||a.DocumentTouch&&b instanceof DocumentTouch,transitions:function(a){var b=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var c in b)if(void 0!==a.style[b[c]])return!0;return!1}(b.createElement("swipe"))};if(c){var F,G,H,I,J=c.children[0],K=parseInt(d.startSlide,10)||0,L=d.speed||300;d.continuous=void 0===d.continuous||d.continuous,d.autoRestart=void 0!==d.autoRestart&&d.autoRestart;var M=D(g),N={handleEvent:function(a){switch(a.type){case"mousedown":case"touchstart":this.start(a);break;case"mousemove":case"touchmove":this.move(a);break;case"mouseup":case"mouseleave":case"touchend":this.end(a);break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":this.transitionEnd(a);break;case"resize":M()}d.stopPropagation&&a.stopPropagation()},start:function(a){var b;u(a)?(b=a,a.preventDefault()):b=a.touches[0],y={x:b.pageX,y:b.pageY,time:+new Date},w=void 0,z={},u(a)?(J.addEventListener("mousemove",this,!1),J.addEventListener("mouseup",this,!1),J.addEventListener("mouseleave",this,!1)):(J.addEventListener("touchmove",this,!1),J.addEventListener("touchend",this,!1))},move:function(a){var b;if(u(a))b=a;else{if(a.touches.length>1||a.scale&&1!==a.scale)return;d.disableScroll&&a.preventDefault(),b=a.touches[0]}z={x:b.pageX-y.x,y:b.pageY-y.y},"undefined"==typeof w&&(w=!!(w||Math.abs(z.x)0||K===F.length-1&&z.x<0?Math.abs(z.x)/H+1:1),p(K-1,z.x+G[K-1],0),p(K,z.x+G[K],0),p(K+1,z.x+G[K+1],0)))},end:function(a){var b=+new Date-y.time,c=Number(b)<250&&Math.abs(z.x)>20||Math.abs(z.x)>H/2,e=!K&&z.x>0||K===F.length-1&&z.x<0;d.continuous&&(e=!1);var f=Math.abs(z.x)/z.x;w||(c&&!e?(f<0?(d.continuous?(o(l(K-1),-H,0),o(l(K+2),H,0)):o(K-1,-H,0),o(K,G[K]-H,L),o(l(K+1),G[l(K+1)]-H,L),K=l(K+1)):(d.continuous?(o(l(K+1),H,0),o(l(K-2),-H,0)):o(K+1,H,0),o(K,G[K]+H,L),o(l(K-1),G[l(K-1)]+H,L),K=l(K-1)),j(m(),F[K],f)):d.continuous?(o(l(K-1),-H,L),o(K,0,L),o(l(K+1),H,L)):(o(K-1,-H,L),o(K,0,L),o(K+1,H,L))),u(a)?(J.removeEventListener("mousemove",N,!1),J.removeEventListener("mouseup",N,!1),J.removeEventListener("mouseleave",N,!1)):(J.removeEventListener("touchmove",N,!1),J.removeEventListener("touchend",N,!1))},transitionEnd:function(a){var b=parseInt(a.target.getAttribute("data-index"),10);b===K&&((A||d.autoRestart)&&t(),k(m(),F[K]))}};return g(),A&&r(),{setup:g,slide:function(a,b){s(),n(a,b)},prev:function(){s(),h()},next:function(){s(),i()},restart:t,stop:s,getPos:m,getNumSlides:function(){return I},kill:v}}}var a="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this,b=a.document;return(a.jQuery||a.Zepto)&&!function(a){a.fn.Swipe=function(b){return this.each(function(){a(this).data("Swipe",new Swipe(a(this)[0],b))})}}(a.jQuery||a.Zepto),Swipe}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.Swipe=b(),a.Swipe}):"object"==typeof module&&module.exports?module.exports=b():a.Swipe=b()}(this,function(){function Swipe(c,d){"use strict";function e(){E.addEventListener?(J.removeEventListener("touchstart",N,!1),J.removeEventListener("mousedown",N,!1),J.removeEventListener("webkitTransitionEnd",N,!1),J.removeEventListener("msTransitionEnd",N,!1),J.removeEventListener("oTransitionEnd",N,!1),J.removeEventListener("otransitionend",N,!1),J.removeEventListener("transitionend",N,!1),a.removeEventListener("resize",N,!1)):a.onresize=null}function f(){E.addEventListener?(E.touch&&J.addEventListener("touchstart",N,!1),d.draggable&&J.addEventListener("mousedown",N,!1),E.transitions&&(J.addEventListener("webkitTransitionEnd",N,!1),J.addEventListener("msTransitionEnd",N,!1),J.addEventListener("oTransitionEnd",N,!1),J.addEventListener("otransitionend",N,!1),J.addEventListener("transitionend",N,!1)),a.addEventListener("resize",N,!1)):a.onresize=M}function g(a){if(a&&a.startSlide&&(K=parseInt(a.startSlide,10)||0),F=J.children,I=F.length,F.length<2&&(d.continuous=!1),E.transitions&&d.continuous&&F.length<3){var b=F[0].cloneNode(!0),g=J.children[1].cloneNode(!0);J.appendChild(b),J.appendChild(g),b.setAttribute("data-cloned",!0),g.setAttribute("data-cloned",!0),F=J.children}G=new Array(F.length),H=c.getBoundingClientRect().width||c.offsetWidth,J.style.width=F.length*H*2+"px";for(var h=F.length;h--;){var i=F[h];i.style.width=H+"px",i.setAttribute("data-index",h),E.transitions&&(i.style.left=h*-H+"px",o(h,K>h?-H:K=I&&(a-=I),a}function n(a,b){if(a="number"!=typeof a?parseInt(a,10):a,K!==a){if(E.transitions){var c=Math.abs(K-a)/(K-a);if(d.continuous){var e=c;c=-G[l(a)]/H,c!==e&&(a=-c*F.length+a)}for(var f=Math.abs(K-a)-1;f--;)o(l((a>K?a:K)-f-1),H*c,0);a=l(a),o(K,H*c,b||L),o(a,0,b||L),d.continuous&&o(l(a-c),-(H*c),0)}else a=l(a),q(K*-H,a*-H,b||L);K=a,C(function(){j(m(),F[K],c)})}}function o(a,b,c){p(a,b,c),G[a]=b}function p(a,b,c){var d=F[a],e=d&&d.style;e&&(e.webkitTransitionDuration=e.MozTransitionDuration=e.msTransitionDuration=e.OTransitionDuration=e.transitionDuration=c+"ms",e.webkitTransform="translate("+b+"px,0)translateZ(0)",e.msTransform=e.MozTransform=e.OTransform="translateX("+b+"px)")}function q(a,b,c){if(!c)return void(J.style.left=b+"px");var e=+new Date,f=setInterval(function(){var g=+new Date-e;if(g>c)return J.style.left=b+"px",(A||d.autoRestart)&&t(),k(m(),F[K]),void clearInterval(f);J.style.left=(b-a)*(Math.floor(g/c*100)/100)+a+"px"},4)}function r(){x=setTimeout(i,A)}function s(){A=0,clearTimeout(x)}function t(){s(),A=d.auto||0,r()}function u(a){return/^mouse/.test(a.type)}function v(){s(),c.style.visibility="",J.style.width="",J.style.left="";for(var a=F.length;a--;){E.transitions&&p(a,0,0);var b=F[a];if(b.getAttribute("data-cloned")){b.parentElement.removeChild(b)}b.style.width="",b.style.left="",b.style.webkitTransitionDuration=b.style.MozTransitionDuration=b.style.msTransitionDuration=b.style.OTransitionDuration=b.style.transitionDuration="",b.style.webkitTransform=b.style.msTransform=b.style.MozTransform=b.style.OTransform=""}e(),M.cancel()}d=d||{};var w,x,y={},z={},A=d.auto||0,B=function(){},C=function(a){setTimeout(a||B,0)},D=function(a,b){function c(){e&&clearTimeout(e)}function d(){var d=this,f=arguments;c(),e=setTimeout(function(){e=null,a.apply(d,f)},b)}b=b||100;var e=null;return d.cancel=c,d},E={addEventListener:!!a.addEventListener,touch:"ontouchstart"in a||a.DocumentTouch&&b instanceof DocumentTouch,transitions:function(a){var b=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var c in b)if(void 0!==a.style[b[c]])return!0;return!1}(b.createElement("swipe"))};if(c){var F,G,H,I,J=c.children[0],K=parseInt(d.startSlide,10)||0,L=d.speed||300;d.continuous=void 0===d.continuous||d.continuous,d.autoRestart=void 0!==d.autoRestart&&d.autoRestart;var M=D(g),N={handleEvent:function(a){switch(a.type){case"mousedown":case"touchstart":this.start(a);break;case"mousemove":case"touchmove":this.move(a);break;case"mouseup":case"mouseleave":case"touchend":this.end(a);break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":this.transitionEnd(a);break;case"resize":M()}d.stopPropagation&&a.stopPropagation()},start:function(a){var b;u(a)?(b=a,a.preventDefault()):b=a.touches[0],y={x:b.pageX,y:b.pageY,time:+new Date},w=void 0,z={},u(a)?(J.addEventListener("mousemove",this,!1),J.addEventListener("mouseup",this,!1),J.addEventListener("mouseleave",this,!1)):(J.addEventListener("touchmove",this,!1),J.addEventListener("touchend",this,!1))},move:function(a){var b;if(u(a))b=a;else{if(a.touches.length>1||a.scale&&1!==a.scale)return;d.disableScroll&&a.preventDefault(),b=a.touches[0]}z={x:b.pageX-y.x,y:b.pageY-y.y},void 0===w&&(w=!!(w||Math.abs(z.x)0||K===F.length-1&&z.x<0?Math.abs(z.x)/H+1:1),p(K-1,z.x+G[K-1],0),p(K,z.x+G[K],0),p(K+1,z.x+G[K+1],0)))},end:function(a){var b=+new Date-y.time,c=Number(b)<250&&Math.abs(z.x)>20||Math.abs(z.x)>H/2,e=!K&&z.x>0||K===F.length-1&&z.x<0;d.continuous&&(e=!1);var f=Math.abs(z.x)/z.x;w||(c&&!e?(f<0?(d.continuous?(o(l(K-1),-H,0),o(l(K+2),H,0)):o(K-1,-H,0),o(K,G[K]-H,L),o(l(K+1),G[l(K+1)]-H,L),K=l(K+1)):(d.continuous?(o(l(K+1),H,0),o(l(K-2),-H,0)):o(K+1,H,0),o(K,G[K]+H,L),o(l(K-1),G[l(K-1)]+H,L),K=l(K-1)),j(m(),F[K],f)):d.continuous?(o(l(K-1),-H,L),o(K,0,L),o(l(K+1),H,L)):(o(K-1,-H,L),o(K,0,L),o(K+1,H,L))),u(a)?(J.removeEventListener("mousemove",N,!1),J.removeEventListener("mouseup",N,!1),J.removeEventListener("mouseleave",N,!1)):(J.removeEventListener("touchmove",N,!1),J.removeEventListener("touchend",N,!1))},transitionEnd:function(a){parseInt(a.target.getAttribute("data-index"),10)===K&&((A||d.autoRestart)&&t(),k(m(),F[K]))}};return g(),A&&r(),{setup:g,slide:function(a,b){s(),n(a,b)},prev:function(){s(),h()},next:function(){s(),i()},restart:t,stop:s,getPos:m,getNumSlides:function(){return I},kill:v}}}var a="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this,b=a.document;return(a.jQuery||a.Zepto)&&function(a){a.fn.Swipe=function(b){return this.each(function(){a(this).data("Swipe",new Swipe(a(this)[0],b))})}}(a.jQuery||a.Zepto),Swipe}); \ No newline at end of file diff --git a/swipe.js b/swipe.js index 1ac89e6..814ea2b 100644 --- a/swipe.js +++ b/swipe.js @@ -434,7 +434,13 @@ } } - function setup() { + function setup(opts) { + if (opts) { + if (opts.startSlide) { + index = parseInt(opts.startSlide, 10) || 0; + } + } + // cache slides slides = element.children; length = slides.length; From 86e45a1ecdae430ff5d583c3d75479749c6ba17d Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Sat, 14 Oct 2017 08:44:40 -1000 Subject: [PATCH 2/2] Update version to "2.2.5" --- bower.json | 2 +- build/swipe.min.js | 2 +- package.json | 2 +- react/index.js | 2 +- react/swipe.jsx | 2 +- swipe.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index dea0349..c44bc4c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "swipe-js", - "version": "2.2.4", + "version": "2.2.5", "main": [ "./swipe.js" ], diff --git a/build/swipe.min.js b/build/swipe.min.js index d81dc94..67a4bd5 100644 --- a/build/swipe.min.js +++ b/build/swipe.min.js @@ -1,5 +1,5 @@ /*! - * Swipe 2.2.4 + * Swipe 2.2.5 * * Brad Birdsall * Copyright 2013, MIT License diff --git a/package.json b/package.json index 10115bf..7772a74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swipejs", - "version": "2.2.4", + "version": "2.2.5", "main": "swipe.js", "types": "types/swipe.d.ts", "description": "Swipe is the most accurate touch slider", diff --git a/react/index.js b/react/index.js index f0f503b..d3e8cab 100644 --- a/react/index.js +++ b/react/index.js @@ -1,5 +1,5 @@ /*! - * React Swipe 2.2.4 + * React Swipe 2.2.5 * * Felix Liu * Copyright 2016, MIT License diff --git a/react/swipe.jsx b/react/swipe.jsx index 7526794..45d5219 100644 --- a/react/swipe.jsx +++ b/react/swipe.jsx @@ -1,5 +1,5 @@ /*! - * React Swipe 2.2.4 + * React Swipe 2.2.5 * * Felix Liu * Copyright 2016, MIT License diff --git a/swipe.js b/swipe.js index 814ea2b..b602f7e 100644 --- a/swipe.js +++ b/swipe.js @@ -1,5 +1,5 @@ /*! - * Swipe 2.2.4 + * Swipe 2.2.5 * * Brad Birdsall * Copyright 2013, MIT License