Sha256: dc804198fb3c61f0dc6a23d67e09f67e7d0bb50df960d19dde9d84056f782f82

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

(function ($) {
  'use strict';
  $.fn.pusherTextCycler = function(options) {

    var self = this;

    self._ = 'pusherTextCycler';

    self.defaults = {
      speed: 100,
      typingSpeed: 50,
      delayBeforeErase: 3000,
      class: 'cycle',
      backgroundColor: '#f7f7f7',
      highlightColor: '#b4d5fe'
    }

    self.$context = self;
    self.options = {};
    self.options = $.extend({}, self.defaults, options);

    self.init = function() {
      self.caption = self.options.text[0];
      self.captionLength = 0;
      self.options.text.push(self.options.text.shift());
      
      self.type();
    }
    
    self.type = function() {
      self.$context.html(self.caption.substr(0, self.captionLength++)).css({'background-color':self.options.backgroundColor});
      
      if(self.captionLength < self.caption.length+1) {
        setTimeout(function() {
          self.type();
        }, self.options.typingSpeed);
      } else {        
        setTimeout(function() {
          self.erase();
        }, self.options.delayBeforeErase);
      }
    }
    
    self.erase = function() {
      self.$context.css({'background-color': self.options.highlightColor});
      setTimeout(function() {
        self.$context.html(self.caption.substr(0, 0));
        self.captionLength = 0;
        self.caption = '';
      }, 500);
      
      setTimeout(function() {
        self.init();
      }, 600);
    }

    return self.init();
  }

})(jQuery);

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
pusher-chameleon-1.4.6 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.4.5 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.4.4 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.4.3 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.4.2 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.4.1 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.4.0 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.3.0 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.2.1 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.2.0 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.1.0 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.0.4 javascripts/chameleon/pusher_text_cycler.js
pusher-chameleon-1.0.3 javascripts/chameleon/pusher_text_cycler.js
pusher_chameleon-1.0.3 javascripts/chameleon/pusher_text_cycler.js
pusher_chameleon-1.0.2 javascripts/chameleon/pusher_text_cycler.js
pusher_chameleon-1.0.0 javascripts/chameleon/pusher_text_cycler.js