Skip to content

Commit 30f6bb0

Browse files
authored
Merge pull request #17 from madflow/fix_15
fix #15, empty targets cannot be locked
2 parents 509a1b5 + e97dd7a commit 30f6bb0

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013-2016 Florian Reiss
1+
Copyright (c) 2013-2017 Florian Reiss
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

dist/slugify.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
/*! jquery-slugify - v1.2.4 - 2016-06-15
2-
* Copyright (c) 2016 madflow; Licensed */
3-
;(function($) {
4-
1+
/*! jquery-slugify - v1.2.5 - 2017-10-06
2+
* Copyright (c) 2017 madflow; Licensed */
3+
(function($) {
54
$.fn.slugify = function(source, options) {
6-
75
return this.each(function() {
86
var $target = $(this),
97
$source = $(source);
@@ -17,6 +15,11 @@
1715
});
1816

1917
$source.on('keyup change', function() {
18+
// If the target is empty - it cannot be locked
19+
if ($target.val() === '' || $target.val() === undefined) {
20+
$target.data('locked', false);
21+
}
22+
2023
if (true === $target.data('locked')) {
2124
return;
2225
}
@@ -31,7 +34,6 @@
3134

3235
// Static method.
3336
$.slugify = function(sourceString, options) {
34-
3537
// Override default options with passed-in options.
3638
options = $.extend({}, $.slugify.options, options);
3739

@@ -62,5 +64,4 @@
6264
return window.getSlug(input, opts);
6365
}
6466
};
65-
66-
}(jQuery));
67+
})(jQuery);

dist/slugify.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jquery-slugify",
33
"filename": "slugify",
44
"description": "Just another another (another) url slug plugin for jQuery",
5-
"version": "1.2.4",
5+
"version": "1.2.5",
66
"main": "dist/slugify.min.js",
77
"author": {
88
"name": "madflow",

src/slugify.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/*
22
* https://github.com/madflow/jquery-slugify
33
*
4-
* Copyright (c) 2015 Florian Reiss
4+
* Copyright (c) 2015-2017 Florian Reiss
55
* Licensed under the MIT license.
66
*/
77

8-
;(function($) {
9-
8+
(function($) {
109
$.fn.slugify = function(source, options) {
11-
1210
return this.each(function() {
1311
var $target = $(this),
1412
$source = $(source);
@@ -22,6 +20,11 @@
2220
});
2321

2422
$source.on('keyup change', function() {
23+
// If the target is empty - it cannot be locked
24+
if ($target.val() === '' || $target.val() === undefined) {
25+
$target.data('locked', false);
26+
}
27+
2528
if (true === $target.data('locked')) {
2629
return;
2730
}
@@ -36,7 +39,6 @@
3639

3740
// Static method.
3841
$.slugify = function(sourceString, options) {
39-
4042
// Override default options with passed-in options.
4143
options = $.extend({}, $.slugify.options, options);
4244

@@ -67,5 +69,4 @@
6769
return window.getSlug(input, opts);
6870
}
6971
};
70-
71-
}(jQuery));
72+
})(jQuery);

test/slugify_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@
159159
'German specific lang option overrides html attribute');
160160
});
161161

162+
// https://github.com/madflow/jquery-slugify/issues/15
163+
test('test locked target should be released', function() {
164+
165+
$('body').prepend('<input type="text" id="slug-source-locked">');
166+
$('body').prepend('<input type="text" id="slug-target-locked">');
167+
$('#slug-target-locked').slugify('#slug-source-locked');
168+
$('#slug-source-locked').val('Hello good Sir! ').trigger('change');
169+
equal($('#slug-target-locked').val(), 'hello-good-sir', "Correct slug in target field change event");
170+
171+
$('#slug-target-locked').val('changed').trigger('change');
172+
$('#slug-source-locked').val('');
173+
$('#slug-target-locked').val('');
174+
175+
$('#slug-source-locked').val('Hello good Sir! ').trigger('change');
176+
equal($('#slug-target-locked').val(), 'hello-good-sir', "Correct slug in target field change event");
177+
178+
179+
});
180+
162181
QUnit.testDone(function() {
163182
$('#slug-target').val('');
164183
$('#slug-source').val('');

0 commit comments

Comments
 (0)