-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2431 from samvera/i189-institutional-repository-c…
…arousel I189 institutional repository carousel
- Loading branch information
Showing
3 changed files
with
105 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,57 @@ | ||
// jQuery Slider | ||
$(document).on('turbolinks:load', function() { | ||
$('.institutional-repository-carousel .carousel-item').each(function(){ | ||
var itemToClone = $(this); | ||
|
||
for (var i = 1; i < 6; i++) { | ||
itemToClone = itemToClone.next(); | ||
|
||
// wrap around if at end of item collection | ||
if (!itemToClone.length) { | ||
itemToClone = $(this).siblings(':first'); | ||
} | ||
|
||
// grab item, clone, add marker class, add to collection | ||
itemToClone.children(':first-child').clone() | ||
.addClass("cloneditem-"+(i)) | ||
.appendTo($(this)); | ||
// Handles the infinite scrolling of the resource icons in the resource_type_slider | ||
|
||
let scrollPosition = 0; | ||
|
||
$(document).on('turbolinks:load', function initializeCarousel() { | ||
const $resourceRow = $('.resource-row'); | ||
const $item = $resourceRow.children(); | ||
const resourceItemWidth = $('.resource-item').width() + 10; // 10px margin | ||
|
||
// Clone first and last items for infinite scrolling | ||
const $clonesBefore = $item.slice(-6).clone(); | ||
const $clonesAfter = $item.slice(0, 6).clone(); | ||
|
||
$resourceRow.prepend($clonesBefore).append($clonesAfter); | ||
|
||
// Adjust the initial scroll position | ||
scrollPosition = 6 * resourceItemWidth; | ||
$resourceRow.css('transform', `translateX(-${scrollPosition}px)`); | ||
}) | ||
|
||
function scrollResources(direction) { | ||
const $resourceRow = $('.resource-row'); | ||
const totalItems = $resourceRow.children().length; | ||
const resourceItemWidth = $('.resource-item').width() + 10; // 10px margin | ||
|
||
if (direction === 'previous') { | ||
scrollPosition -= resourceItemWidth; | ||
} else if (direction === 'next') { | ||
scrollPosition += resourceItemWidth; | ||
} | ||
|
||
$resourceRow.css({ | ||
transition: 'transform 0.3s ease', | ||
transform: `translateX(-${scrollPosition}px)` | ||
}); | ||
|
||
// Handle looping after the transition | ||
$resourceRow.on('transitionend', function () { | ||
if (scrollPosition < 6 * resourceItemWidth) { | ||
// Reset to the original items at the end of the array | ||
scrollPosition += (totalItems - 12) * resourceItemWidth; | ||
$resourceRow.css({ | ||
transition: 'none', | ||
transform: `translateX(-${scrollPosition}px)` | ||
}); | ||
} else if (scrollPosition >= (totalItems - 6) * resourceItemWidth) { | ||
// Reset to the original items at the beginning of the array | ||
scrollPosition -= (totalItems - 12) * resourceItemWidth; | ||
$resourceRow.css({ | ||
transition: 'none', | ||
transform: `translateX(-${scrollPosition}px)` | ||
}); | ||
} | ||
// Remove the transitionend listener after execution | ||
$resourceRow.off('transitionend'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters