/*! * jQuery Lifestream Plug-in * Show a stream of your online activity * @version 0.5.5 * @author Christian Vuerings et al. * @copyright Copyright 2014, Christian Vuerings - http://denbuzze.com * @license https://github.com/christianvuerings/jquery-lifestream/blob/master/LICENSE MIT */ /*global jQuery */ ;(function( $ ){ "use strict"; /** * Initialize the lifestream plug-in * @param {Object} config Configuration object */ $.fn.lifestream = function( config ) { // Make the plug-in chainable return this.each(function() { // The element where the lifestream is linked to var outputElement = $(this), // Extend the default settings with the values passed settings = jQuery.extend({ // The name of the main lifestream class // We use this for the main ul class e.g. lifestream // and for the specific feeds e.g. lifestream-twitter classname: "lifestream", // Callback function which will be triggered when a feed is loaded feedloaded: null, // The amount of feed items you want to show limit: 10, // An array of feed items which you want to use list: [] }, config), // The data object contains all the feed items data = { count: settings.list.length, items: [] }, // We use the item settings to pass the global settings variable to // every feed itemsettings = jQuery.extend( true, {}, settings ), /** * This method will be called every time a feed is loaded. This means * that several DOM changes will occur. We did this because otherwise it * takes to look before anything shows up. * We allow 1 request per feed - so 1 DOM change per feed * @private * @param {Array} inputdata an array containing all the feeditems for a * specific feed. */ finished = function( inputdata ) { // Merge the feed items we have from other feeds, with the feeditems // from the new feed $.merge( data.items, inputdata ); // Sort the feeditems by date - we want the most recent one first data.items.sort( function( a, b ) { return ( b.date - a.date ); }); var items = data.items, // We need to check whether the amount of current feed items is // smaller than the main limit. This parameter will be used in the // for loop length = ( items.length < settings.limit ) ? items.length : settings.limit, i = 0, item, // We create an unordered list which will create all the feed // items ul = $('