1(function ($, Drupal) { 2 Drupal.behaviors.btsParagraphSlider = { 3 attach: function (context, settings) { 4 var carouselInner = $('.carousel-inner', context); 5 6 if (carouselInner.length) { 7 var isFrontPage = $('body').hasClass('path-frontpage'); 8 9 carouselInner.each(function() { 10 var $this = $(this); 11 12 if (isFrontPage) { 13 var indicators = $this.closest('.carousel').find('.carousel-indicators'); 14 var items = $this.children('.item'); 15 16 // Fisher-Yates shuffle algorithm 17 function shuffle(array) { 18 for (let i = array.length - 1; i > 0; i--) { 19 const j = Math.floor(Math.random() * (i + 1)); 20 [array[i], array[j]] = [array[j], array[i]]; 21 } 22 return array; 23 } 24 25 // Shuffle the items 26 var shuffledItems = shuffle(items.get()); 27 28 // Clear current items 29 $this.empty(); 30 indicators.empty(); 31 32 // Re-add the shuffled items 33 $(shuffledItems).each(function(index) { 34 if (index === 0) { 35 $(this).addClass('active'); 36 } else { 37 $(this).removeClass('active'); 38 } 39 $this.append(this); 40 41 // Update indicators 42 var indicator = $('<li>') 43 .attr('data-target', '#' + $this.closest('.carousel').attr('id')) 44 .attr('data-slide-to', index); 45 if (index === 0) { 46 indicator.addClass('active'); 47 } 48 indicators.append(indicator); 49 }); 50 } 51 52 // Immediately remove the overlay by adding the 'carousel-loaded' class 53 $this.closest('.carousel').addClass('carousel-loaded'); 54 }); 55 } 56 } 57 }; 58 })(jQuery, Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.