new static files.
Signed-off-by: rscnt <rascnt@gmail.com>
This commit is contained in:
parent
5da7cfab99
commit
bb68c32ba5
772 changed files with 71557 additions and 0 deletions
39
static/admin/js/prepopulate.js
Normal file
39
static/admin/js/prepopulate.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
(function($) {
|
||||
$.fn.prepopulate = function(dependencies, maxLength) {
|
||||
/*
|
||||
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
|
||||
*/
|
||||
return this.each(function() {
|
||||
var prepopulatedField = $(this);
|
||||
|
||||
var populate = function () {
|
||||
// Bail if the field's value has been changed by the user
|
||||
if (prepopulatedField.data('_changed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var values = [];
|
||||
$.each(dependencies, function(i, field) {
|
||||
field = $(field);
|
||||
if (field.val().length > 0) {
|
||||
values.push(field.val());
|
||||
}
|
||||
});
|
||||
prepopulatedField.val(URLify(values.join(' '), maxLength));
|
||||
};
|
||||
|
||||
prepopulatedField.data('_changed', false);
|
||||
prepopulatedField.change(function() {
|
||||
prepopulatedField.data('_changed', true);
|
||||
});
|
||||
|
||||
if (!prepopulatedField.val()) {
|
||||
$(dependencies.join(',')).keyup(populate).change(populate).focus(populate);
|
||||
}
|
||||
});
|
||||
};
|
||||
})(django.jQuery);
|
||||
Loading…
Add table
Add a link
Reference in a new issue