Advertisement
Guest User

Untitled

a guest
May 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($){
  2.     $(document).ready(function()    {
  3.         //-------------------------
  4.         // init
  5.         //-------------------------
  6.         if(!$('.mod-showcase').length) return;
  7.         mods = $('.mod-showcase');
  8.         var modsLength = mods.length;
  9.         var modsParent = mods.parent();
  10.         var modActive = 0;
  11.        
  12.         // prepare
  13.         mods.hide();
  14.         mods.eq(0)
  15.             .show()
  16.             .addClass('active');
  17.         modActive = 0;
  18.        
  19.         // update all mods excerpts
  20.         $('.mod-showcase').each(function(){
  21.             updateExcerpt($(this));
  22.         });
  23.        
  24.        
  25.         //-------------------------
  26.         // events
  27.         //-------------------------
  28.        
  29.         // carousel slid
  30.         $('.mod-showcase .carousel').on('slid', function(){
  31.             var This = $(this);
  32.             setTimeout(function() {
  33.                 updateExcerpt(This.closest('.mod-showcase'));
  34.             }, 100);
  35.         });
  36.        
  37.         // carousel controls click
  38.         mods.find('.carousel-control').click(function(event){
  39.             var carousel = $(this).closest('.carousel');
  40.             var itemsLength = carousel.find('.item').length-1;
  41.             var itemActive = carousel.find('.item.active').index();
  42.            
  43.             if($(this).hasClass('left')){
  44.                 if(itemActive === 0){
  45.                     cycle('prev');
  46.                 }
  47.             }
  48.             if($(this).hasClass('right')){
  49.                 if(itemActive === (itemsLength)){
  50.                     cycle('next');
  51.                 }
  52.             }
  53.         });
  54.        
  55.  
  56.         //-------------------------
  57.         // functions
  58.         //-------------------------
  59.        
  60.         // update the excerpt using active item
  61.         function updateExcerpt(mod){
  62.             var excerpt = mod.find('.carousel-indicators .active .item-exceprt').text();
  63.             var link = mod.find('.carousel-indicators .active .item-link').attr('href');
  64.             mod.find('.excerpt .item-excerpt').text(excerpt);
  65.             mod.find('.excerpt .item-link').attr('href', link);
  66.         }
  67.        
  68.         // cycle active module
  69.         function cycle(direction){
  70.             var modActiveOld;
  71.             if(modsLength > 1){
  72.                 modActiveOld = modActive;
  73.                 // set active index
  74.                 if(direction === "next"){
  75.                     modActive++;
  76.                 }else if(direction === "prev"){
  77.                     modActive--;
  78.                 }
  79.                 if(modActive >= modsLength){
  80.                     modActive = 0;
  81.                 }else if(modActive < 0){
  82.                     modActive = modsLength-1;
  83.                 }
  84.                 mods.removeClass('active');
  85.                 mods.eq(modActive).addClass('active');
  86.                 // set carousel slide
  87.                 if(direction === "next"){
  88.                     mods.each(function(){
  89.                         if($(this).index() === mods.eq(modActive)) return true;
  90.                         //$(this).carousel(0);
  91.                     });
  92.                 }else if(direction === "prev"){
  93.                     mods.each(function(){
  94.                         if($(this).index() === mods.eq(modActive)) return true;
  95.                         var n = $(this).find('.item').length-1;
  96.                         //$(this).carousel(n);
  97.                     });
  98.                 }
  99.                 console.log(55);
  100.                 // transition
  101.                 mods.eq(modActiveOld).fadeOut(
  102.                     100,
  103.                     function(){
  104.                         mods.eq(modActive).fadeIn(500);
  105.                     }
  106.                 )
  107.             }
  108.         }
  109.        
  110.  
  111.     });
  112. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement