Return to Snippet

Revision: 16044
at July 24, 2009 04:41 by jonniespratley


Initial Code
/**
 * I take a string and create an excerpt from it, returning an object
 * with the summary and body properties,
 * @param {Object} str - the string to shorten
 * @param {Object} limit - the limit of characters
 */
function jps_shortString( str, limit )
{
	var body = new String( str );
	var summary = new String(str);
		summary = summary.substr( 0, summary.lastIndexOf( ' ', limit ) ) + '...';
	
	var returnString = new Object({
		body: body,
		summary: summary
	});
	
	//window.console.log( 'Summary - ' + summary);
	//window.console.log( 'Body - ' + body);
	
	return returnString;
}

Initial URL

                                

Initial Description

                                

Initial Title
JavaScript - Create excerpt

Initial Tags
text

Initial Language
JavaScript