diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2022-03-03 14:18:51 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2022-03-03 14:18:51 +0000 |
commit | dc4374cb9e7d0aa117e62a1cd026dd81ff7cc3e6 (patch) | |
tree | 6471901627388dae5a391bcf6cc04f09e233fa4b /media/admin/js/prepopulate.js | |
parent | 7f41017ce3569cd89c706f089e3f51179e5edc7b (diff) | |
download | troggle-dc4374cb9e7d0aa117e62a1cd026dd81ff7cc3e6.tar.gz troggle-dc4374cb9e7d0aa117e62a1cd026dd81ff7cc3e6.tar.bz2 troggle-dc4374cb9e7d0aa117e62a1cd026dd81ff7cc3e6.zip |
Update to new Django admin styles for v3.x
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); +} |