PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.0
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / assets / js / libraries / leanModal.js

leanModal.js in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.0, at assets/js/libraries/leanModal.js

194 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( $, document ) {
2 var $body,
3 $overlay,
4 options;
5
6 var setup = (function() {
7 var done = false;
8
9 return function( $trigger, params ) {
10 if ( done ) {
11 return;
12 }
13
14 options = $.extend({
15 verticalOffset: 100,
16 overlay: 0.5,
17 closeButton: null
18 }, params);
19 options.verticalOffset = parseInt(options.verticalOffset);
20
21 $body = $( 'body' );
22 $body.append( $( '<div id="lean_overlay"></div>' ) );
23
24 $overlay = $( '#lean_overlay' );
25
26 $trigger.on( 'click', function(e) {
27 var modal_id = methods.get_target($(this)),
28 $modal = $(modal_id);
29
30 methods.open( $modal, e );
31
32 $modal.on( 'click', options.closeButton, function(e){
33 methods.close( $modal );
34 e.preventDefault();
35 });
36
37 $overlay.on( 'click', function() {
38 methods.close( $modal );
39 });
40
41 $(document).on( 'keyup', function(e) {
42 return 27 === e.keyCode && methods.close( $modal );
43 });
44
45 e.preventDefault();
46 });
47
48 done = true;
49 }
50 })();
51
52 /**
53 * General API methods.
54 */
55 var methods = {
56
57 /**
58 * Main fn method
59 */
60 init : function( params ) {
61 setup(this, params);
62 },
63
64 /**
65 * Open modal.
66 */
67 open : function( $modal ) {
68 var resize = function() {
69 methods.resize($modal);
70 };
71
72 $overlay.css({
73 'display': 'block',
74 'opacity': 0,
75 }).fadeTo(200, options.overlay);
76
77 $modal.css({
78 'display': 'block',
79 'position': 'fixed',
80 'opacity': 0,
81 'z-index': 100000,
82 }).fadeTo(200, 1);
83
84 resize();
85 $modal.resize( resize );
86 $(window).resize( resize );
87
88 $modal.trigger( 'focus' );
89
90 /* Provide an event hook for other scripts to use. */
91 $body.trigger( 'charitable:modal:open' );
92 },
93
94 /**
95 * Return the ID of the modal to open.
96 */
97 get_target : function( $trigger ) {
98 var id = '#' + $trigger.data( 'trigger-modal' );
99
100 if ( 1 === id.length ) {
101 id = $trigger.attr( "href" );
102 }
103
104 return id;
105 },
106
107 /**
108 * Close modal
109 */
110 close : function( $modal ) {
111 $overlay.fadeOut( 200 );
112 $modal.hide();
113 methods.reset( $modal );
114
115 /* Provide an event hook for other scripts to use. */
116 $body.trigger( 'charitable:modal:close', $modal );
117 },
118
119 /**
120 * Reset modal CSS
121 */
122 reset : function( $modal ) {
123 $modal.css({
124 'bottom' : 'auto',
125 'overflowY' : 'auto'
126 });
127 },
128
129 /**
130 * Resize modal
131 */
132 resize : function( $modal ) {
133 var window_height = $(window).height(),
134 modal_width = $modal.outerWidth(),
135 modal_height = $modal.outerHeight()
136 available_offset = window_height - modal_height,
137 modal_is_too_tall = ( function() {
138 var modal_calc_height = modal_height + ( 2 * options.verticalOffset );
139 return window_height < modal_calc_height;
140 })(),
141 modal_css = {
142 'left' : 50 + '%',
143 'margin-left' : -( modal_width / 2 ) + "px",
144 'top' : options.verticalOffset + "px"
145 };
146
147 if ( modal_is_too_tall ) {
148 if ( available_offset > 0 ) {
149 var v_offset = available_offset / 2;
150
151 modal_css.top = v_offset + 'px';
152 modal_css.bottom = v_offset + 'px';
153 }
154
155 if ( available_offset <= 0 ) {
156 modal_css.top = '10px';
157 modal_css.bottom = '10px';
158 modal_css.overflowY = 'scroll';
159 }
160 }
161
162 $modal.css( modal_css );
163
164 /* Provide an event hook for other scripts to use. */
165 $body.trigger( 'charitable:modal:resize' );
166 }
167 };
168
169 /**
170 * Register this as a jQuery function.
171 */
172 $.fn.extend({
173 leanModal : function( method_or_options ) {
174 if ( methods[ method_or_options ] ) {
175 return methods[ method_or_options ].apply( this, Array.prototype.slice.call( arguments, 1 ));
176 } else if ( typeof method_or_options === 'object' || ! method_or_options ) {
177 // Default to "init"
178 return methods.init.apply( this, arguments );
179 } else {
180 $.error( 'Method ' + method_or_options + ' does not exist on jQuery.leanModal' );
181 }
182 }
183 });
184
185 /**
186 * Init function.
187 */
188 $(document).ready( function() {
189 $( '[data-trigger-modal]' ).leanModal({
190 closeButton : ".modal-close"
191 });
192 });
193
194 })(jQuery, document);