Make slug in Javascript or Jquery::
<script type="text/javascript">
//Make Slug::
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
$('#page_slug').on('keyup change', function(){ $('#page_slug').val(slugify(($(this).val()))); });
OR
$('#page_slug').on('blur', function(){ $('#page_slug').val(slugify(($(this).val()))); });
</script>
<script type="text/javascript">
//Make Slug::
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
$('#page_slug').on('keyup change', function(){ $('#page_slug').val(slugify(($(this).val()))); });
OR
$('#page_slug').on('blur', function(){ $('#page_slug').val(slugify(($(this).val()))); });
</script>
No comments:
Post a Comment