Guest User

Untitled

a guest
Nov 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($){
  2.  
  3.       var items;
  4.       var settings;
  5.       var firstIndex;
  6.       var lastIndex;
  7.       var currentIndex;
  8.      
  9.       var self = this;
  10.       var tempMap;
  11.       var firstSlide = true;
  12.       var cssObj;
  13.    
  14.       var methods = {
  15.         init : function( options ) {
  16.             var settings = $.extend( {
  17.                 'firstIndex'         : 0,
  18.                 'duration'           : 5000,
  19.                 'cssPath'            : 'css/slider.css',
  20.             }, options);
  21.            
  22.             self.settings = settings;
  23.             self.items = $(this).children();
  24.             self.tempMap = {};
  25.            
  26.             var cssObj;
  27.             $.get(self.settings.cssPath, function(cssContent){
  28.                 $.parsecss(cssContent, function(css){
  29.                     cssObj = css;
  30.                 });
  31.             });
  32.             console.log(cssObj);
  33.            
  34.            
  35.            
  36.             methods.createMap();
  37.             methods.slideElement();
  38.            
  39.         },
  40.        
  41.         parseCss : function(cssContent){
  42.             $.parsecss(cssContent, methods.setCssObj);
  43.         },
  44.        
  45.         setCssObj : function(css){
  46.             self.cssObj = 'asd';
  47.         },
  48.        
  49.         createMap : function() {
  50.           self.firstIndex = self.settings.firstIndex;
  51.           self.currentIndex = self.settings.firstIndex;
  52.           self.lastIndex = self.items.length;
  53.         },
  54.        
  55.         slideElement : function( ) {
  56.            
  57.                 if(self.currentIndex == self.lastIndex )
  58.                     self.currentIndex = self.firstIndex;
  59.  
  60.                 self.items.eq(self.currentIndex).css('z-index', 1);
  61.                 self.items.eq(self.currentIndex - 1).css('z-index', 2);
  62.                
  63.                 self.items.eq(self.currentIndex).children().each(function(index) {
  64.                    
  65.                     if(self.tempMap[self.currentIndex + '-' + index + 'animate-in'] == undefined){
  66.                         var tempElement = $(this).clone();
  67.                         tempElement.addClass('animate-in');
  68.                         self.tempMap[self.currentIndex + '-' + index + 'animate-in'] = tempElement;
  69.                     }
  70.  
  71.                     if(self.tempMap[self.currentIndex + '-' + index + 'animate-out'] == undefined){
  72.                         var tempElement = $(this).clone();
  73.                         tempElement.addClass('animate-out');
  74.                         self.tempMap[self.currentIndex + '-' + index + 'animate-out'] = tempElement;
  75.                     }
  76.  
  77.                     var delay = parseInt(self.tempMap[self.currentIndex + '-' + index + 'animate-in'].css('transition-duration')) * 1000;
  78.  
  79.                     className = '.'+$(this).attr('class').replace(' ', '.');
  80.                    
  81.  
  82.                    
  83.                     //console.log(self.cssObj);
  84.                    
  85.                     $(this).removeClass('animate-in');
  86.                     $(this).removeClass('animate-out');
  87.                     $(this).css('transition-duration', '0s');
  88.                     $(this).addClass('animate-in', delay);
  89.                 });
  90.    
  91.                 if(self.firstSlide == false){
  92.                    
  93.                     var animateOutIndex = self.currentIndex == 0 ? self.lastIndex - 1 : self.currentIndex - 1;
  94.                    
  95.                     self.items.eq(animateOutIndex).children().each(function(index) {
  96.                        
  97.                         var delay = parseInt(self.tempMap[animateOutIndex + '-' + index + 'animate-out'].css('transition-duration')) * 1000;
  98.                        
  99.                         $(this).css('transition-duration', '0s');
  100.                         $(this).addClass('animate-out', delay);
  101.                     });
  102.                 }
  103.                    
  104.                
  105.                 self.currentIndex++;
  106.                 self.firstSlide = false;
  107.                 var p = setTimeout ( methods.slideElement, self.settings.duration );
  108.                
  109.         },
  110.        
  111.       };
  112.  
  113.       $.fn.cssSlider = function( method ) {
  114.         if ( methods[method] ) {
  115.           return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  116.         } else if ( typeof method === 'object' || ! method ) {
  117.           return methods.init.apply( this, arguments );
  118.         } else {
  119.           $.error( 'Method ' +  method + ' does not exist on jQuery.cssSlider' );
  120.         }    
  121.      
  122.       };
  123.  
  124. })(jQuery);
Add Comment
Please, Sign In to add comment