PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.3
1.8.13.1 1.8.13 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 All 212 releases
charitable / assets / js / libraries / leanModal.js

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

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