+
+ // overload the dismissRelatedLookupPopup function
+ oldDismissRelatedLookupPopup = window.dismissRelatedLookupPopup;
+ window.dismissRelatedLookupPopup = function (win, chosenId) {
+ var name = windowname_to_id(win.name),
+ elem = $('#'+name), val;
+ // if the original element was an embed widget, run our script
+ if (elem.parent().hasClass('embed-widget')) {
+ contenttype = $('select',elem.parent()).val();
+ widget.appendEmbed(elem, contenttype, chosenId);
+ elem.focus();
+ win.close();
+ return;
+ }
+ // otherwise, do what you usually do
+ oldDismissRelatedLookupPopup.apply(this, arguments);
+ }
+
+ // overload the dismissAddAnotherPopup function
+ oldDismissAddAnotherPopup = window.dismissAddAnotherPopup;
+ window.dismissAddAnotherPopup = function (win, newId, newRepr) {
+ var name = windowname_to_id(win.name),
+ elem = $('#'+win.name), val;
+ if (elem.parent().hasClass('embed-widget')) {
+ dismissRelatedLookupPopup(win, newId);
+ }
+ // otherwise, do what you usually do
+ oldDismissAddAnotherPopup.apply(this, arguments);
+ }
+
+ // Add grappelli to the body class if the admin is grappelli. This will allow us to customize styles accordingly.
+ if (window.grappelli) {
+ $(document.body).addClass('grappelli');
+ }