From 695fada52d5dcd731b815a5dcc52529540ed5b02 Mon Sep 17 00:00:00 2001 From: Martin Gonzalez Robles Date: Wed, 12 Sep 2018 12:48:20 +0200 Subject: [PATCH] I included spaces from previous commits #63 --- animatedModal.js | 127 +++++++++++++++++++++++---------------- demo/js/animatedModal.js | 8 +-- 2 files changed, 78 insertions(+), 57 deletions(-) diff --git a/animatedModal.js b/animatedModal.js index dd96ec0..9f968fa 100644 --- a/animatedModal.js +++ b/animatedModal.js @@ -7,48 +7,62 @@ =========================================*/ (function ($) { - + $.fn.animatedModal = function(options) { var modal = $(this); - + //Defaults var settings = $.extend({ - modalTarget:'animatedModal', - position:'fixed', - width:'100%', - height:'100%', - top:'0px', - left:'0px', - zIndexIn: '9999', - zIndexOut: '-9999', - color: '#39BEB9', - opacityIn:'1', - opacityOut:'0', + modalTarget:'animatedModal', + position:'fixed', + width:'100%', + height:'100%', + top:'0px', + left:'0px', + zIndexIn: '9999', + zIndexOut: '-9999', + color: '#39BEB9', + opacityIn:'1', + opacityOut:'0', animatedIn:'zoomIn', animatedOut:'zoomOut', - animationDuration:'.6s', - overflow:'auto', + animationDuration:'.6s', + overflow:'auto', // Callbacks - beforeOpen: function() {}, - afterOpen: function() {}, - beforeClose: function() {}, - afterClose: function() {} - - + beforeOpen: function() {}, + afterOpen: function() {}, + beforeClose: function() {}, + afterClose: function() {}, + close: function(event) { + event.preventDefault(); + $('body, html').css({'overflow':'auto'}); + + settings.beforeClose(); //beforeClose + if (id.hasClass(settings.modalTarget+'-on')) { + id.removeClass(settings.modalTarget+'-on'); + id.addClass(settings.modalTarget+'-off'); + } + + if (id.hasClass(settings.modalTarget+'-off')) { + id.removeClass(settings.animatedIn); + id.addClass(settings.animatedOut); + id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterClose); + }; + } }, options); - - var closeBt = $('.close-'+settings.modalTarget); - //console.log(closeBt) + var closeBt = $('.close-'+settings.modalTarget); + var nextBt = $('.next-'+settings.modalTarget); + var previousBt = $('.previous-'+settings.modalTarget); var href = $(modal).attr('href'), id = $('body').find('#'+settings.modalTarget), idConc = '#'+id.attr('id'); - //console.log(idConc); - // Default Classes - id.addClass('animated'); - id.addClass(settings.modalTarget+'-off'); + //console.log(idConc); + // Default Classes + id.addClass('animated'); + id.addClass(settings.modalTarget+'-off'); //Init styles var initStyles = { @@ -61,15 +75,12 @@ 'overflow-y':settings.overflow, 'z-index':settings.zIndexOut, 'opacity':settings.opacityOut, - '-webkit-animation-duration':settings.animationDuration, - '-moz-animation-duration':settings.animationDuration, - '-ms-animation-duration':settings.animationDuration, - 'animation-duration':settings.animationDuration + '-webkit-animation-duration':settings.animationDuration }; //Apply stles id.css(initStyles); - modal.click(function(event) { + modal.click(function(event) { event.preventDefault(); $('body, html').css({'overflow':'hidden'}); if (href == idConc) { @@ -77,50 +88,60 @@ id.removeClass(settings.animatedOut); id.removeClass(settings.modalTarget+'-off'); id.addClass(settings.modalTarget+'-on'); - } + } if (id.hasClass(settings.modalTarget+'-on')) { settings.beforeOpen(); id.css({'opacity':settings.opacityIn,'z-index':settings.zIndexIn}); - id.addClass(settings.animatedIn); + id.addClass(settings.animatedIn); id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterOpen); - }; - } + }; + } }); closeBt.click(function(event) { - event.preventDefault(); - $('body, html').css({'overflow':'auto'}); - - settings.beforeClose(); //beforeClose - if (id.hasClass(settings.modalTarget+'-on')) { - id.removeClass(settings.modalTarget+'-on'); - id.addClass(settings.modalTarget+'-off'); - } + settings.close(event); + }); - if (id.hasClass(settings.modalTarget+'-off')) { - id.removeClass(settings.animatedIn); - id.addClass(settings.animatedOut); - id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterClose); - }; + nextBt.click(function(event) { + settings.close(event); + $(settings.next).click(); + }); + previousBt.click(function(event) { + settings.close(event); + $(settings.previous).click(); }); - function afterClose () { + function afterClose () { id.css({'z-index':settings.zIndexOut}); settings.afterClose(); //afterClose } - function afterOpen () { + function afterOpen () { settings.afterOpen(); //afterOpen } + function afterNext () { + settings.afterNext(); //afterOpen + } + + function afterPrevious () { + settings.afterPrevious(); //afterOpen + } + + // close modal menu if esc key is used + $(document).keyup(function(event){ + if(event.keyCode == 27) { + settings.close(event); + } + }); + }; // End animatedModal.js }(jQuery)); - diff --git a/demo/js/animatedModal.js b/demo/js/animatedModal.js index 70b16e4..c1c2740 100644 --- a/demo/js/animatedModal.js +++ b/demo/js/animatedModal.js @@ -59,10 +59,10 @@ var href = $(modal).attr('href'), id = $('body').find('#'+settings.modalTarget), idConc = '#'+id.attr('id'); - //console.log(idConc); - // Default Classes - id.addClass('animated'); - id.addClass(settings.modalTarget+'-off'); + //console.log(idConc); + // Default Classes + id.addClass('animated'); + id.addClass(settings.modalTarget+'-off'); //Init styles var initStyles = {