Skip to content

Commit

Permalink
Merge pull request #17 from madflow/fix_15
Browse files Browse the repository at this point in the history
fix #15, empty targets cannot be locked
  • Loading branch information
madflow authored Oct 6, 2017
2 parents 509a1b5 + e97dd7a commit 30f6bb0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013-2016 Florian Reiss
Copyright (c) 2013-2017 Florian Reiss

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
17 changes: 9 additions & 8 deletions dist/slugify.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*! jquery-slugify - v1.2.4 - 2016-06-15
* Copyright (c) 2016 madflow; Licensed */
;(function($) {

/*! jquery-slugify - v1.2.5 - 2017-10-06
* Copyright (c) 2017 madflow; Licensed */
(function($) {
$.fn.slugify = function(source, options) {

return this.each(function() {
var $target = $(this),
$source = $(source);
Expand All @@ -17,6 +15,11 @@
});

$source.on('keyup change', function() {
// If the target is empty - it cannot be locked
if ($target.val() === '' || $target.val() === undefined) {
$target.data('locked', false);
}

if (true === $target.data('locked')) {
return;
}
Expand All @@ -31,7 +34,6 @@

// Static method.
$.slugify = function(sourceString, options) {

// Override default options with passed-in options.
options = $.extend({}, $.slugify.options, options);

Expand Down Expand Up @@ -62,5 +64,4 @@
return window.getSlug(input, opts);
}
};

}(jQuery));
})(jQuery);
6 changes: 3 additions & 3 deletions dist/slugify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jquery-slugify",
"filename": "slugify",
"description": "Just another another (another) url slug plugin for jQuery",
"version": "1.2.4",
"version": "1.2.5",
"main": "dist/slugify.min.js",
"author": {
"name": "madflow",
Expand Down
15 changes: 8 additions & 7 deletions src/slugify.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/*
* https://github.com/madflow/jquery-slugify
*
* Copyright (c) 2015 Florian Reiss
* Copyright (c) 2015-2017 Florian Reiss
* Licensed under the MIT license.
*/

;(function($) {

(function($) {
$.fn.slugify = function(source, options) {

return this.each(function() {
var $target = $(this),
$source = $(source);
Expand All @@ -22,6 +20,11 @@
});

$source.on('keyup change', function() {
// If the target is empty - it cannot be locked
if ($target.val() === '' || $target.val() === undefined) {
$target.data('locked', false);
}

if (true === $target.data('locked')) {
return;
}
Expand All @@ -36,7 +39,6 @@

// Static method.
$.slugify = function(sourceString, options) {

// Override default options with passed-in options.
options = $.extend({}, $.slugify.options, options);

Expand Down Expand Up @@ -67,5 +69,4 @@
return window.getSlug(input, opts);
}
};

}(jQuery));
})(jQuery);
19 changes: 19 additions & 0 deletions test/slugify_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@
'German specific lang option overrides html attribute');
});

// https://github.com/madflow/jquery-slugify/issues/15
test('test locked target should be released', function() {

$('body').prepend('<input type="text" id="slug-source-locked">');
$('body').prepend('<input type="text" id="slug-target-locked">');
$('#slug-target-locked').slugify('#slug-source-locked');
$('#slug-source-locked').val('Hello good Sir! ').trigger('change');
equal($('#slug-target-locked').val(), 'hello-good-sir', "Correct slug in target field change event");

$('#slug-target-locked').val('changed').trigger('change');
$('#slug-source-locked').val('');
$('#slug-target-locked').val('');

$('#slug-source-locked').val('Hello good Sir! ').trigger('change');
equal($('#slug-target-locked').val(), 'hello-good-sir', "Correct slug in target field change event");


});

QUnit.testDone(function() {
$('#slug-target').val('');
$('#slug-source').val('');
Expand Down

0 comments on commit 30f6bb0

Please sign in to comment.