String.Slugify 1.1
Details
- Author
- Stian Didriksen
- Current version
- 1.1
- GitHub
- stipsan/String.Slugify.js
- Downloads
- 2724
- Category
- Native
- Tags
- Report
- GitHub Issues
Releases
Dependencies
- core:1.2.4/String/core: 1.2.4
- core:1.2.4/$util/core: 1.2.4
- core:1.2.4/Array/core: 1.2.4
- more:1.2.4/String.Extras/more: 1.2.4
How to use
String.Slugify extends the native String object, so it works on any ordinary string.
"slugify ME n%ø#w".slugify()
Returns "slugify-me-now"
Real World Usage Example
This example shows how you can use slugify on two text inputs to create valid slugs from an ordinary title field.
The title field <input id="title">, and the slug <input id="alias">.
We're listening to the change event on the slug input, and the keyup and keydown events additionally on the <input id="title"> element; This is to make the <input id="alias"> input update as you type the title and be slugified in the process:
var aliasvalidator = function(){
this.value = this.value.slugify();
};
var titlevalidator = function(){
if(!$('alias').defaultValue) $('alias').value = this.value.slugify();
};
$('title').addEvents({'keyup': titlevalidator, 'keydown': titlevalidator, 'change': titlevalidator});
$('alias').addEvents({'change': aliasvalidator});
Discuss
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus