diff options
author | eliott <eliott@cactuswax.net> | 2007-12-29 14:52:45 -0800 |
---|---|---|
committer | eliott <eliott@cactuswax.net> | 2007-12-29 14:52:45 -0800 |
commit | cbb5c0495f42d4e098f234a1e3c390e4ddff3c77 (patch) | |
tree | 4e80228877f69413d76383aeb589ade3a1b4d455 /media/admin_media/js/urlify.js | |
parent | c88e6ff2520dd2caf991f81c3b9a8b5f1e215fe0 (diff) |
Added admin-media files.
Diffstat (limited to 'media/admin_media/js/urlify.js')
-rw-r--r-- | media/admin_media/js/urlify.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/media/admin_media/js/urlify.js b/media/admin_media/js/urlify.js new file mode 100644 index 00000000..9b871136 --- /dev/null +++ b/media/admin_media/js/urlify.js @@ -0,0 +1,15 @@ +function URLify(s, num_chars) { + // changes, e.g., "Petty theft" to "petty_theft" + // remove all these words from the string before urlifying + removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from", + "is", "in", "into", "like", "of", "off", "on", "onto", "per", + "since", "than", "the", "this", "that", "to", "up", "via", + "with"]; + r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); + s = s.replace(r, ''); + s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars + s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces + s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens + s = s.toLowerCase(); // convert to lowercase + return s.substring(0, num_chars);// trim to first num_chars chars +} |