Fixed django 1.7 and django 1.9 compatibility
This commit is contained in:
@@ -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();
|
||||
@@ -26,16 +31,23 @@ if(typeof django !== 'undefined' && typeof django.jQuery !== 'undefined' )
|
||||
// use the clicked link id as iframe name
|
||||
// it will be available as window.name in the loaded iframe
|
||||
var iframeName = $(this).attr('id');
|
||||
//var iframeName = String(window.name + '____' + $(this).attr('id'));
|
||||
//console.log('open modal with name: "' + iframeName + '"');
|
||||
// var iframeName = String(window.name + '____' + $(this).attr('id'));
|
||||
// console.log('open modal with name: "' + iframeName + '"');
|
||||
|
||||
// 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>';
|
||||
// var iframeHTML = '<iframe id="related-modal" name="' + iframeName + '" src="' + iframeSrc + '"></iframe>';
|
||||
var iframeHTML = '<iframe id="related-modal-iframe" name="' + iframeName + '" src="' + iframeSrc + '"></iframe>';
|
||||
|
||||
// create the iframe jquery element
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user