|
231 | 231 | * In django >= 1.10 we could try to rely on input.trigger('change')
|
232 | 232 | * and avoid this hijacking, but the id and repr isn't passed.
|
233 | 233 | */
|
234 |
| - djangoJQuery(document).ready(function () { |
235 |
| - var djangoDismissAddRelatedObjectPopup = |
236 |
| - window.dismissAddRelatedObjectPopup; |
237 |
| - if (!djangoDismissAddRelatedObjectPopup) { |
238 |
| - throw new Error("dismissAddAnotherPopup not found"); |
239 |
| - } |
240 |
| - |
241 |
| - window.dismissAddRelatedObjectPopup = function (win, newId, newRepr) { |
242 |
| - // Iff this is an ajax-select input then close the window and |
243 |
| - // trigger didAddPopup |
244 |
| - var input = $("#" + win.name.replace("__1", "")); |
245 |
| - if (input.length && input.data("ajax-select")) { |
246 |
| - win.close(); |
247 |
| - // note: newRepr is django's repr of object, not the Lookup's formatting of it. |
248 |
| - input.trigger("didAddPopup", [newId, newRepr]); |
249 |
| - } else { |
250 |
| - // Call the normal django set and close function. |
251 |
| - djangoDismissAddRelatedObjectPopup(win, newId, newRepr); |
| 234 | + if (djangoJQuery) { |
| 235 | + djangoJQuery(document).ready(function () { |
| 236 | + var djangoDismissAddRelatedObjectPopup = |
| 237 | + window.dismissAddRelatedObjectPopup; |
| 238 | + if (!djangoDismissAddRelatedObjectPopup) { |
| 239 | + throw new Error("dismissAddAnotherPopup not found"); |
252 | 240 | }
|
253 |
| - }; |
254 |
| - }); |
255 |
| -})(window.jQuery, window.django.jQuery); |
| 241 | + |
| 242 | + window.dismissAddRelatedObjectPopup = function (win, newId, newRepr) { |
| 243 | + // Iff this is an ajax-select input then close the window and |
| 244 | + // trigger didAddPopup |
| 245 | + var input = $("#" + win.name.replace("__1", "")); |
| 246 | + if (input.length && input.data("ajax-select")) { |
| 247 | + win.close(); |
| 248 | + // note: newRepr is django's repr of object, not the Lookup's formatting of it. |
| 249 | + input.trigger("didAddPopup", [newId, newRepr]); |
| 250 | + } else { |
| 251 | + // Call the normal django set and close function. |
| 252 | + djangoDismissAddRelatedObjectPopup(win, newId, newRepr); |
| 253 | + } |
| 254 | + }; |
| 255 | + }); |
| 256 | + } |
| 257 | +})(window.jQuery, window.django && window.django.jQuery); |
0 commit comments