StringToSlug Demo

Change:

Preview: change-the-content-of-this-field-and-view-the-text-with-red-background-preview

Default Usage:

/** * Default Events: Blur, KeyUp e KeyDown: * Default Get Put: #permalink * Default Space Replacement: - (hiphen) * Default &(AND) Char Replacement: and */ $(document).ready( function() { $("#string").stringToSlug(); });

FINALLY: Using the API doesn't need output (added on 1.3.1)

	$(document).ready( function() {
		var text = "I'd like to invite my fiancé";
		_stringToSlug_API( text );
		console.log(text);
	});
	
	$(document).ready( function() {
		var text = "él & ella!";
		result = _stringToSlug_API( text, options = { 'AND': 'y', 'space': '_', suffix: '.jpg' } );
		console.log(result); //returns: el_y_ella.jpg
	});
	

The values Default at Plugin Usage:

$(document).ready( function() { $("#title").stringToSlug({ setEvents: 'keyup keydown blur', getPut: '#permalink', space: '-', prefix: '', suffix: '', replace: '', AND: 'and', callback: false }); });

Other(s) Event(s) Usage:

To change the events, we must insert one or more events separated by space:

	
$(document).ready( function() { //Only Event Blur $("#only-blur-event").stringToSlug({ setEvents: "blur" }); //2 Events or More //This sample, Usage Events: KeyUp and KeyDown $("#keyup-and-keydown-events").stringToSlug({ setEvents: "keyup keydown" }); });

Other Get Put Preview Usage:

$(document).ready( function() { //Previem in all texarea $("input[name=string]").stringToSlug({ getPut: "textarea" }); //Preview in all elements preview class $("#input[name=string]").stringToSlug({ getPut: ".class" }); });

Replace hiphen by other char Usage:

	$(document).ready( function() {
		//Replace by underscore
		$("#input[name=string]").stringToSlug({
			space: "_"
		});
	});
	

Calls a given callback function:

	$(document).ready( function() {
		//Callback function in use
		$("#input[name=string]").stringToSlug({
			callback: function(slug){ console.log(slug);
		});
	});
	

Remove text between parentheses:

	$(document).ready( function() {
		//Remove between parentheses
		$("#input['no-parentheses']").stringToSlug({
			replace: /\s?\([^\)]*\)/gi
		});
	});
	

Replace &(and) CHAR (added on 1.3.0):

	$(document).ready( function() {
		//Replace & to e (Portuguese)
		$("#input").stringToSlug({
			AND: 'e'
		});

		//Replace & to Y (Spanish)
		$("#input").stringToSlug({
			AND: 'y'
		});

		//Replace & to Empty
		$("#input").stringToSlug({
			AND: ''
		});

		//Replace & to hyphen
		$("#input").stringToSlug({
			AND: '-'
		});
	});
	

Set a prefix, like an URL:

	$(document).ready( function() {
		$("#input").stringToSlug({
			prefix: 'http://'
		});
	});
	

Set a suffix, like an extension:

	$(document).ready( function() {
		$("#input").stringToSlug({
			suffix: '.jpg'
		});
	});
	


jQuery Plugin StringToSlug create by @leocaseiro