User:Majr/twitterFeed.js

$( function { 'use strict';

var $feeds = $( '.twitter-feed' ); var pre = 'twitter-feed-tweet-';

if ( $feeds.length ) { $feeds.html( '' ); $feeds.each( function {       var $names = $feeds.data( 'names' ).split( ' ' );        var $count = $feeds.data( 'count' );        $.each( $names, function { $.getJSON(               'https://api.twitter.com/1/statuses/user_timeline.json?include_entities=1&screen_name=' + this + '&count=' + $count + '&callback=?',                function( resp ) { parseTweets( resp ); }            ); } );   } ); } else { return false; }

function parseTweets( tweets ) { $.each( tweets, function {       console.log (this);        var tweet = {};        tweet.name = this.user.screen_name;        tweet.fullName = this.user.name;        tweet.avatar = this.user.profile_image_url_https;        tweet.linkColour = this.user.profile_link_color;        tweet.date = this.created_at;        tweet.id = this.id_str;        tweet.text = this.text;        tweet.source = this.source;        tweet.urls = {};        tweet.mentions = {};        tweet.hashtags = {};        var iu = -1;        if ( this.entities.urls.length ) {            $.each ( this.entities.urls, function( iu ) { tweet.urls[iu] = {}; tweet.urls[iu].short = this.url; tweet.urls[iu].real = this.expanded_url; tweet.urls[iu].display = this.display_url; } );       }        if ( typeof this.entities.media === 'undefined' ) {            this.entities.media = '';        } else {            if ( this.entities.media.length ) {                iu++;                console.log(this.entities);                $.each ( this.entities.media, function( i ) { i = i + iu; tweet.urls[i] = {}; tweet.urls[i].short = this.url; tweet.urls[i].real = this.expanded_url; tweet.urls[i].display = this.display_url; } );           }        }        if ( this.entities.user_mentions.length ) {            $.each ( this.entities.user_mentions, function( i ) { tweet.mentions[i] = this.screen_name; } );       }        if ( this.entities.hashtags.length ) {            $.each ( this.entities.hashtags, function( i ) { tweet.mentions[i] = this.text; } );       }        displayTweet( tweet );    } ); }

function displayTweet( tweet ) { $feeds.append(        '\n' +            '\t\n' +                '\t\t ' + tweet.fullName + ' @ ' + tweet.name + ' \n' +            '\t \n' +            '\t' + tweet.text + ' \n' +            '\t' + tweet.date + ' via ' + tweet.source + ' \n' +        ' \n'    ); }

} );