Last active
August 29, 2015 14:16
-
-
Save huogerac/994fd93786737bd9b340 to your computer and use it in GitHub Desktop.
Two options for using Magnific-Popup JS (Django Template)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<link href="{% static 'bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet"> | |
<link href="{% static 'magnific-popup/dist/magnific-popup.css' %}" rel="stylesheet" media="screen"> | |
<!-- pode ir para o final --> | |
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script> | |
<script src="{% static 'bootstrap/dist/js/bootstrap.min.js' %}"></script> | |
<script src="{% static 'magnific-popup/dist/jquery.magnific-popup.min.js' %}"></script> | |
<script src="{% static 'assets/js/script.js' %}"></script> <!-- POP-UP CODE --> | |
</head> | |
<body id="top"> | |
... | |
<p class="edit-popup"> | |
<a href="{% url '...' %}" class="btn btn-success"> link using pop-up</a> | |
</p> | |
... | |
</body> | |
</html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<link href="{% static 'bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet"> | |
<link href="{% static 'magnific-popup/dist/magnific-popup.css' %}" rel="stylesheet" media="screen"> | |
<!-- pode ir para o final --> | |
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script> | |
<script src="{% static 'magnific-popup/dist/jquery.magnific-popup.min.js' %}"></script> | |
</head> | |
<body id="top"> | |
... | |
<p> | |
<a href="{% url '...' %}" class="btn btn-success" id="btn-link-popup"> link using pop-up</a> | |
</p> | |
... | |
</body> | |
</html> | |
{% block extrajs %} | |
$("#btn-link-popup").click(function(evt) { | |
var magnificPopup = $.magnificPopup.instance; | |
$.ajax({ | |
url: "/url/da/aplicacao/que/sera/aberta/no/popup/", | |
type: "POST", | |
dataType: "json", | |
data: { | |
'csrfmiddlewaretoken': '{{csrf_token}}', | |
}, | |
success: function(data, textStatus, jqXHR) { | |
//TODO: do something here... | |
}, | |
error: function(data, textStatus, jqXHR) { | |
//TODO | |
} | |
}); | |
magnificPopup.close(); | |
evt.preventDefault(); | |
}); | |
{% endblock extrajs %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://dimsemenov.com/plugins/magnific-popup/ | |
$(function() { | |
/* open a modal for each control's block, it can be changed to AJAX instead */ | |
$('.edit-popup a').magnificPopup({ | |
type: 'iframe', | |
closeBtnInside: true, | |
fixedContentPos: true, | |
fixedBgPos: true, | |
overflowY: 'auto', | |
alignTop: true, | |
callbacks: { | |
open: function() { | |
var magnificPopup = $.magnificPopup.instance; | |
}, | |
close: function () { | |
window.location.reload(); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment