PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.1
GiveWP – Donation Plugin and Fundraising Platform v2.0.1
4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / assets / js / frontend / give.js
give / assets / js / frontend Last commit date
give-ajax.js 8 years ago give-ajax.min.js 8 years ago give-donations.js 8 years ago give-donations.min.js 8 years ago give.all.min.js 8 years ago give.js 8 years ago give.min.js 8 years ago
give.js
313 lines
1 /*!
2 * Give JS
3 *
4 * @description: Scripts that power the Give experience
5 * @package: Give
6 * @subpackage: Assets/JS
7 * @copyright: Copyright (c) 2016, WordImpress
8 * @license: http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 */
10
11 var give_scripts;
12 var give_float_labels;
13
14 jQuery( function( $ ) {
15
16 var doc = $( document );
17
18 // Trigger float-labels
19 give_fl_trigger();
20
21 // Set custom validation message.
22 give_change_html5_form_field_validation_message();
23
24 // Disable button if it have give-disabled class init.
25 doc.on( 'click touchend', '.give-disabled', function ( e ) {
26 e.preventDefault();
27 return false;
28 } );
29
30 doc.on( 'give_gateway_loaded', function( ev, response, form_id ) {
31 // Trigger float-labels
32 give_fl_trigger();
33 } );
34
35 doc.on( 'give_checkout_billing_address_updated', function( ev, response, form_id ) {
36 if ( ! $( 'form#' + form_id ).hasClass( 'float-labels-enabled' ) ) return;
37 // Trigger float-labels
38 give_fl_trigger();
39 } );
40
41 // Reveal Btn which displays the checkout content
42 doc.on( 'click', '.give-btn-reveal', function( e ) {
43 e.preventDefault();
44 var this_button = $( this );
45 var this_form = $( this ).parents( 'form' );
46 var payment_field_id = '#give-payment-mode-select',
47 $payment_field = $( payment_field_id ),
48 show_field_ids = '';
49 this_button.hide();
50
51 // Show payment field if active payment gateway count greater then one.
52 if ( $( 'li', $payment_field ).length > 1 ) {
53 show_field_ids = payment_field_id + ', ';
54 }
55
56 this_form.find( show_field_ids + '#give_purchase_form_wrap' ).slideDown();
57 return false;
58 } );
59
60 // Modal with Magnific
61 doc.on( 'click', '.give-btn-modal', function( e ) {
62 e.preventDefault();
63 var this_form_wrap = $( this ).parents( 'div.give-form-wrap' );
64 var this_form = this_form_wrap.find( 'form.give-form' );
65 var this_amount_field = this_form.find( '#give-amount' );
66 var this_amount = this_amount_field.val();
67
68 //Check to ensure our amount is greater than 0
69 //Does this number have a value
70 if ( ! this_amount || this_amount <= 0 ) {
71 this_amount_field.focus();
72 return false;
73 }
74
75 give_open_form_modal( this_form_wrap, this_form );
76
77 } );
78
79 // Auto hide frontend notices.
80 var give_notices = jQuery( '.give_notice[data-dismissible="auto"]' );
81 if ( give_notices.length ) {
82 give_notices.each( function( index, $notice ) {
83 $notice = $( $notice );
84
85 // auto hide setting message in 5 seconds.
86 window.setTimeout(
87 function() {
88 $notice.slideUp();
89 },
90 $notice.data( 'dismiss-interval' )
91 );
92 } );
93 }
94
95 doc.on( 'change', '#give_profile_billing_address_wrap #give_address_country', update_profile_state_field );
96
97 } );
98
99 /**
100 * Open form modal
101 *
102 * @param $form_wrap
103 * @param $form
104 */
105 function give_open_form_modal( $form_wrap, $form ) {
106 // Hide form children.
107 var children = '#give_purchase_form_wrap, #give-payment-mode-select, .mfp-close, .give-hidden';
108
109 //Alls well, open popup!
110 jQuery.magnificPopup.open( {
111 mainClass: give_global_vars.magnific_options.main_class,
112 closeOnBgClick: give_global_vars.magnific_options.close_on_bg_click,
113 fixedContentPos: true,
114 fixedBgPos: true,
115 removalDelay: 250, //delay removal by X to allow out-animation
116 items: {
117 src: $form,
118 type: 'inline'
119 },
120 callbacks: {
121 beforeOpen: function() {
122
123 jQuery( 'body' ).addClass( 'give-modal-open' );
124
125 // add title, content, goal and error to form if admin want to show button only
126 if ( $form_wrap.hasClass( 'give-display-button-only' ) && ! $form.data( 'content' ) ) {
127
128 var $form_content = jQuery( '.give-form-content-wrap', $form_wrap ),
129 $form_title = jQuery( '.give-form-title', $form_wrap ),
130 $form_goal = jQuery( '.give-goal-progress', $form_wrap ),
131 $form_error = jQuery( '>.give_error', $form_wrap ),
132 $form_errors = jQuery( '.give_errors', $form_wrap );
133
134 // Add content container to form.
135 if ( $form_content.length && ! jQuery( '.give-form-content-wrap', $form ).length ) {
136 if ( $form_content.hasClass( 'give_post_form-content' ) ) {
137 $form.append( $form_content );
138 } else {
139 $form.prepend( $form_content );
140 }
141 }
142
143 // Add errors container to form.
144 if ( $form_errors.length && ! jQuery( '.give_errors', $form ).length ) {
145 $form_errors.each( function( index, $error ) {
146 $form.prepend( jQuery( $error ) );
147 } );
148 }
149
150 // Add error container to form.
151 if ( $form_error.length && ! jQuery( '>.give_error', $form ).length ) {
152 $form_error.each( function( index, $error ) {
153 $form.prepend( jQuery( $error ) );
154 } );
155 }
156
157 // Add goal container to form.
158 if ( $form_goal.length && ! jQuery( '.give-goal-progress', $form ).length ) {
159 $form.prepend( $form_goal );
160 }
161
162 // Add title container to form.
163 if ( $form_title.length && ! jQuery( '.give-form-title', $form ).length ) {
164 $form.prepend( $form_title );
165 }
166
167 $form.data( 'content', 'loaded' );
168 }
169 },
170 open: function() {
171
172 // Will fire when this exact popup is opened
173 // this - is Magnific Popup object
174 var $mfp_content = jQuery( '.mfp-content' );
175 if ( $mfp_content.outerWidth() >= 500 ) {
176 $mfp_content.addClass( 'give-responsive-mfp-content' );
177 }
178
179 // Hide .give-hidden and .give-btn-modal if admin only want to show only button.
180 if ( $form_wrap.hasClass( 'give-display-button-only' ) ) {
181 children = $form.children().not( '.give-hidden, .give-btn-modal' );
182 }
183
184 //Hide all form elements besides the ones required for payment
185 $form.children().not( children ).hide();
186 },
187 close: function() {
188 //Remove popup class
189 $form.removeClass( 'mfp-hide' );
190
191 jQuery( 'body' ).removeClass( 'give-modal-open' );
192
193 //Show all fields again
194 $form.children().not( children ).show();
195 }
196 }
197 } );
198 }
199
200 /**
201 * Floating Labels Custom Events
202 */
203 function give_fl_trigger() {
204 if ( give_float_labels instanceof FloatLabels ) {
205 give_float_labels.rebuild();
206 }
207 else {
208 give_float_labels = new FloatLabels( '.float-labels-enabled', {
209 exclude: '#give-amount, .give-select-level, [multiple]',
210 prioritize: 'placeholder',
211 prefix: 'give-fl-',
212 style: 'give',
213 } );
214 }
215 }
216
217 /**
218 * Change localize html5 form validation message
219 */
220 function give_change_html5_form_field_validation_message() {
221 var $forms = jQuery( '.give-form' ),
222 $input_fields;
223
224 // Bailout if no any donation from exist.
225 if ( ! $forms.length ) {
226 return;
227 }
228
229 jQuery.each( $forms, function( index, $form ) {
230 // Get form input fields.
231 $input_fields = jQuery( 'input', $form );
232
233 // Bailout.
234 if ( ! $input_fields.length ) {
235 return;
236 }
237
238 jQuery.each( $input_fields, function( index, item ) {
239 item = jQuery( item ).get( 0 );
240
241 // Set custom message only if translation exit in give global object.
242 if ( give_global_vars.form_translation.hasOwnProperty( item.name ) ) {
243 item.oninvalid = function( e ) {
244 e.target.setCustomValidity( '' );
245 if ( ! e.target.validity.valid ) {
246 e.target.setCustomValidity( give_global_vars.form_translation[ item.name ] );
247 }
248 };
249 }
250 } );
251 } );
252 }
253
254 /**
255 * Update state/province fields per country selection
256 *
257 * @since 1.8.14
258 */
259 function update_profile_state_field() {
260 var $this = jQuery( this ),
261 $form = $this.parents( 'form' );
262 if ( 'give_address_country' === $this.attr( 'id' ) ) {
263
264 //Disable the State field until updated
265 $form.find( '#give_address_state' ).empty().append( '<option value="1">' + give_global_vars.general_loading + '</option>' ).prop( 'disabled', true );
266
267 // If the country field has changed, we need to update the state/province field
268 var postData = {
269 action: 'give_get_states',
270 country: $this.val(),
271 field_name: 'give_address_state'
272 };
273
274 jQuery.ajax( {
275 type: 'POST',
276 data: postData,
277 url: give_global_vars.ajaxurl,
278 xhrFields: {
279 withCredentials: true
280 },
281 success: function( response ) {
282 var html = '';
283 var states_label = response.states_label;
284 if ( typeof (response.states_found) != undefined && true == response.states_found ) {
285 html = response.data;
286 } else {
287 html = '<input type="text" id="give_address_state" name="give_address_state" class="text give-input" placeholder="' + states_label + '" value="' + response.default_state + '"/>';
288 }
289 $form.find( 'input[name="give_address_state"], select[name="give_address_state"]' ).replaceWith( html );
290
291 // Check if user want to show the feilds or not.
292 if ( typeof (response.show_field) != undefined && true == response.show_field ) {
293 $form.find( 'p#give-card-state-wrap' ).removeClass( 'give-hidden' );
294
295 // Add support to zip fields.
296 $form.find( 'p#give-card-zip-wrap' ).addClass( 'form-row-last' );
297 $form.find( 'p#give-card-zip-wrap' ).removeClass( 'form-row-wide' );
298 } else {
299 $form.find( 'p#give-card-state-wrap' ).addClass( 'give-hidden' );
300
301 // Add support to zip fields.
302 $form.find( 'p#give-card-zip-wrap' ).addClass( 'form-row-wide' );
303 $form.find( 'p#give-card-zip-wrap' ).removeClass( 'form-row-last' );
304 }
305 }
306 } ).fail( function( data ) {
307 if ( window.console && window.console.log ) {
308 console.log( data );
309 }
310 } );
311 }
312 return false;
313 }