Fork me on GitHub

Slugify()

A jQuery plugin that automatically creates slugs as you type. Try it:

Your URL is http://geocities.com/awesometown/.

$('.slug').slugify('#title');

The plugin takes one option, slugFunc, a callback function that lets you customize how slugs are created. slugFunc() takes two arguments. The first is a selector for the input field to be translated to a slug. The second, optional argument is the original slugFunc(), which you can use as a base.

var pigLatin = function(str) {
  return replace(/(\w*)([aeiou]\w*)/g, "$2$1ay");
}

$('#pig_latin').slugify('#title', {
    slugFunc: function(str, originalFunc) { return pigLatin(originalFunc(str)); } 
  }
); 

About

This plugin was created by Patrick McElhaney (pmcelhaney@gmail.com). You can download this project in either zip or tar formats. You can also clone the project with Git by running:

$ git clone git://github.com/pmcelhaney/jQuery-Slugify-Plugin