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

litwol - October 11, 2009 - 22:31
Status:needs review» needs work

Submit a patch please. information on how to make patches is here: http://drupal.org/patch

#2

jpmckinney - October 15, 2009 - 16:31
AttachmentSize
example.patch 1.05 KB

#3

jpmckinney - October 15, 2009 - 16:32
Status:needs work» needs review
 
 

Drupal is a registered trademark of Dries Buytaert.