Fixed django 1.7 and django 1.9 compatibility
parent
71ad991ba7
commit
ed669a88be
|
|
@ -22,13 +22,23 @@
|
|||
var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
|
||||
switch(initData.action){
|
||||
case 'change':
|
||||
if( typeof(openerRef.dismissChangeRelatedObjectPopup) == 'function' ){
|
||||
openerRef.dismissChangeRelatedObjectPopup(modalRef, initData.value, initData.obj, initData.new_value);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if( typeof(openerRef.dismissDeleteRelatedObjectPopup) == 'function' ){
|
||||
openerRef.dismissDeleteRelatedObjectPopup(modalRef, initData.value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if( typeof(openerRef.dismissAddRelatedObjectPopup) == 'function' ){
|
||||
openerRef.dismissAddRelatedObjectPopup(modalRef, initData.value, initData.obj);
|
||||
}
|
||||
else if( typeof(openerRef.dismissAddAnotherPopup) == 'function' ){
|
||||
// django 1.7 compatibility
|
||||
openerRef.dismissAddAnotherPopup(modalRef, initData.value, initData.obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -7,18 +7,23 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
|
|||
// create the function that will close the modal
|
||||
function dismissRelatedObjectModal()
|
||||
{
|
||||
// close the popup
|
||||
// close the popup as modal
|
||||
$.magnificPopup.close();
|
||||
}
|
||||
|
||||
// assign the function to a global variable
|
||||
window.dismissRelatedObjectModal = dismissRelatedObjectModal;
|
||||
|
||||
// listen click events on related links
|
||||
// (:link prevents to listen click event if href is not defined)
|
||||
$('a.related-widget-wrapper-link:link').click(function(e){
|
||||
function presentRelatedObjectModal(e)
|
||||
{
|
||||
var href = ($(this).attr('href') || '');
|
||||
if( href == '' ){
|
||||
return;
|
||||
}
|
||||
|
||||
// open the popup as modal
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
// remove focus from clicked link
|
||||
$(this).blur();
|
||||
|
|
@ -32,7 +37,14 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
|
|||
// browsers stop loading nested iframes having the same src url
|
||||
// create a random parameter and append it to the src url to prevent it
|
||||
var iframeSrcRandom = String(Math.round(Math.random() * 999999));
|
||||
var iframeSrc = $(this).attr('href') + '&_modal=' + iframeSrcRandom;
|
||||
var iframeSrc = href;
|
||||
|
||||
// fix for django 1.7
|
||||
if( iframeSrc.indexOf('_popup=1') == -1 ){
|
||||
iframeSrc += '&_popup=1';
|
||||
}
|
||||
|
||||
iframeSrc += '&_modal=' + iframeSrcRandom;
|
||||
|
||||
// build the iframe html
|
||||
// var iframeHTML = '<iframe id="related-modal" name="' + iframeName + '" src="' + iframeSrc + '"></iframe>';
|
||||
|
|
@ -61,7 +73,16 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
|
|||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// listen click events on related links
|
||||
|
||||
// django 1.7 compatibility
|
||||
$('a.add-another').removeAttr('onclick');
|
||||
$('a.add-another').click( presentRelatedObjectModal );
|
||||
|
||||
// django 1.8 and above
|
||||
$('a.related-widget-wrapper-link').click( presentRelatedObjectModal );
|
||||
});
|
||||
|
||||
})(django.jQuery);
|
||||
|
|
|
|||
Loading…
Reference in New Issue