X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F10-modal.js;h=1c290ef1252ce3d236f7c4208efd3fd45c4f3704;hb=8345760abf4953980a85e0d5f9cade421f73d4ff;hp=30da26750d149e2fcb210fcab835605cb53c4861;hpb=0f578ab0f7b5798b2b27fb94901e99303da855a2;p=plack-app-gruntmaster.git diff --git a/js/10-modal.js b/js/10-modal.js index 30da267..1c290ef 100644 --- a/js/10-modal.js +++ b/js/10-modal.js @@ -1,30 +1,30 @@ -;(function(){ - 'use strict'; +let 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', el => { + if(!document.body.classList.contains('modal-open')) + modal.classList.add('hidden'); }); -})(); + $('.backdrop,.modal').each(el => document.body.appendChild(el) ); + $('#solution').on('click', e => { + show_modal(); + e.preventDefault(); + }); + $('.backdrop').on('click', hide_modal); + window.onkeyup = event => { + if (event.keyCode === 27) + hide_modal(); + } +});