|
1 | | -//// jQuery.leanModal2.js v2.6.2 |
| 1 | +//// jQuery.leanModal2.js v2.6.3 |
2 | 2 | // MIT Licensed by eustasy https://eustasy.org |
3 | 3 | // Based on leanModal v1.1 by Ray Stone - http://finelysliced.com.au |
4 | 4 |
|
|
16 | 16 | //// Default Options |
17 | 17 | // Set some Defaults. |
18 | 18 | var defaults = { |
19 | | - overlayOpacity: 0.7, |
| 19 | + defaultStyles: true, // GLOBAL |
| 20 | + fadeTime: 200, // GLOBAL |
| 21 | + overlayOpacity: 0.7, // GLOBAL |
20 | 22 | closeButton: '.js-leanmodal-close', |
21 | 23 | disableCloseOnOverlayClick: false, |
22 | 24 | disableCloseOnEscape: false, |
23 | | - fadeTime: 200, |
24 | 25 | modalCenter: true, |
25 | 26 | } |
26 | 27 | // Merge in any passed options. |
27 | 28 | options = $.extend(defaults, options) |
28 | 29 |
|
| 30 | + //// Default styles |
| 31 | + if ( options.defaultStyles ) { |
| 32 | + if ( $('#js-leanmodal-styles').length == 0 ) { |
| 33 | + $('<style>') |
| 34 | + .prop('type', 'text/css') |
| 35 | + .prop('id', 'js-leanmodal-styles') |
| 36 | + .html('\ |
| 37 | + @keyframes smoothFadeOut {\ |
| 38 | + from { opacity: 1; }\ |
| 39 | + to { opacity: 0; }\ |
| 40 | + }\ |
| 41 | + @keyframes smoothFadeIn {\ |
| 42 | + from { opacity: 0; }\ |
| 43 | + to { opacity: 1; }\ |
| 44 | + }\ |
| 45 | + #js-leanmodal-overlay {\ |
| 46 | + align-items: center;\ |
| 47 | + background: rgba(0, 0, 0, ' + options.overlayOpacity + ');\ |
| 48 | + display: none;\ |
| 49 | + height: 100%;\ |
| 50 | + justify-content: center;\ |
| 51 | + left: 0;\ |
| 52 | + position: fixed;\ |
| 53 | + top: 0;\ |
| 54 | + width: 100%;\ |
| 55 | + }\ |
| 56 | + .js-leanmodal-link {\ |
| 57 | + cursor: pointer;\ |
| 58 | + }\ |
| 59 | + .js-leanmodal-inactive {\ |
| 60 | + animation: smoothFadeOut ' + options.fadeTime + 'ms ease-in-out both;\ |
| 61 | + }\ |
| 62 | + .js-leanmodal-active {\ |
| 63 | + animation: smoothFadeIn ' + options.fadeTime + 'ms ease-in-out both;\ |
| 64 | + display: block;\ |
| 65 | + z-index: 1000\ |
| 66 | + }\ |
| 67 | + #js-leanmodal-overlay.js-leanmodal-active {\ |
| 68 | + display: flex;\ |
| 69 | + z-index: 100;\ |
| 70 | + }' |
| 71 | + ).appendTo('head') |
| 72 | + } |
| 73 | + } |
| 74 | + |
29 | 75 | //// Close the Modal |
30 | 76 | // FUNCTION: Fade out the overlay and a passed identifier. |
31 | 77 | function leanModal_Close(modal_id) { |
32 | | - $('#js-leanmodal-overlay').fadeOut(options.fadeTime) |
33 | | - $(modal_id).fadeOut(options.fadeTime) |
| 78 | + $('#js-leanmodal-overlay').removeClass('js-leanmodal-active').addClass('js-leanmodal-inactive') |
| 79 | + $(modal_id).removeClass('js-leanmodal-active').addClass('js-leanmodal-inactive') |
34 | 80 | $('#js-leanmodal-overlay').unbind('click') |
35 | 81 | $(document).off('keyup') |
36 | 82 | $(modal_id).appendTo('body') |
37 | | - $('#js-leanmodal-overlay').remove() |
38 | 83 | } |
39 | 84 |
|
40 | 85 | //// Everything is Linked |
41 | 86 | // FOREACHLINK For each targeted link. |
42 | 87 | return this.each(function() { |
43 | 88 | // Force this to look like a link. |
44 | | - $(this).css({ 'cursor': 'pointer' }) |
| 89 | + $(this).addClass('js-leanmodal-link') |
45 | 90 |
|
46 | 91 | //// Command Override |
47 | 92 | // Override the existing click command, |
|
85 | 130 | //// There can be only one. |
86 | 131 | // Overlay. If there isn't an overlay, add one. |
87 | 132 | if ( $('#js-leanmodal-overlay').length == 0 ) { |
88 | | - var style = |
89 | | - 'background: rgba(0, 0, 0, ' + |
90 | | - options.overlayOpacity + |
91 | | - '); display: none; height: 100%; left: 0; position: fixed; top: 0; width: 100%; z-index: 100; ' + |
92 | | - 'align-items: center; justify-content: center;' |
93 | | - var overlay = $('<div id="js-leanmodal-overlay" style="' + style + '"></div>') |
| 133 | + var overlay = $('<div id="js-leanmodal-overlay"></div>') |
94 | 134 | $('body').append(overlay) |
95 | 135 | } |
96 | 136 |
|
|
106 | 146 | } |
107 | 147 |
|
108 | 148 | //// Modal Positioning |
109 | | - // Position the modal centrally using JavaScript, because CSS sucks. |
110 | | - // Actually it doesn't, but it is hard to globally position. |
111 | | - //var modal_height = $(modal_id).innerHeight() |
112 | | - //var modal_width = $(modal_id).innerWidth() |
| 149 | + // Position the modal centrally inside the overlay using flexbox. |
113 | 150 | if ( options.modalCenter ) { |
114 | | - $(modal_id).css({ |
115 | | - 'display': 'block', |
116 | | - 'opacity': 0, |
117 | | - 'z-index': 11000, |
118 | | - }) |
119 | 151 | $(modal_id).appendTo('#js-leanmodal-overlay') |
120 | 152 | } |
121 | 153 |
|
122 | 154 | //// Curtain Up |
123 | 155 | // Fade in the modal and overlay. |
124 | | - $('#js-leanmodal-overlay').css({ 'display': 'flex', opacity: 0 }) |
125 | | - $('#js-leanmodal-overlay').fadeTo(options.fadeTime, 1) |
126 | | - $(modal_id).fadeTo(options.fadeTime, 1) |
| 156 | + $('#js-leanmodal-overlay').removeClass('js-leanmodal-inactive').addClass('js-leanmodal-active') |
| 157 | + $(modal_id).removeClass('js-leanmodal-inactive').addClass('js-leanmodal-active') |
127 | 158 |
|
128 | 159 | //// Default Prevention |
129 | 160 | // Prevent whatever the default was (probably scrolling). |
|
0 commit comments