Skip to content

Commit

Permalink
Add a callback parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
hugofcampos committed Jan 23, 2012
1 parent b488b22 commit 39c4847
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion jquery.stringToSlug.js
Expand Up @@ -20,7 +20,8 @@ jQuery.fn.stringToSlug = function(options) {
space: '-', //Sets the space character. If the hyphen,
prefix: '',
suffix: '',
replace: '' //Sample: /\s?\([^\)]*\)/gi
replace: '', //Sample: /\s?\([^\)]*\)/gi
callback: false
};

var opts = jQuery.extend(defaults, options);
Expand Down Expand Up @@ -407,6 +408,9 @@ jQuery.fn.stringToSlug = function(options) {
jQuery(defaults.getPut).val(stringToSlug); //Write in value to input fields (input text, textarea, input hidden, ...)
jQuery(defaults.getPut).html(stringToSlug); //Write in HTML tags (span, p, strong, h1, ...)

if(defaults.callback!=false){
defaults.callback(stringToSlug);
}

return this;
});
Expand Down
16 changes: 14 additions & 2 deletions samples.html
@@ -1,4 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -10,7 +10,7 @@

<script type="text/javascript">
$(document).ready( function() {
$("#string").stringToSlug();
$("#string").stringToSlug({callback: function(text){ console.log(text); }});
});
</script>
<style>
Expand Down Expand Up @@ -111,6 +111,18 @@ <h4>Replace hiphen by other char Usage:</h4>
});
</pre>
</div>

<div class="sample">
<h4>Calls a given callback function:</h4>
<pre class="brush: javascript">
$(document).ready( function() {
//Replace by underscore
$(&quot;#input[name=string]&quot;).stringToSlug({
callback: function(slug){ console.log(slug); }
);
});
</pre>
</div>
<br /><br />
<em><small>jQuery Plugin StringToSlug create by <a title="Create at Leo Caseiro" href="http://leocaseiro.com.br/">@leocaseiro</a></small></em>
</body>
Expand Down

0 comments on commit 39c4847

Please sign in to comment.