Add Drupal.truncateUtf8
jpmckinney - October 11, 2009 - 21:03
| Project: | JavaScript Theming |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
(I thought I submitted this just now, but it's not showing up.)
<?php
Drupal.truncateUtf8 = function (string, len, wordsafe, dots) {
if (string.length <= len) {
return string;
}
if (dots) {
len -= 4;
}
if (wordsafe) {
string = string.substring(0, len + 1);
if (lastSpace = string.lastIndexOf(' ')) {
string = string.substring(0, lastSpace);
}
else {
string = string.substring(0, len);
}
}
else {
string = string.substring(0, len);
}
if (dots) {
string += ' ...';
}
return string;
}
?>
#1
Submit a patch please. information on how to make patches is here: http://drupal.org/patch
#2
#3