@@ -46,6 +46,23 @@ const createBullets = (container, bulletId) => {
46
46
container . append ( $element ) ;
47
47
} ;
48
48
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
+
49
66
/**
50
67
* Creates navigation arrows for the slider.
51
68
* @param {Element } container The slider container element.
@@ -231,10 +248,7 @@ const prepareData = (block, container, containerClass) => {
231
248
clickable : $bullet . clickable ,
232
249
dynamicBullets : $bullet . dynamicBullets ,
233
250
...( 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 )
238
252
} )
239
253
} ;
240
254
}
@@ -267,9 +281,7 @@ const prepareData = (block, container, containerClass) => {
267
281
try {
268
282
// Case where slide element tag does not match.
269
283
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.` ) ;
273
285
}
274
286
275
287
// An info message if slide is empty.
0 commit comments