Created
May 10, 2015 21:13
-
-
Save timstermatic/a53cbe94320679a8f1e1 to your computer and use it in GitHub Desktop.
populate one field with a url slug based on value entered into another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ( $ ) { | |
$.fn.slugger = function(options) { | |
var that = this; | |
var settings = $.extend({ | |
target: null, | |
}, options ); | |
if(settings.target) { | |
settings.target.focus(function() { | |
$(this).addClass('dirty'); | |
}); | |
that.keyup(function() { | |
if(!settings.target.hasClass('dirty')) { | |
settings.target.val($(that).val().toLowerCase().replace(/[^\w\s]/gi, '-').split(" ").join("-")); | |
} | |
}) | |
} | |
}; | |
}( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment