Convert any string into slugs and bind using jQuery
bower install --save jquery.stringtoslug
English / Lating by default
$(document).ready( function() { $(".basic-usage").stringToSlug(); });
All options are optional and will work as default following the table bellow:
Option | Type | Description | Default |
---|---|---|---|
setEvents | string | jQuery events to bind | 'keyup keydown blur' |
getPut | string | The jQuery selector that will output the slugged string | '#permalink |
space | string | Separator char that will be replaced for every space | '-' |
prefix | string | A prefix that will be concatenated before string slugged | '' |
suffix | string | A suffix that will be concatenated before string slugged | '' |
replace | regExp | A Regular Expression to replace/remove the string | '' |
AND | string | The default value of & which normally means and | 'and' |
options | object | string | This option is used to custom the SpeakingURL library | {} |
callback | function | A callback function that will be called after every bind defined on setEvents | false |
$(document).ready( function() { $(".basic-usage").stringToSlug({ setEvents: 'keyup keydown blur', getPut: '#permalink', space: '-', prefix: '', suffix: '', replace: '', AND: 'and', options: {}, callback: false }); });
Use the option setEvents to choose events for bind
focus-on-this-input-and-after-blur-it-will-be-slugged
$(document).ready( function() { $(".input-to-slug").stringToSlug({ setEvents: 'blur' }); });
Use the option getPut to choose an output. jQuery StringToSlug works for html elements or inputs as well
.alert.alert-info
$(document).ready( function() { $('[type="text"]').stringToSlug({ getPut: '.alert.alert-info' }); });
Use the option space to choose a separator replacement.
replace_me_with_some_dummy_data_and_check_the_separator
$(document).ready( function() { $('[type="text"]').stringToSlug({ space: '_' }); });
Use the option prefix to choose a prefix.
js-
js-selector-for-javascript
$(document).ready( function() { $('[type="text"]').stringToSlug({ prefix: 'js-' }); });
Use the option suffix to choose a suffix.
js-
suffix-for-images.jpg
$(document).ready( function() { $('[type="text"]').stringToSlug({ suffix: '.jpg' }); });
Use the option replace to replace/remove some pattern.
replace
and the regex /\s?\([^\)]*\)/gi
product-example
$(document).ready( function() { $('[type="text"]').stringToSlug({ replace: /\s?\([^\)]*\)/gi, }); });
Use the option AND to choose a different replacement for &.
AND
in Spanish (Español)el-y-ella
$(document).ready( function() { $('[type="text"]').stringToSlug({ AND: 'y' }); });
Use options to customize SpeakinURL.
options
from SpeakingURL changing the language to Arabic and using titleCase pattern$(document).ready( function() { $('[type="text"]').stringToSlug({ options: { lang: 'ar', titleCase: true } }); });
Use callback to call a function after stringToSlug.
callback
open-your-console-from-developer-tools-and-check-the-warning
$(document).ready( function() { $('[type="text"]').stringToSlug({ callback: function(text) { console.warn('This warn is a callback: ' + text); } }); });