From 38fc319ba30e3a9fa034e71331ae58fec00b04f0 Mon Sep 17 00:00:00 2001 From: Wikiki Date: Sun, 13 May 2018 13:40:31 +0200 Subject: [PATCH] [Prerelease] Bumped version number --- CHANGELOG.md | 5 +++++ bower.json | 2 +- dist/bulma-carousel.js | 14 +++++--------- dist/bulma-carousel.min.js | 2 +- package.json | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebe2171..cb05bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ + +## [2.0.10](https://github.com/Wikiki/bulma-carousel/compare/2.0.9...2.0.10) (2018-05-13) + + + ## [2.0.9](https://github.com/Wikiki/bulma-carousel/compare/2.0.8...2.0.9) (2018-05-11) diff --git a/bower.json b/bower.json index dbb45a7..35a9f7b 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "bulma-carousel", "description": "Display a Image / Content carousel", "main": "carousel.sass", - "version": "2.0.9", + "version": "2.0.10", "authors": [ "Wikiki (https://wikiki.github.io/bulma-extensions/overview)" ], diff --git a/dist/bulma-carousel.js b/dist/bulma-carousel.js index 3700aa8..1bba287 100644 --- a/dist/bulma-carousel.js +++ b/dist/bulma-carousel.js @@ -146,9 +146,9 @@ class Carousel extends EventEmitter { /// Set default options and merge with instance defined this.options = Object.assign({}, { - threshold: 150, //required min distance traveled to be considered swipe + threshold: 50, //required min distance traveled to be considered swipe restraint: 100, // maximum distance allowed at the same time in perpendicular direction - allowedTime: 300 // maximum time allowed to travel that distance + allowedTime: 500 // maximum time allowed to travel that distance }); this.init(); @@ -302,18 +302,12 @@ class Carousel extends EventEmitter { this.carousel.addEventListener('touchstart', e => { this._swipeStart(e); }); - this.carousel.addEventListener('mousedown', e => { - this._swipeStart(e); - }); this.carousel.addEventListener('touchmove', e => { e.preventDefault(); }); this.carousel.addEventListener('touchend', e => { this._swipeEnd(e); }); - this.carousel.addEventListener('mouseup', e => { - this._swipeEnd(e); - }); } /** @@ -376,6 +370,7 @@ class Carousel extends EventEmitter { */ _swipeStart(e) { e.preventDefault(); + this._touch = { start: { time: new Date().getTime(), // record time when finger first makes contact with surface @@ -397,6 +392,7 @@ class Carousel extends EventEmitter { */ _swipeEnd(e) { e.preventDefault(); + const touchObj = e.changedTouches[0]; this._touch.dist = { x: touchObj.pageX - this._touch.start.x, // get horizontal dist traveled by finger while in contact with surface @@ -412,7 +408,7 @@ class Carousel extends EventEmitter { * @return {void} */ _handleGesture() { - elapsedTime = new Date().getTime() - this._touch.start.time; // get time elapsed + const elapsedTime = new Date().getTime() - this._touch.start.time; // get time elapsed if (elapsedTime <= this.options.allowedTime) { // first condition for awipe met if (Math.abs(this._touch.dist.x) >= this.options.threshold && Math.abs(this._touch.dist.y) <= this.options.restraint) { // 2nd condition for horizontal swipe met (this._touch.dist.x < 0) ? this._slide('next') : this._slide('previous'); // if dist traveled is negative, it indicates left swipe diff --git a/dist/bulma-carousel.min.js b/dist/bulma-carousel.min.js index 13a6f0c..8fd174b 100644 --- a/dist/bulma-carousel.min.js +++ b/dist/bulma-carousel.min.js @@ -1 +1 @@ -(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define('bulmaCarousel',b):a.bulmaCarousel=b()})(this,function(){'use strict';var a=Math.abs;class b{constructor(a=[]){this._listeners=new Map(a),this._middlewares=new Map}listenerCount(a){if(!this._listeners.has(a))return 0;const b=this._listeners.get(a);return b.length}removeListeners(a=null,b=!1){null===a?this._listeners=new Map:Array.isArray(a)?name.forEach((a)=>this.removeListeners(a,b)):(this._listeners.delete(a),b&&this.removeMiddleware(a))}middleware(a,b){Array.isArray(a)?name.forEach((a)=>this.middleware(a,b)):(!Array.isArray(this._middlewares.get(a))&&this._middlewares.set(a,[]),this._middlewares.get(a).push(b))}removeMiddleware(a=null){null===a?this._middlewares=new Map:Array.isArray(a)?name.forEach((a)=>this.removeMiddleware(a)):this._middlewares.delete(a)}on(a,b,c=!1){if(Array.isArray(a))a.forEach((a)=>this.on(a,b));else{a=a.toString();const d=a.split(/,|, | /);1this.on(a,b)):(!Array.isArray(this._listeners.get(a))&&this._listeners.set(a,[]),this._listeners.get(a).push({once:c,callback:b}))}}once(a,b){this.on(a,b,!0)}emit(a,b,c=!1){a=a.toString();let d=this._listeners.get(a),e=null,f=0,g=c;if(Array.isArray(d))for(d.forEach((h,i)=>{c||(e=this._middlewares.get(a),Array.isArray(e)?(e.forEach((c)=>{c(b,(a=null)=>{null!==a&&(b=a),f++},a)}),f>=e.length&&(g=!0)):g=!0),g&&(h.once&&(d[i]=null),h.callback(b))});-1!==d.indexOf(null);)d.splice(d.indexOf(null),1)}}class c extends b{constructor(a){if(super(),this._clickEvents=['touchstart','click'],this.carousel='string'==typeof a?document.querySelector(a):a,!this.carousel)throw new Error('An invalid selector or non-DOM node has been provided.');this.options=Object.assign({},{threshold:150,restraint:100,allowedTime:300}),this.init()}static attach(a='.carousel, .hero-carousel'){let b=[];const d=document.querySelectorAll(a);return[].forEach.call(d,(a)=>{setTimeout(()=>{b.push(new c(a))},100)}),b}init(){let a=!1;if(this.computedStyle=window.getComputedStyle(this.carousel),this.carouselWidth=parseInt(this.computedStyle.getPropertyValue('width'),10),this.carouselContainer=this.carousel.querySelector('.carousel-container'),this.carouselItems=this.carousel.querySelectorAll('.carousel-item'),this.carouselItemsArray=Array.from(this.carouselItems),this.carousel.dataset.size&&!this.carousel.classList.contains('carousel-animate-fade')&&(this.carousel.dataset.size>=this.carouselItemsArray.length?(this.offset=0,a=!0):this.offset=this.carouselWidth/this.carousel.dataset.size,this.carouselContainer.style.left=0-this.offset+'px',this.carouselContainer.style.transform=`translateX(${this.offset}px)`,[].forEach.call(this.carouselItems,(a)=>{a.style.flexBasis=`${this.offset}px`})),this._initNavigation(a),this.carousel.classList.contains('carousel-animate-fade')&&this.carouselItems.length){let a=this.carouselItems[0].querySelector('img'),b=1;a.naturalWidth?(b=this.carouselWidth/a.naturalWidth,this.carouselContainer.style.height=a.naturalHeight*b+'px'):a.onload=()=>{b=this.carouselWidth/a.naturalWidth,this.carouselContainer.style.height=a.naturalHeight*b+'px'}}this.currentItem={carousel:this.carousel,node:null,pos:-1},this.currentItem.node=this.carousel.querySelector('.carousel-item.is-active'),this.currentItem.pos=this.currentItem.node?this.carouselItemsArray.indexOf(this.currentItem.node):-1,this.currentItem.node||(this.currentItem.node=this.carouselItems[0],this.currentItem.node.classList.add('is-active'),this.currentItem.pos=0),this._setOrder(),this.carousel.dataset.autoplay&&'true'==this.carousel.dataset.autoplay&&this._autoPlay(this.carousel.dataset.delay||5e3),this._bindEvents(),this.emit('carousel:ready',this.currentItem)}_initNavigation(a=!1){this.previousControl=this.carousel.querySelector('.carousel-nav-left'),this.nextControl=this.carousel.querySelector('.carousel-nav-right'),(1>=this.carouselItems.length||a)&&(this.carouselContainer&&(this.carouselContainer.style.left='0'),this.previousControl&&(this.previousControl.style.display='none'),this.nextControl&&(this.nextControl.style.display='none'))}_bindEvents(){this.previousControl&&this._clickEvents.forEach((a)=>{this.previousControl.addEventListener(a,(a)=>{a.preventDefault(),this._slide('previous'),this._autoPlayInterval&&(clearInterval(this._autoPlayInterval),this._autoPlay(this.carousel.dataset.delay||5e3))})}),this.nextControl&&this._clickEvents.forEach((a)=>{this.nextControl.addEventListener(a,(a)=>{a.preventDefault(),this._slide('next'),this._autoPlayInterval&&(clearInterval(this._autoPlayInterval),this._autoPlay(this.carousel.dataset.delay||5e3))})}),this.carousel.addEventListener('touchstart',(a)=>{this._swipeStart(a)}),this.carousel.addEventListener('mousedown',(a)=>{this._swipeStart(a)}),this.carousel.addEventListener('touchmove',(a)=>{a.preventDefault()}),this.carousel.addEventListener('touchend',(a)=>{this._swipeEnd(a)}),this.carousel.addEventListener('mouseup',(a)=>{this._swipeEnd(a)})}_next(a){return a.nextElementSibling?a.nextElementSibling:this.carouselItems[0]}_previous(a){return a.previousElementSibling?a.previousElementSibling:this.carouselItems[this.carouselItems.length-1]}_setOrder(){this.currentItem.node.style.order='1',this.currentItem.node.style.zIndex='1';let a,b,c,d=this.currentItem.node;for(a=b=2,c=this.carouselItemsArray.length;2<=c?b<=c:b>=c;a=2<=c?++b:--b)d=this._next(d),d.style.order=''+a%this.carouselItemsArray.length,d.style.zIndex='0'}_swipeStart(a){a.preventDefault(),this._touch={start:{time:new Date().getTime(),x:touchObj.pageX,y:touchObj.pageY},dist:{x:0,y:0}}}_swipeEnd(a){a.preventDefault();const b=a.changedTouches[0];this._touch.dist={x:b.pageX-this._touch.start.x,y:b.pageY-this._touch.start.y},this._handleGesture()}_handleGesture(){elapsedTime=new Date().getTime()-this._touch.start.time,elapsedTime<=this.options.allowedTime&&a(this._touch.dist.x)>=this.options.threshold&&a(this._touch.dist.y)<=this.options.restraint&&(0>this._touch.dist.x?this._slide('next'):this._slide('previous'))}_slide(b='next'){this.carouselItems.length&&(this.emit('carousel:slide:before',this.currentItem),this.currentItem.node.classList.remove('is-active'),'previous'===b?(this.currentItem.node=this._previous(this.currentItem.node),!this.carousel.classList.contains('carousel-animate-fade')&&(this.carousel.classList.add('is-reversing'),this.carouselContainer.style.transform=`translateX(${-a(this.offset)}px)`)):(this.currentItem.node=this._next(this.currentItem.node),this.carousel.classList.remove('is-reversing'),this.carouselContainer.style.transform=`translateX(${a(this.offset)}px)`),this.currentItem.node.classList.add('is-active'),this.carousel.classList.remove('carousel-animated'),setTimeout(()=>{this.carousel.classList.add('carousel-animated')},50),this._setOrder(),this.emit('carousel:slide:after',this.currentItem))}_autoPlay(a=5e3){this._autoPlayInterval=setInterval(()=>{this._slide('next')},a)}}return c}); \ No newline at end of file +(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b():'function'==typeof define&&define.amd?define('bulmaCarousel',b):a.bulmaCarousel=b()})(this,function(){'use strict';var a=Math.abs;class b{constructor(a=[]){this._listeners=new Map(a),this._middlewares=new Map}listenerCount(a){if(!this._listeners.has(a))return 0;const b=this._listeners.get(a);return b.length}removeListeners(a=null,b=!1){null===a?this._listeners=new Map:Array.isArray(a)?name.forEach((a)=>this.removeListeners(a,b)):(this._listeners.delete(a),b&&this.removeMiddleware(a))}middleware(a,b){Array.isArray(a)?name.forEach((a)=>this.middleware(a,b)):(!Array.isArray(this._middlewares.get(a))&&this._middlewares.set(a,[]),this._middlewares.get(a).push(b))}removeMiddleware(a=null){null===a?this._middlewares=new Map:Array.isArray(a)?name.forEach((a)=>this.removeMiddleware(a)):this._middlewares.delete(a)}on(a,b,c=!1){if(Array.isArray(a))a.forEach((a)=>this.on(a,b));else{a=a.toString();const d=a.split(/,|, | /);1this.on(a,b)):(!Array.isArray(this._listeners.get(a))&&this._listeners.set(a,[]),this._listeners.get(a).push({once:c,callback:b}))}}once(a,b){this.on(a,b,!0)}emit(a,b,c=!1){a=a.toString();let d=this._listeners.get(a),e=null,f=0,g=c;if(Array.isArray(d))for(d.forEach((h,i)=>{c||(e=this._middlewares.get(a),Array.isArray(e)?(e.forEach((c)=>{c(b,(a=null)=>{null!==a&&(b=a),f++},a)}),f>=e.length&&(g=!0)):g=!0),g&&(h.once&&(d[i]=null),h.callback(b))});-1!==d.indexOf(null);)d.splice(d.indexOf(null),1)}}class c extends b{constructor(a){if(super(),this._clickEvents=['touchstart','click'],this.carousel='string'==typeof a?document.querySelector(a):a,!this.carousel)throw new Error('An invalid selector or non-DOM node has been provided.');this.options=Object.assign({},{threshold:50,restraint:100,allowedTime:500}),this.init()}static attach(a='.carousel, .hero-carousel'){let b=[];const d=document.querySelectorAll(a);return[].forEach.call(d,(a)=>{setTimeout(()=>{b.push(new c(a))},100)}),b}init(){let a=!1;if(this.computedStyle=window.getComputedStyle(this.carousel),this.carouselWidth=parseInt(this.computedStyle.getPropertyValue('width'),10),this.carouselContainer=this.carousel.querySelector('.carousel-container'),this.carouselItems=this.carousel.querySelectorAll('.carousel-item'),this.carouselItemsArray=Array.from(this.carouselItems),this.carousel.dataset.size&&!this.carousel.classList.contains('carousel-animate-fade')&&(this.carousel.dataset.size>=this.carouselItemsArray.length?(this.offset=0,a=!0):this.offset=this.carouselWidth/this.carousel.dataset.size,this.carouselContainer.style.left=0-this.offset+'px',this.carouselContainer.style.transform=`translateX(${this.offset}px)`,[].forEach.call(this.carouselItems,(a)=>{a.style.flexBasis=`${this.offset}px`})),this._initNavigation(a),this.carousel.classList.contains('carousel-animate-fade')&&this.carouselItems.length){let a=this.carouselItems[0].querySelector('img'),b=1;a.naturalWidth?(b=this.carouselWidth/a.naturalWidth,this.carouselContainer.style.height=a.naturalHeight*b+'px'):a.onload=()=>{b=this.carouselWidth/a.naturalWidth,this.carouselContainer.style.height=a.naturalHeight*b+'px'}}this.currentItem={carousel:this.carousel,node:null,pos:-1},this.currentItem.node=this.carousel.querySelector('.carousel-item.is-active'),this.currentItem.pos=this.currentItem.node?this.carouselItemsArray.indexOf(this.currentItem.node):-1,this.currentItem.node||(this.currentItem.node=this.carouselItems[0],this.currentItem.node.classList.add('is-active'),this.currentItem.pos=0),this._setOrder(),this.carousel.dataset.autoplay&&'true'==this.carousel.dataset.autoplay&&this._autoPlay(this.carousel.dataset.delay||5e3),this._bindEvents(),this.emit('carousel:ready',this.currentItem)}_initNavigation(a=!1){this.previousControl=this.carousel.querySelector('.carousel-nav-left'),this.nextControl=this.carousel.querySelector('.carousel-nav-right'),(1>=this.carouselItems.length||a)&&(this.carouselContainer&&(this.carouselContainer.style.left='0'),this.previousControl&&(this.previousControl.style.display='none'),this.nextControl&&(this.nextControl.style.display='none'))}_bindEvents(){this.previousControl&&this._clickEvents.forEach((a)=>{this.previousControl.addEventListener(a,(a)=>{a.preventDefault(),this._slide('previous'),this._autoPlayInterval&&(clearInterval(this._autoPlayInterval),this._autoPlay(this.carousel.dataset.delay||5e3))})}),this.nextControl&&this._clickEvents.forEach((a)=>{this.nextControl.addEventListener(a,(a)=>{a.preventDefault(),this._slide('next'),this._autoPlayInterval&&(clearInterval(this._autoPlayInterval),this._autoPlay(this.carousel.dataset.delay||5e3))})}),this.carousel.addEventListener('touchstart',(a)=>{this._swipeStart(a)}),this.carousel.addEventListener('touchmove',(a)=>{a.preventDefault()}),this.carousel.addEventListener('touchend',(a)=>{this._swipeEnd(a)})}_next(a){return a.nextElementSibling?a.nextElementSibling:this.carouselItems[0]}_previous(a){return a.previousElementSibling?a.previousElementSibling:this.carouselItems[this.carouselItems.length-1]}_setOrder(){this.currentItem.node.style.order='1',this.currentItem.node.style.zIndex='1';let a,b,c,d=this.currentItem.node;for(a=b=2,c=this.carouselItemsArray.length;2<=c?b<=c:b>=c;a=2<=c?++b:--b)d=this._next(d),d.style.order=''+a%this.carouselItemsArray.length,d.style.zIndex='0'}_swipeStart(a){a.preventDefault(),this._touch={start:{time:new Date().getTime(),x:touchObj.pageX,y:touchObj.pageY},dist:{x:0,y:0}}}_swipeEnd(a){a.preventDefault();const b=a.changedTouches[0];this._touch.dist={x:b.pageX-this._touch.start.x,y:b.pageY-this._touch.start.y},this._handleGesture()}_handleGesture(){const b=new Date().getTime()-this._touch.start.time;b<=this.options.allowedTime&&a(this._touch.dist.x)>=this.options.threshold&&a(this._touch.dist.y)<=this.options.restraint&&(0>this._touch.dist.x?this._slide('next'):this._slide('previous'))}_slide(b='next'){this.carouselItems.length&&(this.emit('carousel:slide:before',this.currentItem),this.currentItem.node.classList.remove('is-active'),'previous'===b?(this.currentItem.node=this._previous(this.currentItem.node),!this.carousel.classList.contains('carousel-animate-fade')&&(this.carousel.classList.add('is-reversing'),this.carouselContainer.style.transform=`translateX(${-a(this.offset)}px)`)):(this.currentItem.node=this._next(this.currentItem.node),this.carousel.classList.remove('is-reversing'),this.carouselContainer.style.transform=`translateX(${a(this.offset)}px)`),this.currentItem.node.classList.add('is-active'),this.carousel.classList.remove('carousel-animated'),setTimeout(()=>{this.carousel.classList.add('carousel-animated')},50),this._setOrder(),this.emit('carousel:slide:after',this.currentItem))}_autoPlay(a=5e3){this._autoPlayInterval=setInterval(()=>{this._slide('next')},a)}}return c}); \ No newline at end of file diff --git a/package.json b/package.json index 18aec5c..e679dbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bulma-carousel", - "version": "2.0.9", + "version": "2.0.10", "description": "Display a Image / Content carousel", "main": "dist/bulma-carousel.sass", "scripts": {