Created
July 6, 2017 13:09
-
-
Save SilencerWeb/d8d9acbb884c0735c85d4a33151e006d to your computer and use it in GitHub Desktop.
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
var _document = $(document), | |
_window = $(window), | |
body = $("body"); | |
var modals = function () { | |
var overlay = $(".overlay"), | |
modalsWrapper = $(".modals-wrapper"), | |
modal = $(".modal"), | |
setTimeout; | |
function compareHeight() { | |
var visibleModal = $(".modal_visible"), | |
visibleModalHeight = visibleModal.innerHeight(), | |
windowHeight = _window.innerHeight(); | |
if (visibleModalHeight > windowHeight) { | |
visibleModal.addClass("modal_relative"); | |
} else if (visibleModalHeight < windowHeight) { | |
visibleModal.removeClass("modal_relative"); | |
} | |
} | |
_window.on("resize", function () { | |
if (modal.hasClass("modal_visible")) { | |
clearTimeout(setTimeout); | |
setTimeout = setTimeout(compareHeight, 100); | |
} | |
}); | |
return { | |
open: function (elem) { | |
var thisModal = $(".modal_" + $(elem).data("modal")); | |
modalsWrapper.addClass("modals-wrapper_visible"); | |
thisModal.addClass("modal_visible"); | |
overlay.addClass("overlay_visible"); | |
body.addClass("body_overflow_hidden"); | |
if (thisModal.innerHeight() > _window.innerHeight()) { | |
thisModal.addClass("modal_relative"); | |
} | |
}, | |
close: function () { | |
modalsWrapper.removeClass("modals-wrapper_visible"); | |
setTimeout(function () { | |
modal.removeClass("modal_visible modal_relative"); | |
overlay.removeClass("overlay_visible"); | |
}, 500); | |
body.removeClass("body_overflow_hidden"); | |
} | |
} | |
}(); | |
_document.on('click', '.open-modal', function (e) { | |
e.preventDefault(); | |
modals.open(this); | |
return false; | |
}); | |
_document.on('click', '.close-modal', function (e) { | |
e.preventDefault(); | |
modals.close(); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment