| 1 |
|
function URLify(s, num_chars) { |
| 2 |
|
// changes, e.g., "Petty theft" to "petty_theft" |
| 3 |
|
// remove all these words from the string before urlifying |
| 4 |
|
var removelist = [Drupal.settings.urlify.remove_list]; |
| 5 |
|
r = new RegExp('\\\b(' + removelist.join('|') + ')\\\b', 'gi'); |
| 6 |
|
s = s.replace(r, ''); |
| 7 |
|
s = s.replace(/[^-A-Z0-9\s]/gi, ''); // remove unneeded chars |
| 8 |
|
s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces |
| 9 |
|
s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens |
| 10 |
|
s = s.toLowerCase(); // convert to lowercase |
| 11 |
|
return s.substring(0, num_chars); // trim to first num_chars chars |
| 12 |
|
} |
| 13 |
|
|