Created
May 17, 2017 11:51
-
-
Save kmcconnell/1e4772bf02c5c0f8f3b47712db573749 to your computer and use it in GitHub Desktop.
Truncate long text within a span.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Truncate long text within a span. Hover over span to see full text. | |
* | |
* @param {string} data The text content to include between span elements if longer | |
* than the specified maximum characters. | |
* @param {integer} chars The maximum number of characters before truncating with an | |
* ellipse. | |
* | |
* @return {string} The ellipsed span with the full text set as the title attribute if | |
* the specified data is greater than the max characters, otherwise | |
* the data is returned unaffected. | |
*/ | |
function ellipse_span(data, chars = 50) | |
{ | |
return data.length > chars ? | |
"<span title=\""+data+"\">"+data.substr(0,chars)+"...</span>" | |
: data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment