@evermade/overflow-slider 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +8 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/arrows/index.d.ts +1 -1
- package/dist/plugins/autoplay/index.d.ts +1 -1
- package/dist/plugins/classnames/index.d.ts +1 -1
- package/dist/plugins/core/index.d.ts +65 -10
- package/dist/plugins/core/index.d2.ts +12 -63
- package/dist/plugins/dots/index.d.ts +1 -1
- package/dist/plugins/dots/index.esm.js +9 -1
- package/dist/plugins/dots/index.min.js +1 -1
- package/dist/plugins/drag-scrolling/index.d.ts +1 -1
- package/dist/plugins/fade/index.d.ts +1 -1
- package/dist/plugins/full-width/index.d.ts +1 -1
- package/dist/plugins/scroll-indicator/index.d.ts +1 -1
- package/dist/plugins/skip-links/index.d.ts +1 -1
- package/dist/plugins/thumbnails/index.d.ts +1 -1
- package/docs/assets/demo.css +6 -0
- package/docs/assets/demo.js +22 -0
- package/docs/dist/index.esm.js +8 -3
- package/docs/dist/index.esm.js.map +1 -1
- package/docs/dist/index.min.js +1 -1
- package/docs/dist/index.min.js.map +1 -1
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/core/index.d.ts +2 -0
- package/docs/dist/plugins/core/index.d2.ts +2 -0
- package/docs/dist/plugins/dots/index.esm.js +9 -1
- package/docs/dist/plugins/dots/index.min.js +1 -1
- package/docs/index.html +15 -0
- package/package.json +1 -1
- package/src/core/details.ts +6 -3
- package/src/core/slider.ts +2 -0
- package/src/core/types.ts +2 -0
- package/src/plugins/dots/index.ts +13 -2
- package/src/plugins/dots/styles.scss +0 -1
|
@@ -20,6 +20,7 @@ function DotsPlugin(args) {
|
|
|
20
20
|
const buildDots = () => {
|
|
21
21
|
dots.setAttribute('data-has-content', slider.details.hasOverflow.toString());
|
|
22
22
|
dots.innerHTML = '';
|
|
23
|
+
console.log('buildDots');
|
|
23
24
|
const dotsList = document.createElement('ul');
|
|
24
25
|
const count = options.type === 'view' ? slider.details.amountOfPages : slider.details.slideCount;
|
|
25
26
|
const currentIndex = options.type === 'view' ? slider.details.currentPage : slider.activeSlideIdx;
|
|
@@ -77,8 +78,15 @@ function DotsPlugin(args) {
|
|
|
77
78
|
}
|
|
78
79
|
};
|
|
79
80
|
const activateDot = (index) => {
|
|
81
|
+
console.log('activateDot', index, 'slider.details', slider.details);
|
|
80
82
|
if (options.type === 'view') {
|
|
81
|
-
const
|
|
83
|
+
const count = slider.details.amountOfPages;
|
|
84
|
+
let targetPosition = slider.details.containerWidth * (index - 1);
|
|
85
|
+
// For the last page, scroll to the maximum scroll position to ensure it activates
|
|
86
|
+
if (index === count) {
|
|
87
|
+
const maxScroll = slider.details.scrollableAreaWidth - slider.details.containerWidth;
|
|
88
|
+
targetPosition = maxScroll;
|
|
89
|
+
}
|
|
82
90
|
const scrollLeft = slider.options.rtl ? -targetPosition : targetPosition;
|
|
83
91
|
slider.container.scrollTo({
|
|
84
92
|
left: scrollLeft,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={dotDescription:"Page %d of %d"},e={dotsContainer:"overflow-slider__dots",dotsItem:"overflow-slider__dot-item"};function n(n){return i=>{var o,s,a;const
|
|
1
|
+
const t={dotDescription:"Page %d of %d"},e={dotsContainer:"overflow-slider__dots",dotsItem:"overflow-slider__dot-item"};function n(n){return i=>{var o,s,a;const l={type:null!==(o=null==n?void 0:n.type)&&void 0!==o?o:"slide",texts:Object.assign(Object.assign({},t),(null==n?void 0:n.texts)||[]),classNames:Object.assign(Object.assign({},e),(null==n?void 0:n.classNames)||[]),container:null!==(s=null==n?void 0:n.container)&&void 0!==s?s:null},r=document.createElement("div");r.classList.add(l.classNames.dotsContainer);let d=null;const c=()=>{r.setAttribute("data-has-content",i.details.hasOverflow.toString()),r.innerHTML="",console.log("buildDots");const t=document.createElement("ul"),e="view"===l.type?i.details.amountOfPages:i.details.slideCount,n="view"===l.type?i.details.currentPage:i.activeSlideIdx;if(!(e<=1)){for(let i=0;i<e;i++){const o=document.createElement("li"),s=document.createElement("button");s.setAttribute("type","button"),s.setAttribute("class",l.classNames.dotsItem),s.setAttribute("aria-label",l.texts.dotDescription.replace("%d",(i+1).toString()).replace("%d",e.toString())),s.setAttribute("aria-pressed",(i===n).toString()),s.setAttribute("data-item",(i+1).toString()),o.appendChild(s),t.appendChild(o),s.addEventListener("click",()=>u(i+1)),s.addEventListener("focus",()=>d=i+1),s.addEventListener("keydown",t=>{var n;const i=r.querySelector('[aria-pressed="true"]');if(!i)return;const o=parseInt(null!==(n=i.getAttribute("data-item"))&&void 0!==n?n:"1");if("ArrowLeft"===t.key){const t=o-1;if(t>0){const e=r.querySelector(`[data-item="${t}"]`);e&&e.focus(),u(t)}}if("ArrowRight"===t.key){const t=o+1;if(t<=e){const e=r.querySelector(`[data-item="${t}"]`);e&&e.focus(),u(t)}}})}if(r.appendChild(t),d){const t=r.querySelector(`[data-item="${d}"]`);t&&t.focus()}}},u=t=>{if(console.log("activateDot",t,"slider.details",i.details),"view"===l.type){const e=i.details.amountOfPages;let n=i.details.containerWidth*(t-1);if(t===e){n=i.details.scrollableAreaWidth-i.details.containerWidth}const o=i.options.rtl?-n:n;i.container.scrollTo({left:o,behavior:i.options.scrollBehavior})}else i.moveToSlide(t-1)};c(),l.container?l.container.appendChild(r):null===(a=i.container.parentNode)||void 0===a||a.insertBefore(r,i.container.nextSibling),i.on("scrollEnd",c),i.on("contentsChanged",c),i.on("containerSizeChanged",c),i.on("detailsChanged",c)}}export{n as default};
|
package/docs/index.html
CHANGED
|
@@ -180,6 +180,21 @@
|
|
|
180
180
|
<a href="#9" class="example-item example-item--9">9</a>
|
|
181
181
|
<a href="#10" class="example-item example-item--10">10</a>
|
|
182
182
|
</div>
|
|
183
|
+
<p style="margin-top:1.5rem;">Display dots indicator (by view) and FullWidthPlugin.</p>
|
|
184
|
+
<div class="example-container-1-full-width-wrapper">
|
|
185
|
+
<div class="overflow-slider example-container example-container-1-dots-view-full">
|
|
186
|
+
<a href="#1" class="example-item example-item--1">1</a>
|
|
187
|
+
<a href="#2" class="example-item example-item--2">2</a>
|
|
188
|
+
<a href="#3" class="example-item example-item--3">3</a>
|
|
189
|
+
<a href="#4" class="example-item example-item--4">4</a>
|
|
190
|
+
<a href="#5" class="example-item example-item--5">5</a>
|
|
191
|
+
<a href="#6" class="example-item example-item--6">6</a>
|
|
192
|
+
<a href="#7" class="example-item example-item--7">7</a>
|
|
193
|
+
<a href="#8" class="example-item example-item--8">8</a>
|
|
194
|
+
<a href="#9" class="example-item example-item--9">9</a>
|
|
195
|
+
<a href="#10" class="example-item example-item--10">10</a>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
183
198
|
</div>
|
|
184
199
|
|
|
185
200
|
<div class="entry__item">
|
package/package.json
CHANGED
package/src/core/details.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default function details( slider: Slider) {
|
|
|
10
10
|
let containerHeight = 0;
|
|
11
11
|
let scrollableAreaWidth = 0;
|
|
12
12
|
let amountOfPages = 0;
|
|
13
|
-
let currentPage =
|
|
13
|
+
let currentPage = 0;
|
|
14
14
|
|
|
15
15
|
if ( Math.floor( slider.getInclusiveScrollWidth() ) > Math.floor( slider.getInclusiveClientWidth() ) ) {
|
|
16
16
|
hasOverflow = true;
|
|
@@ -28,8 +28,11 @@ export default function details( slider: Slider) {
|
|
|
28
28
|
|
|
29
29
|
if ( Math.floor( slider.getScrollLeft() ) >= 0) {
|
|
30
30
|
currentPage = Math.floor(slider.getScrollLeft() / containerWidth);
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
|
|
32
|
+
// Consider as last page if we're within tolerance of the maximum scroll position
|
|
33
|
+
// When FullWidthPlugin is active, account for the margin offset
|
|
34
|
+
const maxScroll = scrollableAreaWidth - containerWidth - (2 * slider.getLeftOffset() );
|
|
35
|
+
if ( slider.getScrollLeft() >= maxScroll - 1 ) {
|
|
33
36
|
currentPage = amountOfPages - 1;
|
|
34
37
|
}
|
|
35
38
|
}
|
package/src/core/slider.ts
CHANGED
|
@@ -593,6 +593,8 @@ export default function Slider( container: HTMLElement, options : SliderOptionAr
|
|
|
593
593
|
snapToClosestSlide,
|
|
594
594
|
getInclusiveScrollWidth,
|
|
595
595
|
getInclusiveClientWidth,
|
|
596
|
+
getLeftOffset,
|
|
597
|
+
getGapSize,
|
|
596
598
|
getScrollLeft,
|
|
597
599
|
setScrollLeft,
|
|
598
600
|
setActiveSlideIdx,
|
package/src/core/types.ts
CHANGED
|
@@ -19,6 +19,8 @@ export type Slider<O = {}, C = {}, H extends string = string> = {
|
|
|
19
19
|
) => boolean
|
|
20
20
|
getInclusiveScrollWidth: () => number
|
|
21
21
|
getInclusiveClientWidth: () => number
|
|
22
|
+
getGapSize: () => number
|
|
23
|
+
getLeftOffset: () => number
|
|
22
24
|
getScrollLeft: () => number
|
|
23
25
|
setScrollLeft: (value: number) => void
|
|
24
26
|
setActiveSlideIdx: () => void
|
|
@@ -45,6 +45,8 @@ export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
|
45
45
|
dots.setAttribute( 'data-has-content', slider.details.hasOverflow.toString() );
|
|
46
46
|
dots.innerHTML = '';
|
|
47
47
|
|
|
48
|
+
console.log('buildDots');
|
|
49
|
+
|
|
48
50
|
const dotsList = document.createElement( 'ul' );
|
|
49
51
|
|
|
50
52
|
const count = options.type === 'view' ? slider.details.amountOfPages : slider.details.slideCount;
|
|
@@ -105,10 +107,19 @@ export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
};
|
|
108
|
-
|
|
109
110
|
const activateDot = ( index: number ) => {
|
|
111
|
+
console.log('activateDot', index, 'slider.details', slider.details);
|
|
112
|
+
|
|
110
113
|
if ( options.type === 'view' ) {
|
|
111
|
-
const
|
|
114
|
+
const count = slider.details.amountOfPages;
|
|
115
|
+
let targetPosition = slider.details.containerWidth * ( index - 1 );
|
|
116
|
+
|
|
117
|
+
// For the last page, scroll to the maximum scroll position to ensure it activates
|
|
118
|
+
if ( index === count ) {
|
|
119
|
+
const maxScroll = slider.details.scrollableAreaWidth - slider.details.containerWidth;
|
|
120
|
+
targetPosition = maxScroll;
|
|
121
|
+
}
|
|
122
|
+
|
|
112
123
|
const scrollLeft = slider.options.rtl ? -targetPosition : targetPosition;
|
|
113
124
|
slider.container.scrollTo({
|
|
114
125
|
left: scrollLeft,
|