Skip to content

Commit beb2d15

Browse files
author
hsehszroc
committed
ADDED: method to handle rendering custom bullet.
1 parent 7e332b7 commit beb2d15

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

build/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/slider.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/slider.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/slider.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ const createBullets = (container, bulletId) => {
4646
container.append($element);
4747
};
4848

49+
/**
50+
* Sets contents to display instead of just bullet.
51+
*
52+
* @param {string[]} options Bullets render options.
53+
* @param {number} count Total number of slides.
54+
* @param {number} index The current bullet position.
55+
* @param {string} className The current bullet class name.
56+
* @returns {string} HTML output with `span` tag for rendering bullet.
57+
*/
58+
const setBullets = (options, count, index, className) => {
59+
let $bulletContent = options.length === count ? options[index] : '',
60+
$bulletCount = index + 1,
61+
$bulletClass = `${className} bullet__${$bulletCount}`;
62+
63+
return '<span class="' + $bulletClass + '">' + $bulletContent + '</span>';
64+
};
65+
4966
/**
5067
* Creates navigation arrows for the slider.
5168
* @param {Element} container The slider container element.
@@ -231,10 +248,7 @@ const prepareData = (block, container, containerClass) => {
231248
clickable: $bullet.clickable,
232249
dynamicBullets: $bullet.dynamicBullets,
233250
...(hasContent($bulletRender, $invalidBulletMsg) && {
234-
renderBullet: (index, className) => {
235-
let $bulletContent = $bulletRender.length === $slideCount ? $bulletRender[index] : '';
236-
return '<span class="' + className + '">' + $bulletContent + '</span>';
237-
}
251+
renderBullet: (index, className) => setBullets($bulletRender, $slideCount, index, className)
238252
})
239253
};
240254
}
@@ -267,9 +281,7 @@ const prepareData = (block, container, containerClass) => {
267281
try {
268282
// Case where slide element tag does not match.
269283
if ($getSlide[0] !== $nodeTag) {
270-
throw new Error(
271-
`${$msgPrefix}the slide elements do not match. Element set on slider option is "<${$getSlide[0]}>" but "<${$nodeTag}>" found.`
272-
);
284+
throw new Error(`${$msgPrefix}the slide elements do not match. Element set on slider option is "<${$getSlide[0]}>" but "<${$nodeTag}>" found.`);
273285
}
274286

275287
// An info message if slide is empty.

0 commit comments

Comments
 (0)