JavaScript
How to Truncate in Prototype
Last Updated (Thursday, 15 January 2009 18:11) 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. See his hip new site at komputerart.com.
| < Prev | Next > |
|---|


