Commit 465e9cd3 authored by Nicolas Widart's avatar Nicolas Widart

Updating jquery.slug script

parent 85052cd3
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"laravel5" "laravel5"
], ],
"license": "MIT", "license": "MIT",
"version": "1.6.0", "version": "1.7.0",
"type": "project", "type": "project",
"require": { "require": {
"laravel/framework": "~5.1", "laravel/framework": "~5.1",
......
// //
// jQuery Slug Generation Plugin by Perry Trinier (perrytrinier@gmail.com) // jQuery Slug Generation Plugin by Perry Trinier (perrytrinier@gmail.com)
// Modified November 2015 by Micheal Mand for AsgardCMS (micheal@kmdwebdesigns.com) // Modified November 2015 by Micheal Mand for AsgardCMS (micheal@kmdwebdesigns.com)
// Modified November 2015 by Simon Funk for AsgardCMS (simon.funk@treestones.ch)
// Licensed under the GPL: http://www.gnu.org/copyleft/gpl.html // Licensed under the GPL: http://www.gnu.org/copyleft/gpl.html
jQuery.fn.slug = function (options) { jQuery.fn.slug = function (options) {
var settings = { var settings = {
slug: 'slug', // Class used for slug destination input and span. The span is created on $(document).ready() 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 override: false
}; };
$this = jQuery(this); $this = jQuery(this);
var slugContainer = $this.closest('.box-body').find('[data-slug="target"]');
if (options) { if (options) {
jQuery.extend(settings, options); jQuery.extend(settings, options);
} else { } else {
...@@ -20,23 +22,13 @@ jQuery.fn.slug = function (options) { ...@@ -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) { makeSlug = function (event) {
var $theUnSlug = jQuery(event.target), var $theUnSlug = jQuery(event.target),
$slugParent = $theUnSlug.closest('.form-group').next(),
slugContent = $theUnSlug.val(), slugContent = $theUnSlug.val(),
slugContentHyphens = slugContent.replace(/\s+/g, '-'), slugContentHyphens = slugContent.replace(/\s+/g, '-'),
slugNoAccents = normalize(slugContentHyphens), slugNoAccents = normalize(slugContentHyphens),
finishedSlug = slugNoAccents.replace(/[^a-zA-Z0-9\-]/g, ''); finishedSlug = slugNoAccents.replace(/[^a-zA-Z0-9\-]/g, '');
slugContainer.val(finishedSlug.toLowerCase());
$slugParent.find('input.' + settings.slug).val(finishedSlug.toLowerCase());
$slugParent.find('span.' + settings.slug).text(finishedSlug.toLowerCase());
}; };
normalize = function(string) { normalize = function(string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment