Download
Demo
- Overview
- Documents
User Rating: 4.5/5 ( 1 votes)
Your Rating:
dotdotdot is a jQuery plugin for advanced cross-browser ellipsis on multiple line content.
Source: dotdotdot.frebsite.nl
1. INCLUDE JS FILES
<script src="jquery.js" type="text/javascript"></script> <script src="jquery.dotdotdot.js" type="text/javascript"></script>
2. HTML
<div id="wrapper"> <p>Lorem Ipsum is simply dummy text.</p> </div>
3. JAVASCRIPT
$(document).ready(function() {
$("#wrapper").dotdotdot({
// configuration goes here
});
});
4. OPTIONS
$(document).ready(function() {
$("#wrapper").dotdotdot({
/* The HTML to add as ellipsis. */
ellipsis : '... ',
/* How to cut off the text/html: 'word'/'letter'/'children' */
wrap : 'word',
/* Wrap-option fallback to 'letter' for long words */
fallbackToLetter: true,
/* jQuery-selector for the element to keep and put after the ellipsis. */
after : null,
/* Whether to update the ellipsis: true/'window' */
watch : false,
/* Optionally set a max-height, if null, the height will be measured. */
height : null,
/* Deviation for the height-option. */
tolerance : 0,
/* Callback function that is fired after the ellipsis is added,
receives two parameters: isTruncated(boolean), orgContent(string). */
callback : function( isTruncated, orgContent ) {},
lastCharacter : {
/* Remove these characters from the end of the truncated text. */
remove : [ ' ', ',', ';', '.', '!', '?' ],
/* Don't add an ellipsis if this array contains
the last character of the truncated text. */
noEllipsis : []
}
});
});
5. EVENTS
Need to update the ellipsis manually? Trigger the "update"-event.
$("#button").click(function() {
$("#wrapper").trigger("update");
});
Want to know if the text got truncated? Trigger the "isTruncated"-event.
$("#button").click(function() {
// by using the return-value...
var isTruncated = $("#wrapper").triggerHandler("isTruncated");
if ( isTruncated ) {
// do something
}
// ...or by using the callback function
$("#wrapper").trigger("isTruncated", function( isTruncated ) {
if ( isTruncated ) {
// do something
}
});
});
Need the original content? Trigger the "originalContent"-event.
$("#button").click(function() {
// by using the return-value...
var content = $("#wrapper").triggerHandler("originalContent");
$("#foo").append( content );
// ...or by using the callback function
$("#wrapper").trigger("originalContent", function( content ) {
$("#foo").append( content );
});
});
If you want to destroy the ellipsis, trigger the "destroy"-event.
$("#button").click(function() {
$("#wrapper").trigger("destroy");
});
Please note that all custom events have been namespaced to ".dot", so to prevent interfering with other scripts, triggering an event would best be done like this:
$("#wrapper").trigger("update.dot");
JS Tutorial
