+
+ // overload the dismissRelatedLookupPopup function
+ oldDismissRelatedLookupPopup = window.dismissRelatedLookupPopup;
+ window.dismissRelatedLookupPopup = function (win, chosenId) {
+ var name = windowname_to_id(win.name),
+ elem = $('#'+win.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);
+ }