Main Menu

  • Home
  • jQuery
  • MooTools
  • CSS
  • JavaScript
  • Ruby on Rails
The True Tribe

Search, View and Navigation

JavaScript

How to Truncate in Prototype

Last Updated (Monday, 20 October 2008 08:27) Written by Alex Grande Thursday, 28 August 2008 05:26

Attention, open in a new window. PDFPrintE-mail

JavaScript - General


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 >

Add your comment

Your name:
Your email:
Your website:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
yvComment v.1.18.4

Additional Information

What is your job title?












Results

 © The True Tribe, 2008. Created by Jonah Dempcy and Alex Grande.    We are now accepting freelance work. Email us for rates and more information.