JSFiddle - React, Tailwind, and code Playground

by gabrieleromanato

HTML

<div id="twitter"></div>

CSS

div.tweet {
    padding: 1em;
    background: #ddd;
    margin: 1em;
    border-radius: 6px;
    box-shadow: 1px 1px 2px #aaa;
    width: 300px;
}

p {
    margin: 0;
}

small {
    display: block;
    margin: 5px 0;
}

a {
    text-decoration: none;
    color: #444;
}

a:hover {
    text-decoration: underline;
}

JavaScript

(function($) {

    $.fn.searchTwitter = function(options) {
    
        var that = this;
        
        var settings = {
        
            term: '',
            limit: 3
        
        };
        
        options = $.extend(settings, options);
        
        var Search = new function() {
        
            var url = 'http://search.twitter.com/search.json?callback=?&q=' + options.term;
            var html = '';
            
    
        // PrettyDate by John Resig. 
    
        var prettyDate = function(time) {
        
        var date = new Date((time || "").replace(/-/g,"/").replace(/TZ/g," ")),
            diff = (((new Date()).getTime() - date.getTime()) / 1000),
            day_diff = Math.floor(diff / 86400);
                
        if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
            return;
        var v = day_diff == 0 && (
                diff < 60 && "now" ||
                diff < 120 && "1 minute ago" ||
                diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
                diff < 7200 && "1 hour ago" ||
                diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
            day_diff == 1 && "yesterday" ||
            day_diff < 7 && day_diff + " days ago" ||
            day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago";
        if (!v)
            window.console && console.log(time);
        return v ? v : '';
        }
        
        var formatTweet = function(text) {
        
            var tweet = '';
            
            tweet = text.replace(/(http:\/\/\S+)/g, '<a href="$1">$1</a>');
            tweet = tweet.replace(/\@(\w+)/g, '<a href="http://twitter.com/$1">@$1</a>');
            
            return tweet;
        
        };

            
          this.run = function() {
            
                
            
                $.getJSON(url, function(data) {
                
                
                    $.each(data.results, function(i, item) {
   ...