X-Git-Url: http://git.ieval.ro/?p=plack-app-gruntmaster.git;a=blobdiff_plain;f=js%2F10-modal.js;h=980bab79a987ae6001413765e665d6fb7390d69c;hp=30da26750d149e2fcb210fcab835605cb53c4861;hb=7093e9ba00cf7727a52a49d34d4df12e4f865dd4;hpb=d5bf9a1d1fc3583bc058a90ce28efeb34819744b diff --git a/js/10-modal.js b/js/10-modal.js index 30da267..980bab7 100644 --- a/js/10-modal.js +++ b/js/10-modal.js @@ -1,30 +1,32 @@ -;(function(){ - 'use strict'; +var modal, hiding; - function show_modal () { - $('.modal').removeClass('hidden'); - setTimeout(function (){ - $('body').addClass('modal-open'); - }, 20); - } +function show_modal () { + modal.classList.remove('hidden'); + setTimeout(function (){ + document.body.classList.add('modal-open'); + }, 20); +} - function hide_modal () { - $('body').removeClass('modal-open'); - $('.modal').one('transitionend', function (){ - $('.modal').addClass('hidden'); - }); - } +function hide_modal () { + document.body.classList.remove('modal-open'); +} - $( document ).ready(function() { - $('.backdrop,.modal').detach().appendTo('body'); - $('#solution').on('click', function (e){ - show_modal(); - e.preventDefault(); - }); - $('.backdrop').on('click', hide_modal); - window.onkeyup = function (event) { - if (event.keyCode === 27) - hide_modal(); - } +$(function() { + modal = $('.modal')[0]; + $(modal).on('transitionend', function (){ + if(!document.body.classList.contains('modal-open')) + modal.classList.add('hidden'); + }); + $('.backdrop,.modal').each(function(el){ + document.body.appendChild(el); }); -})(); + $('#solution').on('click', function (e){ + show_modal(); + e.preventDefault(); + }); + $('.backdrop').on('click', hide_modal); + window.onkeyup = function (event) { + if (event.keyCode === 27) + hide_modal(); + } +});