mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Refs #28956 -- Removed usage of jQuery's deprecated .selector property in admin JavaScript.
This commit is contained in:
parent
8dbaeb6138
commit
b730973fff
@ -145,10 +145,10 @@
|
||||
|
||||
|
||||
// Tabular inlines ---------------------------------------------------------
|
||||
$.fn.tabularFormset = function(options) {
|
||||
$.fn.tabularFormset = function(selector, options) {
|
||||
var $rows = $(this);
|
||||
var alternatingRows = function(row) {
|
||||
$($rows.selector).not(".add-row").removeClass("row1 row2")
|
||||
$(selector).not(".add-row").removeClass("row1 row2")
|
||||
.filter(":even").addClass("row1").end()
|
||||
.filter(":odd").addClass("row2");
|
||||
};
|
||||
@ -212,10 +212,10 @@
|
||||
};
|
||||
|
||||
// Stacked inlines ---------------------------------------------------------
|
||||
$.fn.stackedFormset = function(options) {
|
||||
$.fn.stackedFormset = function(selector, options) {
|
||||
var $rows = $(this);
|
||||
var updateInlineLabel = function(row) {
|
||||
$($rows.selector).find(".inline_label").each(function(i) {
|
||||
$(selector).find(".inline_label").each(function(i) {
|
||||
var count = i + 1;
|
||||
$(this).html($(this).html().replace(/(#\d+)/g, "#" + count));
|
||||
});
|
||||
@ -281,13 +281,16 @@
|
||||
$(document).ready(function() {
|
||||
$(".js-inline-admin-formset").each(function() {
|
||||
var data = $(this).data(),
|
||||
inlineOptions = data.inlineFormset;
|
||||
inlineOptions = data.inlineFormset,
|
||||
selector;
|
||||
switch(data.inlineType) {
|
||||
case "stacked":
|
||||
$(inlineOptions.name + "-group .inline-related").stackedFormset(inlineOptions.options);
|
||||
selector = inlineOptions.name + "-group .inline-related";
|
||||
$(selector).stackedFormset(selector, inlineOptions.options);
|
||||
break;
|
||||
case "tabular":
|
||||
$(inlineOptions.name + "-group .tabular.inline-related tbody:first > tr").tabularFormset(inlineOptions.options);
|
||||
selector = inlineOptions.name + "-group .tabular.inline-related tbody:first > tr";
|
||||
$(selector).tabularFormset(selector, inlineOptions.options);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
@ -1,13 +1,13 @@
|
||||
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(b,c,a){b instanceof String&&(b=String(b));for(var d=b.length,f=0;f<d;f++){var g=b[f];if(c.call(a,g,f,b))return{i:f,v:g}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(b,c,a){b!=Array.prototype&&b!=Object.prototype&&(b[c]=a.value)};
|
||||
$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(b,c,a,d){if(c){a=$jscomp.global;b=b.split(".");for(d=0;d<b.length-1;d++){var f=b[d];f in a||(a[f]={});a=a[f]}b=b[b.length-1];d=a[b];c=c(d);c!=d&&null!=c&&$jscomp.defineProperty(a,b,{configurable:!0,writable:!0,value:c})}};
|
||||
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(b,d,a){b instanceof String&&(b=String(b));for(var c=b.length,f=0;f<c;f++){var g=b[f];if(d.call(a,g,f,b))return{i:f,v:g}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(b,d,a){b!=Array.prototype&&b!=Object.prototype&&(b[d]=a.value)};
|
||||
$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(b,d,a,c){if(d){a=$jscomp.global;b=b.split(".");for(c=0;c<b.length-1;c++){var f=b[c];f in a||(a[f]={});a=a[f]}b=b[b.length-1];c=a[b];d=d(c);d!=c&&null!=d&&$jscomp.defineProperty(a,b,{configurable:!0,writable:!0,value:d})}};
|
||||
$jscomp.polyfill("Array.prototype.find",function(b){return b?b:function(b,a){return $jscomp.findInternal(this,b,a).v}},"es6","es3");
|
||||
(function(b){b.fn.formset=function(c){var a=b.extend({},b.fn.formset.defaults,c),d=b(this);c=d.parent();var f=function(a,e,c){var h=new RegExp("("+e+"-(\\d+|__prefix__))");e=e+"-"+c;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(h,e));a.id&&(a.id=a.id.replace(h,e));a.name&&(a.name=a.name.replace(h,e))},g=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),e=parseInt(g.val(),10),h=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),m=""===h.val()||0<h.val()-g.val();
|
||||
d.each(function(e){b(this).not("."+a.emptyCssClass).addClass(a.formCssClass)});if(d.length&&m){var k=a.addButton;null===k&&("TR"===d.prop("tagName")?(d=this.eq(-1).children().length,c.append('<tr class="'+a.addCssClass+'"><td colspan="'+d+'"><a href="#">'+a.addText+"</a></tr>"),k=c.find("tr:last a")):(d.filter(":last").after('<div class="'+a.addCssClass+'"><a href="#">'+a.addText+"</a></div>"),k=d.filter(":last").next().find("a")));k.click(function(c){c.preventDefault();c=b("#"+a.prefix+"-empty");
|
||||
var d=c.clone(!0);d.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+e);d.is("tr")?d.children(":last").append('<div><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></div>"):d.is("ul")||d.is("ol")?d.append('<li><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></li>"):d.children(":first").append('<span><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></span>");d.find("*").each(function(){f(this,a.prefix,g.val())});d.insertBefore(b(c));
|
||||
b(g).val(parseInt(g.val(),10)+1);e+=1;""!==h.val()&&0>=h.val()-g.val()&&k.parent().hide();d.find("a."+a.deleteCssClass).click(function(c){c.preventDefault();d.remove();--e;a.removed&&a.removed(d);b(document).trigger("formset:removed",[d,a.prefix]);c=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(c.length);(""===h.val()||0<h.val()-c.length)&&k.parent().show();var g,m=function(){f(this,a.prefix,l)};var l=0;for(g=c.length;l<g;l++)f(b(c).get(l),a.prefix,l),b(c.get(l)).find("*").each(m)});
|
||||
a.added&&a.added(d);b(document).trigger("formset:added",[d,a.prefix])})}return this};b.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null,addButton:null};b.fn.tabularFormset=function(c){var a=b(this),d=function(c){b(a.selector).not(".add-row").removeClass("row1 row2").filter(":even").addClass("row1").end().filter(":odd").addClass("row2")},f=function(){"undefined"!==
|
||||
typeof SelectFilter&&(b(".selectfilter").each(function(b,a){b=a.name.split("-");SelectFilter.init(a.id,b[b.length-1],!1)}),b(".selectfilterstacked").each(function(b,a){b=a.name.split("-");SelectFilter.init(a.id,b[b.length-1],!0)}))},g=function(a){a.find(".prepopulated_field").each(function(){var c=b(this).find("input, select, textarea"),d=c.data("dependency_list")||[],e=[];b.each(d,function(b,c){e.push("#"+a.find(".field-"+c).find("input, select, textarea").attr("id"))});e.length&&c.prepopulate(e,
|
||||
c.attr("maxlength"))})};a.formset({prefix:c.prefix,addText:c.addText,formCssClass:"dynamic-"+c.prefix,deleteCssClass:"inline-deletelink",deleteText:c.deleteText,emptyCssClass:"empty-form",removed:d,added:function(a){g(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());f();d(a)},addButton:c.addButton});return a};b.fn.stackedFormset=function(c){var a=b(this),d=function(c){b(a.selector).find(".inline_label").each(function(a){a+=1;b(this).html(b(this).html().replace(/(#\d+)/g,
|
||||
"#"+a))})},f=function(){"undefined"!==typeof SelectFilter&&(b(".selectfilter").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!1)}),b(".selectfilterstacked").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!0)}))},g=function(a){a.find(".prepopulated_field").each(function(){var c=b(this).find("input, select, textarea"),d=c.data("dependency_list")||[],e=[];b.each(d,function(b,c){e.push("#"+a.find(".form-row .field-"+c).find("input, select, textarea").attr("id"))});
|
||||
e.length&&c.prepopulate(e,c.attr("maxlength"))})};a.formset({prefix:c.prefix,addText:c.addText,formCssClass:"dynamic-"+c.prefix,deleteCssClass:"inline-deletelink",deleteText:c.deleteText,emptyCssClass:"empty-form",removed:d,added:function(a){g(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());f();d(a)},addButton:c.addButton});return a};b(document).ready(function(){b(".js-inline-admin-formset").each(function(){var c=b(this).data(),a=c.inlineFormset;
|
||||
switch(c.inlineType){case "stacked":b(a.name+"-group .inline-related").stackedFormset(a.options);break;case "tabular":b(a.name+"-group .tabular.inline-related tbody:first > tr").tabularFormset(a.options)}})})})(django.jQuery);
|
||||
(function(b){b.fn.formset=function(d){var a=b.extend({},b.fn.formset.defaults,d),c=b(this);d=c.parent();var f=function(a,e,d){var c=new RegExp("("+e+"-(\\d+|__prefix__))");e=e+"-"+d;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(c,e));a.id&&(a.id=a.id.replace(c,e));a.name&&(a.name=a.name.replace(c,e))},g=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),h=parseInt(g.val(),10),e=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),m=""===e.val()||0<e.val()-g.val();
|
||||
c.each(function(e){b(this).not("."+a.emptyCssClass).addClass(a.formCssClass)});if(c.length&&m){var l=a.addButton;null===l&&("TR"===c.prop("tagName")?(c=this.eq(-1).children().length,d.append('<tr class="'+a.addCssClass+'"><td colspan="'+c+'"><a href="#">'+a.addText+"</a></tr>"),l=d.find("tr:last a")):(c.filter(":last").after('<div class="'+a.addCssClass+'"><a href="#">'+a.addText+"</a></div>"),l=c.filter(":last").next().find("a")));l.click(function(d){d.preventDefault();d=b("#"+a.prefix+"-empty");
|
||||
var c=d.clone(!0);c.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+h);c.is("tr")?c.children(":last").append('<div><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></div>"):c.is("ul")||c.is("ol")?c.append('<li><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></li>"):c.children(":first").append('<span><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></span>");c.find("*").each(function(){f(this,a.prefix,g.val())});c.insertBefore(b(d));
|
||||
b(g).val(parseInt(g.val(),10)+1);h+=1;""!==e.val()&&0>=e.val()-g.val()&&l.parent().hide();c.find("a."+a.deleteCssClass).click(function(d){d.preventDefault();c.remove();--h;a.removed&&a.removed(c);b(document).trigger("formset:removed",[c,a.prefix]);d=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(d.length);(""===e.val()||0<e.val()-d.length)&&l.parent().show();var m,g=function(){f(this,a.prefix,k)};var k=0;for(m=d.length;k<m;k++)f(b(d).get(k),a.prefix,k),b(d.get(k)).find("*").each(g)});
|
||||
a.added&&a.added(c);b(document).trigger("formset:added",[c,a.prefix])})}return this};b.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null,addButton:null};b.fn.tabularFormset=function(d,a){var c=b(this),f=function(a){b(d).not(".add-row").removeClass("row1 row2").filter(":even").addClass("row1").end().filter(":odd").addClass("row2")},g=function(){"undefined"!==
|
||||
typeof SelectFilter&&(b(".selectfilter").each(function(b,a){b=a.name.split("-");SelectFilter.init(a.id,b[b.length-1],!1)}),b(".selectfilterstacked").each(function(b,a){b=a.name.split("-");SelectFilter.init(a.id,b[b.length-1],!0)}))},h=function(a){a.find(".prepopulated_field").each(function(){var c=b(this).find("input, select, textarea"),d=c.data("dependency_list")||[],e=[];b.each(d,function(b,c){e.push("#"+a.find(".field-"+c).find("input, select, textarea").attr("id"))});e.length&&c.prepopulate(e,
|
||||
c.attr("maxlength"))})};c.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:f,added:function(a){h(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());g();f(a)},addButton:a.addButton});return c};b.fn.stackedFormset=function(d,a){var c=b(this),f=function(a){b(d).find(".inline_label").each(function(a){a+=1;b(this).html(b(this).html().replace(/(#\d+)/g,
|
||||
"#"+a))})},g=function(){"undefined"!==typeof SelectFilter&&(b(".selectfilter").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!1)}),b(".selectfilterstacked").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!0)}))},h=function(a){a.find(".prepopulated_field").each(function(){var c=b(this).find("input, select, textarea"),d=c.data("dependency_list")||[],e=[];b.each(d,function(b,c){e.push("#"+a.find(".form-row .field-"+c).find("input, select, textarea").attr("id"))});
|
||||
e.length&&c.prepopulate(e,c.attr("maxlength"))})};c.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:f,added:function(a){h(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());g();f(a)},addButton:a.addButton});return c};b(document).ready(function(){b(".js-inline-admin-formset").each(function(){var d=b(this).data(),a=d.inlineFormset;
|
||||
switch(d.inlineType){case "stacked":d=a.name+"-group .inline-related";b(d).stackedFormset(d,a.options);break;case "tabular":d=a.name+"-group .tabular.inline-related tbody:first > tr",b(d).tabularFormset(d,a.options)}})})})(django.jQuery);
|
||||
|
@ -11,7 +11,7 @@ QUnit.module('admin.inlines: tabular formsets', {
|
||||
$('#qunit-fixture').append($('#tabular-formset').text());
|
||||
this.table = $('table.inline');
|
||||
this.inlineRow = this.table.find('tr');
|
||||
that.inlineRow.tabularFormset({
|
||||
that.inlineRow.tabularFormset('table.inline tr', {
|
||||
prefix: 'first',
|
||||
addText: that.addText,
|
||||
deleteText: 'Remove'
|
||||
@ -60,7 +60,7 @@ QUnit.test('existing add button', function(assert) {
|
||||
this.inlineRow = this.table.find('tr');
|
||||
this.table.append('<i class="add-button"></i>');
|
||||
var addButton = this.table.find('.add-button');
|
||||
this.inlineRow.tabularFormset({
|
||||
this.inlineRow.tabularFormset('table.inline tr', {
|
||||
prefix: 'first',
|
||||
deleteText: 'Remove',
|
||||
addButton: addButton
|
||||
|
Loading…
Reference in New Issue
Block a user