-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
4 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
// | ||
// jQuery Slug Generation Plugin by Perry Trinier ([email protected]) | ||
// Modified November 2015 by Micheal Mand for AsgardCMS ([email protected]) | ||
// Modified November 2015 by Simon Funk for AsgardCMS ([email protected]) | ||
// Licensed under the GPL: http://www.gnu.org/copyleft/gpl.html | ||
|
||
jQuery.fn.slug = function (options) { | ||
var settings = { | ||
slug: 'slug', // Class used for slug destination input and span. The span is created on $(document).ready() | ||
hide: false, // Boolean - By default the slug input field is shown, set to false to hide the input field and show the span. | ||
override: false | ||
}; | ||
|
||
$this = jQuery(this); | ||
|
||
var slugContainer = $this.closest('.box-body').find('[data-slug="target"]'); | ||
|
||
if (options) { | ||
jQuery.extend(settings, options); | ||
} else { | ||
|
@@ -20,23 +22,13 @@ jQuery.fn.slug = function (options) { | |
} | ||
} | ||
|
||
jQuery(document).ready(function () { | ||
if (settings.hide) { | ||
$this.closest('input.' + settings.slug).after("<span class=" + settings.slug + "></span>"); | ||
$this.closest('input.' + settings.slug).hide(); | ||
} | ||
}); | ||
|
||
makeSlug = function (event) { | ||
var $theUnSlug = jQuery(event.target), | ||
$slugParent = $theUnSlug.closest('.form-group').next(), | ||
slugContent = $theUnSlug.val(), | ||
slugContentHyphens = slugContent.replace(/\s+/g, '-'), | ||
slugNoAccents = normalize(slugContentHyphens), | ||
finishedSlug = slugNoAccents.replace(/[^a-zA-Z0-9\-]/g, ''); | ||
|
||
$slugParent.find('input.' + settings.slug).val(finishedSlug.toLowerCase()); | ||
$slugParent.find('span.' + settings.slug).text(finishedSlug.toLowerCase()); | ||
slugContainer.val(finishedSlug.toLowerCase()); | ||
}; | ||
|
||
normalize = function(string) { | ||
|