Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-03-2011, 05:45 PM   PM User | #1
vyp0r
New Coder

 
Join Date: May 2007
Posts: 16
Thanks: 2
Thanked 1 Time in 1 Post
vyp0r is an unknown quantity at this point
How to truncate and add ellipsis

Hi,

You'll have to forgive me. I'm still pretty much a beginner when it come to js and jQuery, so bare with me please.

I'm trying to embed a tumblr blog into a website using the following code:
Code:
<script type="text/javascript">
function tumblr(resp) {
	var posts = resp.posts;
	$('.blog .loading').replaceWith('<ul class="blogcontent"/>');
	$ul = $('.blog ul');
	for (var i=0; i<posts.length; i++) {
		var p = posts[i];
				var date = p['date'];
                var title = p['regular-title'] || p['link-text'] || null;
				var body = p['regular-body'];
		if (date)
			$ul.append('<li><h1>'+date+'</h1>');
		if (title)
			$ul.append('<a href="'+p['url']+'" target="_blank"> <h2>'+title+'</h2></a>');
		if (body)
			$ul.append('<a href="'+p['url']+'" target="_blank"> <p>'+body+'</p> </a></li>');
	}
}
</script>
The posts are displayed no problem. But this is where I get lost. If the 'body' copy is longer than, let's say, 30 words (which all of the posts are), I'd like it to be truncated and replaced with '... Read more >" You get the idea.

I've found a few examples online (unrelated to tumblr embedding) but the code is so detailed and interwoven, and me being the newbie that I am, I don't know which bits I need and which I don't.

Could someone point me in the right direction, given the code that I already have?

Any help is greatly appreciated. Thanks.
vyp0r is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:44 PM.


Advertisement
Log in to turn off these ads.