diff options
Diffstat (limited to 'media/admin/js/prepopulate.js')
-rw-r--r-- | media/admin/js/prepopulate.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/media/admin/js/prepopulate.js b/media/admin/js/prepopulate.js index db7903a..89e95ab 100644 --- a/media/admin/js/prepopulate.js +++ b/media/admin/js/prepopulate.js @@ -1,39 +1,43 @@ -(function($) { - $.fn.prepopulate = function(dependencies, maxLength) { +/*global URLify*/ +'use strict'; +{ + const $ = django.jQuery; + $.fn.prepopulate = function(dependencies, maxLength, allowUnicode) { /* Depends on urlify.js Populates a selected field with the values of the dependent fields, URLifies and shortens the string. dependencies - array of dependent fields ids maxLength - maximum length of the URLify'd string + allowUnicode - Unicode support of the URLify'd string */ return this.each(function() { - var prepopulatedField = $(this); + const prepopulatedField = $(this); - var populate = function () { + const populate = function() { // Bail if the field's value has been changed by the user if (prepopulatedField.data('_changed')) { return; } - var values = []; + const values = []; $.each(dependencies, function(i, field) { field = $(field); if (field.val().length > 0) { values.push(field.val()); } }); - prepopulatedField.val(URLify(values.join(' '), maxLength)); + prepopulatedField.val(URLify(values.join(' '), maxLength, allowUnicode)); }; prepopulatedField.data('_changed', false); - prepopulatedField.change(function() { + prepopulatedField.on('change', function() { prepopulatedField.data('_changed', true); }); if (!prepopulatedField.val()) { - $(dependencies.join(',')).keyup(populate).change(populate).focus(populate); + $(dependencies.join(',')).on('keyup change focus', populate); } }); }; -})(django.jQuery); +} |