Skip to content

Commit a288abc

Browse files
authored
Update defaults, add more options.
1 parent 1abef57 commit a288abc

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

jQuery.leanModal2.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
//// jQuery.leanModal2.js v2.3.2
1+
//// jQuery.leanModal2.js v2.3.3
22
// MIT Licensed by eustasy https://eustasy.org
33
// Based on leanModal v1.1 by Ray Stone - http://finelysliced.com.au
44

55
// ANONFUNC Wrap in an anonymous function.
66
(function($){
77

8-
//// Close the Modal
9-
// FUNCTION: Fade out the overlay and a passed identifier.
10-
function leanModal_Close(modal_id) {
11-
$('.js-leanmodal-overlay').fadeOut(300);
12-
$(modal_id).fadeOut(200);
13-
}
14-
158
//// Extend jQuery
169
// EXTENDFUNC
1710
$.fn.extend({
@@ -21,15 +14,24 @@
2114
//// Default Options
2215
// Set some Defaults.
2316
var defaults = {
24-
top: 100,
25-
overlayOpacity: 0.5,
17+
top: '100px',
18+
overlayOpacity: 0.7,
2619
closeButton: '.js-leanmodal-close',
2720
disableCloseOnOverlayClick: false,
2821
disableCloseOnEscape: false,
22+
fadeTime: 300,
23+
modalCenter: true,
2924
};
3025
// Merge in any passed options.
3126
options = $.extend(defaults, options);
3227

28+
//// Close the Modal
29+
// FUNCTION: Fade out the overlay and a passed identifier.
30+
function leanModal_Close(modal_id) {
31+
$('.js-leanmodal-overlay').fadeOut(options.fadeTime);
32+
$(modal_id).fadeOut(options.fadeTime);
33+
}
34+
3335
//// There can be only one.
3436
// Overlay. If there isn't an overlay, add one.
3537
if ( $('.js-leanmodal-overlay').length == 0 ) {
@@ -96,21 +98,23 @@
9698
// Actually it doesn't, but it is hard to globally position.
9799
var modal_height = $(modal_id).innerHeight();
98100
var modal_width = $(modal_id).innerWidth();
99-
$(modal_id).css({
100-
'display': 'block',
101-
'left': 50 + '%',
102-
'margin-left': - ( modal_width / 2 ) + 'px',
103-
'opacity': 0,
104-
'position': 'fixed',
105-
'top': options.top + 'px',
106-
'z-index': 11000,
107-
});
101+
if ( options.modalCenter ) {
102+
$(modal_id).css({
103+
'display': 'block',
104+
'left': 50 + '%',
105+
'margin-left': - ( modal_width / 2 ) + 'px',
106+
'opacity': 0,
107+
'position': 'fixed',
108+
'top': options.top,
109+
'z-index': 11000,
110+
});
111+
}
108112

109113
//// Curtain Up
110114
// Fade in the modal and overlay.
111115
$('.js-leanmodal-overlay').css({ 'display': 'block', opacity: 0 });
112-
$('.js-leanmodal-overlay').fadeTo(300, options.overlayOpacity);
113-
$(modal_id).fadeTo(200, 1);
116+
$('.js-leanmodal-overlay').fadeTo(options.fadeTime, options.overlayOpacity);
117+
$(modal_id).fadeIn(options.fadeTime);
114118

115119
//// Default Prevention
116120
// Prevent whatever the default was (probably scrolling).

0 commit comments

Comments
 (0)