JavaScript
How to Truncate in Prototype
Last Updated (Monday, 20 October 2008 08:27) Written by Alex Grande Thursday, 28 August 2008 05:26
This is to truncate multiple items in the javascript library Prototype. If it has the it will be truncated! Simple way:
var TruncateIt = Class.create({
initialize: function(sTruncate){
var toTruncate = (typeof sTruncate != 'undefined') ? $$(sTruncate) : $$('.truncate');
var len = 100;
for (var i = 0; i < toTruncate.length; i++) {
toTruncate[i].innerHTML = toTruncate[i].innerHTML.truncate(len);
}
}
});
document.observe('dom:loaded', function(){
var truncate = new TruncateIt('.truncate');
});
Thanks to Kris for helping me write this in a class as I'm totally new to prototype. See his hip new site at komputerart.com.
| < Prev | Next > |
|---|



