Advertisement
Guenni007

headline_rotator

Sep 13th, 2022 (edited)
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($)
  2. {
  3.     "use strict";
  4.  
  5.     // -------------------------------------------------------------------------------------------
  6.     // Avia Text Rotator
  7.     // Guenni007 : new area for only one circle 68ff and 128ff
  8.     // accordion slider script
  9.     // -------------------------------------------------------------------------------------------
  10.  
  11.     $.AviaTextRotator  =  function(options, slider)
  12.     {
  13.         this.$win       = $( window );
  14.         this.$slider    = $( slider );
  15.         this.$inner     = this.$slider.find('.av-rotator-text');
  16.         this.$slides    = this.$inner.find('.av-rotator-text-single');
  17.         this.$current   = this.$slides.eq(0);
  18.         this.open       = 0;
  19.         this.count      = this.$slides.length;
  20.  
  21.         if($.avia_utilities.supported.transition === undefined)
  22.         {
  23.             $.avia_utilities.supported.transition = $.avia_utilities.supports('transition');
  24.         }
  25.  
  26.         this.browserPrefix  = $.avia_utilities.supported.transition;
  27.         this.cssActive      = this.browserPrefix !== false ? true : false;
  28.         this.property       = this.browserPrefix + 'transform',
  29.  
  30.         //this.cssActive    = false; //testing no css3 browser
  31.  
  32.         this._init( options );
  33.     }
  34.  
  35.     $.AviaTextRotator.prototype =
  36.     {
  37.         _init: function( options )
  38.         {
  39.             var _self = this;
  40.  
  41.             if(this.count <= 1) return;
  42.  
  43.             _self.options = $.extend({}, options, this.$slider.data());
  44.             _self.$inner.addClass('av-rotation-active');
  45.             //if(_self.options.fixwidth == 1) this.$inner.width(this.$current.width());
  46.             _self._autoplay();
  47.  
  48.             if(_self.options.animation == "typewriter")
  49.             {
  50.                 _self.$slider.addClass('av-caret av-blinking-caret');
  51.             }
  52.  
  53.         },
  54.  
  55.         _autoplay: function()
  56.         {
  57.             var _self = this;
  58.  
  59.             _self.autoplay = setTimeout(function()
  60.             {
  61.                 _self.open = _self.open === false ? 0 : _self.open + 1;
  62.                 if(_self.open >= _self.count) _self.open = 0;
  63.  
  64.                 if(_self.options.animation != "typewriter")
  65.                 {
  66.                     _self._move({}, _self.open);
  67.                     _self._autoplay();
  68. // this is the new area to stop after one circle if the custom class is set: once
  69.                     if(  (_self.open == _self.count - 1) && (_self.$slider.hasClass('once')) ){
  70.                         clearInterval(_self.autoplay);
  71.                     }
  72.                 }
  73.                 else
  74.                 {
  75.                     _self._typewriter();
  76.                 }
  77.  
  78.             }, _self.options.interval * 1000);
  79.         },
  80.  
  81.         _typewriter: function(event)
  82.         {
  83.             var _self = this;
  84.  
  85.             //mark text
  86.             _self.$current.css('background-color', _self.$current.css('color') );
  87.             _self.$slider.removeClass('av-caret av-blinking-caret').addClass('av-marked-text');
  88.  
  89.  
  90.             //store and hide text
  91.             setTimeout(function()
  92.             {
  93.                 _self.$slider.addClass('av-caret av-blinking-caret').removeClass('av-marked-text');
  94.                 _self.$current.data('av_typewriter_text', _self.$current.html());
  95.                 _self.$current.css('background-color', 'transparent');
  96.                 _self.$current.html("");
  97.  
  98.             }, 800 );
  99.  
  100.  
  101.             //start typing new text
  102.             setTimeout(function()
  103.             {
  104.                 _self.$slider.removeClass('av-blinking-caret');
  105.                 _self.$next = _self.$slides.eq(_self.open);
  106.                 var content = _self.$next.data('av_typewriter_text') || _self.$next.html();
  107.             content = content.replace(/&amp;/g, '&');
  108.  
  109.                 _self.$current.css({display:'none'});
  110.                 _self.$next.css({display:'inline'});
  111.                 _self.$next.html("");
  112.  
  113.                 var i = 0;
  114.                 var speed = 50; /* The speed/duration of the effect in milliseconds */
  115.  
  116.                 function typeWriter() {
  117.  
  118.                   if (i < content.length) {
  119.                     _self.$next[0].innerHTML += content.charAt(i);
  120.                     i++;
  121.                     setTimeout(typeWriter, speed + Math.floor(Math.random() * 100 ) );
  122.                   }
  123.                   else
  124.                   {
  125.                         _self.$slider.addClass('av-caret av-blinking-caret');
  126.                         _self.$current = _self.$slides.eq(_self.open);
  127.                         _self._autoplay();
  128. // this is the new area to stop after one circle if the custom class is set: once
  129.                         if(  (_self.open == _self.count - 1) && (_self.$slider.hasClass('once')) ){
  130.                             _self.$slider.removeClass('av-caret av-blinking-caret');
  131.                             clearInterval(_self.autoplay);
  132.                         }
  133.                   }
  134.  
  135.                 }
  136.  
  137.                 typeWriter();
  138.  
  139.             }, 1500 );
  140.         },
  141.  
  142.         _move: function(event)
  143.         {
  144.             var _self       = this,
  145.                 modifier    = 30 * _self.options.animation,
  146.                 fade_out    = {opacity:0},
  147.                 fade_start  = {display:'inline-block', opacity:0},
  148.                 fade_in     = {opacity:1};
  149.  
  150.             this.$next = _self.$slides.eq(this.open);
  151.  
  152.             if(this.cssActive)
  153.             {
  154.                 fade_out[_self.property]    = "translate(0px," + modifier +"px)";
  155.                 fade_start[_self.property]  = "translate(0px," + (modifier * -1) +"px)";
  156.                 fade_in[_self.property]     = "translate(0px,0px)";
  157.             }
  158.             else
  159.             {
  160.                 fade_out['top']     = modifier;
  161.                 fade_start['top']   = (modifier * -1);
  162.                 fade_in['top']      = 0;
  163.             }
  164.  
  165.  
  166.             _self.$current.avia_animate(fade_out, function()
  167.             {
  168.                 _self.$current.css({display:'none'});
  169.                 _self.$next.css(fade_start).avia_animate(fade_in, function()
  170.                 {
  171.                     _self.$current = _self.$slides.eq(_self.open);
  172.                 });
  173.             });
  174.         }
  175.     };
  176.  
  177.  
  178.     $.fn.avia_textrotator = function( options )
  179.     {
  180.         return this.each(function()
  181.         {
  182.             var active = $.data( this, 'AviaTextRotator' );
  183.  
  184.             if(!active)
  185.             {
  186.                 //make sure that the function doesnt get aplied a second time
  187.                 $.data( this, 'AviaTextRotator', 1 );
  188.  
  189.                 //create the preparations for fullscreen slider
  190.                 new $.AviaTextRotator( options, this );
  191.             }
  192.         });
  193.     };
  194.  
  195. }(jQuery));
  196.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement