Skip to content

Instantly share code, notes, and snippets.

@arnaudbreton
Created May 30, 2014 09:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudbreton/748c03a1948a62ab680f to your computer and use it in GitHub Desktop.
Save arnaudbreton/748c03a1948a62ab680f to your computer and use it in GitHub Desktop.
Mention tweet feed
/*
*---------------------------------------------------------------
* Twitter
*---------------------------------------------------------------
*/
(function($, undefined){
"use strict";
var MentionApp = MentionApp || {};
// Class
MentionApp.twitter = function( elem, options ) {
this.el = elem;
this.$el = $(elem);
this.init( options );
};
MentionApp.twitter.prototype = {
defaults: {
speed: 700,
easing: 'ease',
interval: 6000,
itemClass: '.tweet',
log: true
},
init: function( options ) {
this.config = $.extend({}, this.defaults, options);
this._config();
this.setTransition();
this.startRotator();
return this;
},
_config: function() {
this.$items = this.$el.find( this.config.itemClass );
this.itemsCount = this.$items.length;
this.$progress = this.$el.find('#progress');
this.current = 0;
},
setTransition: function() {
setTimeout( $.proxy( function() {
this.$items.css( 'transition', 'opacity ' + this.config.speed + 'ms ' + this.config.easing );
}, this ), 25 );
},
startRotator: function() {
this.startProgress();
setTimeout( $.proxy( function() {
this.resetProgress();
this.next();
this.startRotator();
}, this ), this.config.interval );
},
next: function() {
// Remove .active = opacity 0
this.$items.eq( this.current ).removeClass('active');
this.current = this.current < this.itemsCount - 1 ? this.current + 1 : 0;
// Show next items
this.$items.eq( this.current ).addClass('active');
},
startProgress: function() {
setTimeout( $.proxy(function() {
this.$progress.css( { transition : 'width ' + this.config.interval + 'ms linear', width : '100%' } );
}, this), 25);
},
resetProgress: function() {
this.$progress.css({ transition: 'none', width: '0%' });
},
log: function(message, type) {
if( ! this.config.log ) return;
if( type == undefined ) type = 'Infos';
console.log( type + ' : ' + message );
}
}
// end class //
// Config
var twitterOptions = {}
// Create a new jQuery plugin
$.fn.letsTweetThis = function( options ) {
return this.each(function() {
new MentionApp.twitter(this, twitterOptions);
});
};
// Init jQuery plugin
$('div#tweets').letsTweetThis();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment