Convert any string into slugs and bind using jQuery
bower install --save jquery.stringtoslug
English / Latin by default
$(document).ready( function() { $(".basic-usage").stringToSlug(); });
All settings are optional and work as a default as set out in the table below:
Setting | Type | Description | Default |
---|---|---|---|
setEvents | string | jQuery events to bind | 'keyup keydown blur' |
getPut | string | The jQuery selector that will output the converted string (slug) | '#permalink' |
space | string | Separator char that will be replaced for every space | '-' |
prefix | string | A prefix that will be concatenated in front of the slug | '' |
suffix | string | A suffix that will be concatenated at the end of the slug | '' |
replace | regExp | A regular expression to replace/remove the string | '' |
AND | string | The default value of '&' which normally means 'and' | 'and' |
options | object | string | Use options to customize 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 setting setEvents to choose events to bind
focus-on-this-input-and-after-blur-it-will-be-converted-into-a-slug
$(document).ready( function() { $(".input-to-slug").stringToSlug({ setEvents: 'blur' }); });
Use the setting getPut to choose an output. jQuery StringToSlug works for html elements or inputs
.alert.alert-info
$(document).ready( function() { $('[type="text"]').stringToSlug({ getPut: '.alert.alert-info' }); });
Use the setting 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 setting prefix to choose a prefix
js-
js-selector-for-javascript
$(document).ready( function() { $('[type="text"]').stringToSlug({ prefix: 'js-' }); });
Use the setting suffix to choose a suffix
.jpg
suffix-for-images.jpg
$(document).ready( function() { $('[type="text"]').stringToSlug({ suffix: '.jpg' }); });
Use the setting 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 setting 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 defining 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); } }); });