Skip to content

Instantly share code, notes, and snippets.

@jackabox
Last active December 14, 2015 01:49
Show Gist options
  • Save jackabox/4949fe20344bc06a21ca to your computer and use it in GitHub Desktop.
Save jackabox/4949fe20344bc06a21ca to your computer and use it in GitHub Desktop.
Creating a JS function to fire a reveal model on a link.
<div id="arbitrary-modal" class="reveal-modal medium">
<div class="modal-content"></div>
<a class="close-reveal-modal">&#215;</a>
</div>
function open_reveal(html_element_or_url) {
if ($('.reveal-modal:visible').length > 0) {
close_reveal(function() {
open_reveal(html_element_or_url)
});
return;
}
if (typeof(html_element_or_url) == 'string' && html_element_or_url.substr(0, 4) == 'http') {
$('#arbitrary-modal .modal-content').html("<h2>Loading, please wait...</h2>");
$('#arbitrary-modal').bind('reveal:opened.reveal', function() {
$.get(html_element_or_url, function(data) {
$('#arbitrary-modal').html(data).trigger('loaded_festival_reveal');
});
}).reveal();
return;
} else {
$('#arbitrary-modal .modal-content').html(html_element_or_url);
$('#arbitrary-modal').reveal();
}
}
$(".fire-ajax").click(function (e){
open_reveal($(this).attr('href')); return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment