Skip to content

Commit bfe94ca

Browse files
authored
Merge branch 'master' into feat-fix-aria
2 parents 130fe99 + 28d53aa commit bfe94ca

File tree

12 files changed

+129
-35
lines changed

12 files changed

+129
-35
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ jspm_packages/
5151

5252
# vuepress build output
5353
.vuepress/dist
54+
55+
# npm package lock file
56+
./package-lock.json

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default {
9292
| speed | Number | 500 | Slide transition speed. Number of milliseconds accepted. |
9393
| value | Number | | Support for v-model functionality. Setting this value will change the current page to the number inputted (if between 0 and pageCount). |
9494

95+
9596
### Events
9697
| Event | Type | Emitter | Description |
9798
|:--------------------------|:--------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -104,7 +105,7 @@ export default {
104105
Once the **Carousel** and **Slide** components are installed globally or imported, they can be used in templates in the following manner:
105106

106107
``` vue
107-
<carousel :per-page="1" :navigate-to="someLocalProperty" mouse-drag="false">
108+
<carousel :per-page="1" :navigate-to="someLocalProperty" :mouse-drag="false">
108109
<slide>
109110
Slide 1 Content
110111
</slide>

dist/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/db.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/public/api/index.html

Lines changed: 84 additions & 18 deletions
Large diffs are not rendered by default.

docs/public/js/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/themes/vue/source/js/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-carousel",
3-
"version": "0.15.0",
3+
"version": "0.16.1",
44
"description": "A flexible, responsive, touch-friendly carousel for Vue.js",
55
"main": "dist/vue-carousel.min.js",
66
"scripts": {

play/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ play("Carousel", module)
5555
h, containerWidth, [h(Carousel, {}, generateSlideImages(h))]
5656
)
5757
)
58+
.add("Too few per page", h => createContainer(
59+
h, containerWidth, [h(Carousel, { props: { perPage: 10, scrollPerPage: false } }, generateSlideImages(h))]
60+
)
61+
)
5862
.add("3 per page", h => createContainer(
5963
h, containerWidth, [h(Carousel, { props: { perPage: 3 } }, generateSlideImages(h))]
6064
)

src/Carousel.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ export default {
163163
type: Boolean,
164164
default: true
165165
},
166+
/*
167+
* Flag to toggle touch dragging
168+
*/
169+
touchDrag: {
170+
type: Boolean,
171+
default: true
172+
},
166173
/**
167174
* Listen for an external navigation request using this prop.
168175
*/
@@ -405,9 +412,10 @@ export default {
405412
* @return {Number}
406413
*/
407414
maxOffset() {
408-
return (
415+
return Math.max(
409416
this.slideWidth * (this.slideCount - this.currentPerPage) -
410-
this.spacePadding * this.spacePaddingMaxOffsetFactor
417+
this.spacePadding * this.spacePaddingMaxOffsetFactor,
418+
0
411419
);
412420
},
413421
/**
@@ -417,7 +425,7 @@ export default {
417425
pageCount() {
418426
return this.scrollPerPage
419427
? Math.ceil(this.slideCount / this.currentPerPage)
420-
: this.slideCount - 2;
428+
: this.slideCount - this.currentPerPage + 1;
421429
},
422430
/**
423431
* Calculate the width of each slide
@@ -762,7 +770,18 @@ export default {
762770
const width = this.scrollPerPage
763771
? this.slideWidth * this.currentPerPage
764772
: this.slideWidth;
765-
this.offset = width * Math.round(this.offset / width);
773+
774+
// lock offset to either the nearest page, or to the last slide
775+
const lastFullPageOffset =
776+
width * Math.floor(this.slideCount / this.currentPerPage - 1);
777+
const remainderOffset =
778+
lastFullPageOffset +
779+
this.slideWidth * (this.slideCount % this.currentPerPage);
780+
if (this.offset > (lastFullPageOffset + remainderOffset) / 2) {
781+
this.offset = remainderOffset;
782+
} else {
783+
this.offset = width * Math.round(this.offset / width);
784+
}
766785
767786
// clamp the offset between 0 -> maxOffset
768787
this.offset = Math.max(0, Math.min(this.offset, this.maxOffset));
@@ -811,7 +830,7 @@ export default {
811830
);
812831
813832
// setup the start event only if touch device or mousedrag activated
814-
if (this.isTouch || this.mouseDrag) {
833+
if ((this.isTouch && this.touchDrag) || this.mouseDrag) {
815834
this.$refs["VueCarousel-wrapper"].addEventListener(
816835
this.isTouch ? "touchstart" : "mousedown",
817836
this.onStart

src/Pagination.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export default {
3232
paginationCount() {
3333
return this.carousel && this.carousel.scrollPerPage
3434
? this.carousel.pageCount
35-
: this.carousel.slideCount
36-
? this.carousel.slideCount - 2
35+
: this.carousel.slideCount && this.carousel.currentPerPage
36+
? this.carousel.slideCount - this.carousel.currentPerPage + 1
3737
: 0;
3838
}
3939
},

src/Slide.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
this.carousel.minSwipeDistance === 0 ||
9292
Math.abs(deltaX) < this.carousel.minSwipeDistance
9393
) {
94-
this.$emit("slideClick", Object.assign({}, e.currentTarget.dataset));
94+
this.$emit("slideclick", Object.assign({}, e.currentTarget.dataset));
9595
}
9696
}
9797
}
@@ -106,6 +106,7 @@ export default {
106106
user-select: none;
107107
backface-visibility: hidden;
108108
-webkit-touch-callout: none;
109+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
109110
outline: none;
110111
}
111112

0 commit comments

Comments
 (0)