Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HTML
<div id="posts"><img src="http://dev.trgiman.eu/dev/download/attachments/4620293/ajax-loader.gif" /></div>

<script>

(function( $ ){
	$.extend( {
		jTwitter: function( username, numPosts, fnk ) {
			var info = {};

			// If no arguments are sent or only username is set
			if( username == 'undefined' || numPosts == 'undefined' ) {
				return;
			} else if( $.isFunction( numPosts ) ) {
				// If only username and callback function is set
				fnk = numPosts;
				numPosts = 5;
			}

			var url = "http://twitter.com/status/user_timeline/"
				+ username + ".json?count="+numPosts+"&callback=?";

			$.getJSON( url, function( data ){
				if( $.isFunction( fnk ) ) {
					fnk.call( this, data );
				}
			});
		}
	});
})( jQuery );

function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href='$1'>$1</a>");
}


$(document).ready(function(){
    $.jTwitter('BellaDati', 8, function(data){
        $('#posts').empty();
        $('#posts').addClass("postsComplete");
        $.each(data, function(i, post){
            $('#posts').append(
                '<div class="twitterPost">'
                +    replaceURLWithHTMLLinks(post.text)
                +'</div>'
            );
        });
    });


var stamp = new Date().getTime();
    $.getJSON('http://www.local.cz:8080/BellaDati-website/blog:jsonFeed?count=10&stamp='+stamp+'&callback=?',function() {});

});


function blogPostCallback(data) {
 $('#blog').empty();
 $('#blog').addClass("blogComplete");
	 $.each(data, function(i, post){
          $('#blog').append(
                '<div class="blogPost"><div class="blogPostTitle"><a href="'+post.url+'">'
                +    post.title
                +'</a></div>'+
                  '<div class="blogPostContent">'+post.short+'</div>'+
                  '<img src="'+post.image+'" />'+
                  '</div>'
            );

});
}


</script>
<style>
.twitterPost {
margin-bottom: 5px;
padding-bottom: 5px;
border-bottom: 1px solid silver;
}
</style>

...