Created
November 7, 2019 09:34
-
-
Save ivan-kalachikov/9f18dbf34db316c33468241f93fd50f3 to your computer and use it in GitHub Desktop.
Modal Age Confirm
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
<div class="age-confirm-popup popup mfp-hide" data-url="not-allowed.html"> | |
<div class="inner"> | |
<div class="wrap"> | |
<h2 class="title">Are you over age 21?</h2> | |
<a href="#" class="btn btn-cancel">No</a> | |
<a href="#" class="btn btn-submit">Yes</a> | |
</div> | |
</div> | |
</div> | |
$.magnificPopup.open({ | |
modal: true, | |
items: { | |
src: $('.age-confirm-popup'), | |
type: 'inline' | |
}, | |
callbacks: { | |
open: function() { | |
var $content = $(this.content); | |
var url = $content.data('url'); | |
$content.on('click', '.btn-submit', function() { | |
$.magnificPopup.close(); | |
$(document).off('keydown', keydownHandler); | |
}); | |
$content.on('click', '.btn-cancel', function() { | |
$.magnificPopup.close(); | |
window.location.replace(url); | |
$(document).off('keydown', keydownHandler); | |
}); | |
var keydownHandler = function (e) { | |
if (e.keyCode == 13) { | |
$content.find('.btn-submit').click(); | |
return false; | |
} else if (e.keyCode == 27) { | |
$content.find('.btn-cancel').click(); | |
return false; | |
} | |
}; | |
$(document).on('keydown', keydownHandler); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment