/**
* Updates the active state of the bullets, if displayed.
+ * Move the descriptor of the current slide `[data-slide-active-label]` to the newly active bullet.
+ * If no `[data-slide-active-label]` is set, will move the exceeding `span` element.
+ *
* @function
* @private
* @param {Number} idx - the index of the current slide.
*/
_updateBullets(idx) {
var $oldBullet = this.$bullets.filter('.is-active');
+ var $othersBullets = this.$bullets.not('.is-active');
var $newBullet = this.$bullets.eq(idx);
+
$oldBullet.removeClass('is-active').blur();
$newBullet.addClass('is-active');
+ // Find the descriptor for the current slide to move it to the new slide button
var activeStateDescriptor = $oldBullet.children('[data-slide-active-label]').last();
+
+ // If not explicitely given, search for the last "exceeding" span element (compared to others bullets).
if (!activeStateDescriptor.length) {
- activeStateDescriptor = $oldBullet.find('span:last');
- activeStateDescriptor.attr('data-slide-active-label', '');
+ var spans = $oldBullet.children('span');
+ var spanCountInOthersBullets = $othersBullets.toArray().map(b => $(b).children('span').length);
+
+ // If there is an exceeding span element, use it as current slide descriptor
+ if (spanCountInOthersBullets.every(count => count < spans.length)) {
+ activeStateDescriptor = spans.last();
+ activeStateDescriptor.attr('data-slide-active-label', '');
+ }
}
+ // Move the current slide descriptor to the new slide button
+ if (activeStateDescriptor.length) {
+ activeStateDescriptor.detach();
+ $newBullet.append(activeStateDescriptor);
+ }
}
/**