/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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; }