From 18ad4b4bac2bfd97d1feb0831929190bcaa9fbe5 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Sat, 4 Aug 2018 23:47:20 +0200 Subject: [PATCH] feat: use the "exceeding" span instead of the last one for Orbit current slide descriptor --- js/foundation.orbit.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/js/foundation.orbit.js b/js/foundation.orbit.js index bfcf1ab08..730f68c26 100644 --- a/js/foundation.orbit.js +++ b/js/foundation.orbit.js @@ -378,22 +378,41 @@ class Orbit extends Plugin { /** * 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); + } } /** -- 2.47.2