]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
feat: use the "exceeding" span instead of the last one for Orbit current slide descriptor
authorNicolas Coden <nicolas@ncoden.fr>
Sat, 4 Aug 2018 21:47:20 +0000 (23:47 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 4 Aug 2018 21:47:20 +0000 (23:47 +0200)
js/foundation.orbit.js

index bfcf1ab08c36167d80e126057a01734af0d180a0..730f68c26902b159bfaede30aaedd2ff32ded2e4 100644 (file)
@@ -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);
+    }
   }
 
   /**