Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- $(document).ready(function() {
- //-------------------------
- // init
- //-------------------------
- if(!$('.mod-showcase').length) return;
- mods = $('.mod-showcase');
- var modsLength = mods.length;
- var modsParent = mods.parent();
- var modActive = 0;
- // prepare
- mods.hide();
- mods.eq(0)
- .show()
- .addClass('active');
- modActive = 0;
- // update all mods excerpts
- $('.mod-showcase').each(function(){
- updateExcerpt($(this));
- });
- //-------------------------
- // events
- //-------------------------
- // carousel slid
- $('.mod-showcase .carousel').on('slid', function(){
- var This = $(this);
- setTimeout(function() {
- updateExcerpt(This.closest('.mod-showcase'));
- }, 100);
- });
- // carousel controls click
- mods.find('.carousel-control').click(function(event){
- var carousel = $(this).closest('.carousel');
- var itemsLength = carousel.find('.item').length-1;
- var itemActive = carousel.find('.item.active').index();
- if($(this).hasClass('left')){
- if(itemActive === 0){
- cycle('prev');
- }
- }
- if($(this).hasClass('right')){
- if(itemActive === (itemsLength)){
- cycle('next');
- }
- }
- });
- //-------------------------
- // functions
- //-------------------------
- // update the excerpt using active item
- function updateExcerpt(mod){
- var excerpt = mod.find('.carousel-indicators .active .item-exceprt').text();
- var link = mod.find('.carousel-indicators .active .item-link').attr('href');
- mod.find('.excerpt .item-excerpt').text(excerpt);
- mod.find('.excerpt .item-link').attr('href', link);
- }
- // cycle active module
- function cycle(direction){
- var modActiveOld;
- if(modsLength > 1){
- modActiveOld = modActive;
- // set active index
- if(direction === "next"){
- modActive++;
- }else if(direction === "prev"){
- modActive--;
- }
- if(modActive >= modsLength){
- modActive = 0;
- }else if(modActive < 0){
- modActive = modsLength-1;
- }
- mods.removeClass('active');
- mods.eq(modActive).addClass('active');
- // set carousel slide
- if(direction === "next"){
- mods.each(function(){
- if($(this).index() === mods.eq(modActive)) return true;
- //$(this).carousel(0);
- });
- }else if(direction === "prev"){
- mods.each(function(){
- if($(this).index() === mods.eq(modActive)) return true;
- var n = $(this).find('.item').length-1;
- //$(this).carousel(n);
- });
- }
- console.log(55);
- // transition
- mods.eq(modActiveOld).fadeOut(
- 100,
- function(){
- mods.eq(modActive).fadeIn(500);
- }
- )
- }
- }
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement