This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | /*@global PodsI18n */ |
||
2 | ( function ( $ ) { |
||
3 | var pods_changed = false, |
||
4 | pods_form_field_names = [], |
||
5 | methods = { |
||
6 | validate : function () { |
||
7 | var $containers = $( 'form.pods-submittable, .pods-validation' ), |
||
8 | form_fields = 'input.pods-validate, select.pods-validate, textarea.pods-validate'; |
||
9 | |||
10 | // handle required |
||
11 | $containers.on( 'change keyup blur', form_fields.replace( ',', '.pods-validate-required,' ) + '.pods-validate-required', function () { |
||
12 | var $el = $( this ); |
||
13 | |||
14 | if ( !$el.is( ':visible' ) ) |
||
15 | return; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
16 | |||
17 | var label = ''; |
||
18 | |||
19 | if ( 'undefined' != typeof $el.data( 'label' ) ) |
||
0 ignored issues
–
show
|
|||
20 | label = $el.data( 'label' ); |
||
0 ignored issues
–
show
|
|||
21 | else if ( 0 < $el.parent().find( 'label' ).length ) |
||
22 | label = $el.parent().find( 'label' ).html().trim(); |
||
0 ignored issues
–
show
|
|||
23 | else |
||
24 | label = $el.prop( 'name' ).trim().replace( '_', ' ' ); |
||
0 ignored issues
–
show
|
|||
25 | |||
26 | // TinyMCE support |
||
27 | if ( 'object' == typeof tinyMCE && -1 < $el.prop( 'class' ).indexOf( 'pods-ui-field-tinymce' ) ) |
||
0 ignored issues
–
show
|
|||
28 | tinyMCE.triggerSave(); |
||
0 ignored issues
–
show
|
|||
29 | |||
30 | var valid_field = true; |
||
31 | |||
32 | if ( $el.is( 'input[type=checkbox]' ) && !( $el.is( ':checked' ) ) ) { |
||
33 | valid_field = false; |
||
34 | |||
35 | // extra check for relationship checkboxes to see if siblings are checked |
||
36 | if ( $el.hasClass( 'pods-form-ui-field-type-pick' ) ) { |
||
37 | $el.closest( '.pods-pick-checkbox' ).find( 'input[type=checkbox]' ).each( function () { |
||
38 | if ( $( this ).is( ':checked' ) ) { |
||
39 | valid_field = true; |
||
40 | } |
||
41 | } ) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
42 | |||
43 | } |
||
44 | |||
45 | } |
||
46 | else if ( '' === $el.val() ) |
||
47 | valid_field = false; |
||
0 ignored issues
–
show
|
|||
48 | |||
49 | if ( !valid_field ) { |
||
50 | if ( -1 == jQuery.inArray( $el.prop( 'name' ), pods_form_field_names ) ) { |
||
0 ignored issues
–
show
|
|||
51 | $el.closest( '.pods-field-input' ).find( '.pods-validate-error-message' ).remove(); |
||
52 | |||
53 | if ( $el.closest( '.pods-field-input > td' ).length > 0 ) { |
||
54 | $el.closest( '.pods-field-input > td' ).last().prepend( '<div class="pods-validate-error-message">' + PodsI18n.__( '%s is required.' ).replace( '%s', label.replace( /( <([^>]+ )> )/ig, '' ) ) + '</div>' ); |
||
55 | } else { |
||
56 | $el.closest( '.pods-field-input' ).append( '<div class="pods-validate-error-message">' + PodsI18n.__( '%s is required.' ).replace( '%s', label.replace( /( <([^>]+ )> )/ig, '' ) ) + '</div>' ); |
||
57 | } |
||
58 | $el.addClass( 'pods-validate-error' ); |
||
59 | |||
60 | pods_form_field_names.push( $el.prop( 'name' ) ); |
||
61 | } |
||
62 | } |
||
63 | else { |
||
64 | $el.closest( '.pods-field-input' ).find( '.pods-validate-error-message' ).remove(); |
||
65 | $el.removeClass( 'pods-validate-error' ); |
||
66 | |||
67 | if ( -1 < jQuery.inArray( $el.prop( 'name' ), pods_form_field_names ) ) |
||
68 | pods_form_field_names.splice( jQuery.inArray( $el.prop( 'name' ), pods_form_field_names ), 1 ); |
||
0 ignored issues
–
show
|
|||
69 | } |
||
70 | } ); |
||
71 | }, |
||
72 | submit_meta : function () { |
||
73 | var $submitbutton; |
||
74 | |||
75 | // Verify required fields in WordPress posts with CPT |
||
76 | $( 'form.pods-submittable' ).on( 'submit', function ( e ) { |
||
77 | var $submittable = $( this ); |
||
78 | |||
79 | pods_changed = false; |
||
80 | |||
81 | /* e.preventDefault(); */ |
||
82 | |||
83 | var postdata = {}; |
||
84 | var field_data = {}; |
||
85 | |||
86 | var valid_form = true; |
||
87 | |||
88 | var field_id = 0, |
||
89 | field_index = 0; |
||
90 | |||
91 | // See if we have any instances of tinyMCE and save them |
||
92 | if ( 'undefined' != typeof tinyMCE ) |
||
0 ignored issues
–
show
|
|||
93 | tinyMCE.triggerSave(); |
||
0 ignored issues
–
show
|
|||
94 | |||
95 | $submittable.find( '.pods-submittable-fields' ).find( 'input, select, textarea' ).each( function () { |
||
96 | var $el = $( this ); |
||
97 | var field_name = $el.prop( 'name' ); |
||
98 | |||
99 | if ( 'undefined' != typeof field_name && null !== field_name && '' != field_name && 0 != field_name.indexOf( 'field_data[' ) ) { |
||
0 ignored issues
–
show
|
|||
100 | var val = $el.val(); |
||
101 | |||
102 | if ( $el.is( 'input[type=checkbox]' ) && !$el.is( ':checked' ) ) { |
||
103 | if ( 1 == val ) |
||
0 ignored issues
–
show
|
|||
104 | val = 0; |
||
0 ignored issues
–
show
|
|||
105 | else |
||
106 | return true; // This input isn't a boolean, continue the loop |
||
0 ignored issues
–
show
|
|||
107 | } |
||
108 | else if ( $el.is( 'input[type=radio]' ) && !$el.is( ':checked' ) ) |
||
109 | return true; // This input is not checked, continue the loop |
||
0 ignored issues
–
show
|
|||
110 | |||
111 | if ( $el.is( ':visible' ) && $el.hasClass( 'pods-validate pods-validate-required' ) && ( '' === $el.val() ) ) { |
||
112 | $el.trigger( 'change' ); |
||
113 | |||
114 | if ( false !== valid_form ) |
||
115 | $el.focus(); |
||
0 ignored issues
–
show
|
|||
116 | |||
117 | valid_form = false; |
||
118 | } |
||
119 | if ( null !== val ) { |
||
120 | postdata[field_name] = val; |
||
121 | } |
||
122 | } |
||
123 | } ); |
||
124 | |||
125 | if ( 'undefined' != typeof pods_admin_submit_validation ) |
||
0 ignored issues
–
show
|
|||
126 | valid_form = pods_admin_submit_validation( valid_form, $submittable ); |
||
0 ignored issues
–
show
|
|||
127 | |||
128 | if ( false === valid_form ) { |
||
129 | $submittable.addClass( 'invalid-form' ); |
||
130 | |||
131 | // re-enable the submit button |
||
132 | $( $submittable ).find( 'input[type=submit], button[type=submit]' ).each( function () { |
||
133 | var $submitbutton = $( this ); |
||
134 | |||
135 | $submitbutton.css( 'cursor', 'pointer' ); |
||
136 | $submitbutton.prop( 'disabled', false ); |
||
137 | $submitbutton.parent().find( '.waiting' ).fadeOut(); |
||
138 | } ); |
||
139 | |||
140 | pods_form_field_names = []; |
||
141 | |||
142 | return false; |
||
143 | } |
||
144 | else |
||
145 | $submittable.removeClass( 'invalid-form' ); |
||
0 ignored issues
–
show
|
|||
146 | |||
147 | return true; |
||
148 | } ); |
||
149 | }, |
||
150 | submit : function () { |
||
151 | var $submitbutton, id, data; |
||
152 | |||
153 | // Handle submit of form and translate to AJAX |
||
154 | $( 'form.pods-submittable' ).on( 'submit', function ( e ) { |
||
155 | var $submittable = $( this ); |
||
156 | |||
157 | pods_changed = false; |
||
158 | |||
159 | e.preventDefault(); |
||
160 | |||
161 | pods_ajaxurl = $submittable.attr( 'action' ); |
||
162 | pods_ajaxurl = pods_ajaxurl.replace( /\?nojs\=1/, '?pods_ajax=1' ); |
||
163 | |||
164 | if ( 'undefined' != typeof ajaxurl && ( '' == pods_ajaxurl || '?pods_ajax=1' == pods_ajaxurl || document.location.href == pods_ajaxurl || document.location.href.replace( /\?nojs\=1/, '?pods_ajax=1' ) == pods_ajaxurl ) ) |
||
0 ignored issues
–
show
|
|||
165 | pods_ajaxurl = ajaxurl + '?pods_ajax=1'; |
||
0 ignored issues
–
show
|
|||
166 | |||
167 | if ( 'undefined' != typeof ajaxurl && $submittable.hasClass( 'pods-submittable-ajax' ) ) |
||
0 ignored issues
–
show
|
|||
168 | pods_ajaxurl = ajaxurl + '?pods_ajax=1'; |
||
0 ignored issues
–
show
|
|||
169 | |||
170 | var postdata = {}; |
||
171 | var field_data = {}; |
||
172 | |||
173 | var valid_form = true; |
||
174 | |||
175 | var field_id = 0, |
||
176 | field_index = 0; |
||
177 | |||
178 | // See if we have any instances of tinyMCE and save them |
||
179 | if ( 'undefined' != typeof tinyMCE ) |
||
0 ignored issues
–
show
|
|||
180 | tinyMCE.triggerSave(); |
||
0 ignored issues
–
show
|
|||
181 | |||
182 | $submittable.find( '.pods-submittable-fields' ).find( 'input, select, textarea' ).each( function () { |
||
183 | var $el = $( this ); |
||
184 | var field_name = $el.prop( 'name' ); |
||
185 | |||
186 | if ( 'undefined' != typeof field_name && null !== field_name && '' != field_name && 0 != field_name.indexOf( 'field_data[' ) ) { |
||
0 ignored issues
–
show
|
|||
187 | var val = $el.val(); |
||
188 | |||
189 | if ( $el.is( 'input[type=checkbox]' ) && !$el.is( ':checked' ) ) { |
||
190 | if ( $el.is( '.pods-boolean' ) || $el.is( '.pods-form-ui-field-type-boolean') ) |
||
191 | val = 0; |
||
0 ignored issues
–
show
|
|||
192 | else |
||
193 | return true; // This input isn't a boolean, continue the loop |
||
0 ignored issues
–
show
|
|||
194 | } |
||
195 | else if ( $el.is( 'input[type=radio]' ) && !$el.is( ':checked' ) ) |
||
196 | return true; // This input is not checked, continue the loop |
||
0 ignored issues
–
show
|
|||
197 | |||
198 | if ( $el.is( ':visible' ) && $el.hasClass( 'pods-validate pods-validate-required' ) && ( '' === $el.val() ) ) { |
||
199 | $el.trigger( 'change' ); |
||
200 | |||
201 | if ( false !== valid_form ) |
||
202 | $el.focus(); |
||
0 ignored issues
–
show
|
|||
203 | |||
204 | valid_form = false; |
||
205 | } |
||
206 | |||
207 | if ( null !== val ) { |
||
208 | postdata[field_name] = val; |
||
209 | } |
||
210 | } |
||
211 | } ); |
||
212 | |||
213 | // Check for unsaved open fields. (separate if's to prevent possible unneeded jQuery selector) |
||
214 | if ( 'undefined' !== typeof postdata.method ) { |
||
215 | if ( 'save_pod' === postdata.method ) { |
||
216 | if ( $( 'tbody.pods-manage-list tr.pods-manage-row-expanded', $submittable ).length ) { |
||
217 | alert( PodsI18n.__( 'Some fields have changes that were not saved yet, please save them or cancel the changes before saving the Pod.' ) ); |
||
218 | valid_form = false; |
||
219 | } |
||
220 | } |
||
221 | } |
||
222 | |||
223 | if ( 'undefined' != typeof pods_admin_submit_validation ) |
||
0 ignored issues
–
show
|
|||
224 | valid_form = pods_admin_submit_validation( valid_form, $submittable ); |
||
0 ignored issues
–
show
|
|||
225 | |||
226 | if ( false === valid_form ) { |
||
227 | $submittable.addClass( 'invalid-form' ); |
||
228 | |||
229 | // re-enable the submit button |
||
230 | $( $submittable ).find( 'input[type=submit], button[type=submit]' ).each( function () { |
||
231 | var $submitbutton = $( this ); |
||
232 | |||
233 | $submitbutton.css( 'cursor', 'pointer' ); |
||
234 | $submitbutton.prop( 'disabled', false ); |
||
235 | $submitbutton.parent().find( '.waiting' ).fadeOut(); |
||
236 | } ); |
||
237 | |||
238 | pods_form_field_names = []; |
||
239 | |||
240 | return false; |
||
241 | } |
||
242 | else |
||
243 | $submittable.removeClass( 'invalid-form' ); |
||
0 ignored issues
–
show
|
|||
244 | |||
245 | pods_ajaxurl = pods_ajaxurl + '&action=' + postdata.action; |
||
246 | |||
247 | $submitbutton = $submittable.find( 'input[type=submit], button[type=submit]' ); |
||
248 | |||
249 | $.ajax( { |
||
250 | type : 'POST', |
||
251 | dataType : 'html', |
||
252 | url : pods_ajaxurl, |
||
253 | cache : false, |
||
254 | data : postdata, |
||
255 | success : function ( d ) { |
||
256 | |||
257 | // Attempt to parse what was returned as data |
||
258 | try { |
||
259 | data = $.parseJSON( d ); |
||
260 | } |
||
261 | catch ( e ) { |
||
262 | data = undefined; |
||
263 | } |
||
264 | |||
265 | if ( -1 === d.indexOf( '<e>' ) && -1 === d.indexOf( '</e>' ) && -1 !== d ) { |
||
266 | |||
267 | // Added for modal add/edit support. If we get a valid JSON object, we assume we're modal |
||
268 | if ( 'object' === typeof data && null !== data ) { |
||
269 | |||
270 | // Phone home with the data |
||
271 | window.parent.jQuery( window.parent ).trigger('dfv:modal:update', data ); |
||
272 | } |
||
273 | else { |
||
274 | id = d.match( /\d*$/, '' ); |
||
275 | |||
276 | if ( 0 < id.length ) { |
||
277 | id = parseInt( id[ 0 ] ); |
||
278 | |||
279 | if ( isNaN( id ) ) { |
||
280 | id = 0; |
||
281 | } |
||
282 | } |
||
283 | else { |
||
284 | id = 0; |
||
285 | } |
||
286 | |||
287 | if ( 'undefined' != typeof pods_admin_submit_callback ) { |
||
0 ignored issues
–
show
|
|||
288 | pods_admin_submit_callback( d, $submittable, id ); |
||
289 | } |
||
290 | else if ( 'undefined' != typeof $submittable.data( 'location' ) ) { |
||
0 ignored issues
–
show
|
|||
291 | document.location.href = $submittable.data( 'location' ).replace( 'X_ID_X', id ); |
||
292 | } |
||
293 | else { |
||
294 | document.location.reload( true ); |
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | else if ( 'undefined' != typeof $submittable.data( 'error-location' ) ) { |
||
0 ignored issues
–
show
|
|||
299 | document.location.href = $submittable.data( 'error-location' ); |
||
300 | } |
||
301 | else { |
||
302 | var err_msg = d.replace( '<e>', '' ).replace( '</e>', '' ); |
||
303 | |||
304 | if ( 'undefined' != typeof pods_admin_submit_error_callback ) { |
||
0 ignored issues
–
show
|
|||
305 | pods_admin_submit_error_callback( err_msg, $submittable ); |
||
306 | } |
||
307 | else { |
||
308 | alert( 'Error: ' + err_msg ); |
||
309 | if ( window.console ) console.log( err_msg ); |
||
0 ignored issues
–
show
|
|||
310 | } |
||
311 | |||
312 | $submitbutton.css( 'cursor', 'pointer' ); |
||
313 | $submitbutton.prop( 'disabled', false ); |
||
314 | $submitbutton.parent().find( '.waiting' ).fadeOut(); |
||
315 | |||
316 | if ( $( '#pods-wizard-next' )[ 0 ] ) { |
||
317 | $( '#pods-wizard-next' ).css( 'cursor', 'pointer' ); |
||
318 | $( '#pods-wizard-next' ).prop( 'disabled', false ); |
||
319 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'next' ) ); |
||
320 | } |
||
321 | } |
||
322 | }, |
||
323 | error : function () { |
||
324 | var err_msg = 'Unable to process request, please try again.'; |
||
325 | |||
326 | if ( 'undefined' != typeof pods_admin_submit_error_callback ) { |
||
0 ignored issues
–
show
There were too many errors found in this file; checking aborted after 16%.
If JSHint finds too many errors in a file, it aborts checking altogether because it suspects a configuration issue. Further Reading: ![]() |
|||
327 | pods_admin_submit_error_callback( err_msg, $submittable ); |
||
328 | } |
||
329 | else { |
||
330 | alert( 'Error: ' + err_msg ); |
||
331 | if ( window.console ) console.log( err_msg ); |
||
332 | } |
||
333 | |||
334 | $submitbutton.css( 'cursor', 'pointer' ); |
||
335 | $submitbutton.prop( 'disabled', false ); |
||
336 | $submitbutton.parent().find( '.waiting' ).fadeOut(); |
||
337 | |||
338 | if ( $( '#pods-wizard-next' )[ 0 ] ) { |
||
339 | $( '#pods-wizard-next' ).css( 'cursor', 'pointer' ); |
||
340 | $( '#pods-wizard-next' ).prop( 'disabled', false ); |
||
341 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'next' ) ); |
||
342 | } |
||
343 | } |
||
344 | } ); |
||
345 | } )// Handle submit button and show waiting image |
||
346 | .on( 'click', 'input[type=submit], button[type=submit]', function ( e ) { |
||
347 | pods_changed = false; |
||
348 | |||
349 | e.preventDefault(); |
||
350 | |||
351 | $( 'div#message' ).slideUp( 'fast', function () { |
||
352 | $( this ).remove(); |
||
353 | } ); |
||
354 | |||
355 | var $submitbutton = $( this ); |
||
356 | $submitbutton.css( 'cursor', 'default' ); |
||
357 | $submitbutton.prop( 'disabled', true ); |
||
358 | $submitbutton.parent().find( '.waiting' ).fadeIn(); |
||
359 | |||
360 | $( this ).closest( 'form.pods-submittable' ).trigger( 'submit' ); |
||
361 | } ); |
||
362 | |||
363 | // Handle submit via link and translate to AJAX |
||
364 | $( 'form.pods-submittable a.pods-submit' ).on( 'click', function ( e ) { |
||
365 | var $submitbutton = $( this ); |
||
366 | |||
367 | e.preventDefault(); |
||
368 | |||
369 | pods_ajaxurl = $submitbutton.data( 'ajaxurl' ); |
||
370 | |||
371 | if ( 'undefined' != typeof pods_ajaxurl ) |
||
372 | pods_ajaxurl = pods_ajaxurl.replace( /\?nojs\=1/, '?pods_ajax=1' ); |
||
373 | else if ( 'undefined' != typeof ajaxurl && ( 'undefined' == typeof pods_ajaxurl || '' == pods_ajaxurl || '?pods_ajax=1' == pods_ajaxurl || document.location.href == pods_ajaxurl || document.location.href.replace( /\?nojs\=1/, '?pods_ajax=1' ) == pods_ajaxurl ) ) |
||
374 | pods_ajaxurl = ajaxurl + '?pods_ajax=1'; |
||
375 | |||
376 | var postdata = $submitbutton.data(); |
||
377 | |||
378 | if ( 'undefined' != typeof $submitbutton.data( 'confirm' ) && !confirm( $submitbutton.data( 'confirm' ) ) ) |
||
379 | return false; |
||
380 | |||
381 | $( 'div#message' ).slideUp( 'fast', function () { |
||
382 | $( this ).remove(); |
||
383 | } ); |
||
384 | |||
385 | pods_changed = false; |
||
386 | |||
387 | pods_ajaxurl = pods_ajaxurl + '&action=' + postdata.action; |
||
388 | |||
389 | $.ajax( { |
||
390 | type : 'POST', |
||
391 | dataType : 'html', |
||
392 | url : pods_ajaxurl, |
||
393 | cache : false, |
||
394 | data : postdata, |
||
395 | success : function ( d ) { |
||
396 | if ( -1 == d.indexOf( '<e>' ) && -1 == d.indexOf( '</e>' ) && -1 != d ) { |
||
397 | var id = d.match( /\d*$/, '' ); |
||
398 | |||
399 | if ( 0 < id.length ) { |
||
400 | id = parseInt( id[ 0 ] ); |
||
401 | |||
402 | if ( isNaN( id ) ) |
||
403 | id = 0; |
||
404 | } |
||
405 | else |
||
406 | id = 0; |
||
407 | |||
408 | if ( 'undefined' != typeof pods_admin_submit_callback ) |
||
409 | pods_admin_submit_callback( d, $submittable, id ); |
||
410 | else if ( 'undefined' != typeof $submittable.data( 'location' ) ) |
||
411 | document.location.href = $submittable.data( 'location' ).replace( 'X_ID_X', id ); |
||
412 | else |
||
413 | document.location.reload( true ); |
||
414 | } |
||
415 | else if ( 'undefined' != typeof $submitbutton.data( 'error-location' ) ) |
||
416 | document.location.href = $submitbutton.data( 'error-location' ); |
||
417 | else { |
||
418 | var err_msg = d.replace( '<e>', '' ).replace( '</e>', '' ); |
||
419 | |||
420 | if ( 'undefined' != typeof pods_admin_submit_error_callback ) |
||
421 | pods_admin_submit_error_callback( err_msg, $submittable ); |
||
422 | else { |
||
423 | alert( 'Error: ' + err_msg ); |
||
424 | if ( window.console ) console.log( err_msg ); |
||
425 | } |
||
426 | |||
427 | $submitbutton.css( 'cursor', 'pointer' ); |
||
428 | $submitbutton.prop( 'disabled', false ); |
||
429 | $submitbutton.parent().find( '.waiting' ).fadeOut(); |
||
430 | } |
||
431 | }, |
||
432 | error : function () { |
||
433 | var err_msg = PodsI18n.__( 'Unable to process request, please try again.' ); |
||
434 | |||
435 | if ( 'undefined' != typeof pods_admin_submit_error_callback ) |
||
436 | pods_admin_submit_error_callback( err_msg, $submittable ); |
||
437 | else { |
||
438 | alert( 'Error: ' + err_msg ); |
||
439 | if ( window.console ) console.log( err_msg ); |
||
440 | } |
||
441 | |||
442 | $submitbutton.css( 'cursor', 'pointer' ); |
||
443 | $submitbutton.prop( 'disabled', false ); |
||
444 | $submitbutton.parent().find( '.waiting' ).fadeOut(); |
||
445 | } |
||
446 | } ); |
||
447 | } ); |
||
448 | }, |
||
449 | sluggable : function () { |
||
450 | // Setup selector |
||
451 | var $sluggable = $( '.pods-sluggable' ), |
||
452 | last_slug = null; |
||
453 | |||
454 | if ( 0 !== $sluggable.length ) { |
||
455 | // Hold onto slug in-case change is cancelled |
||
456 | if ( $sluggable.find( '.pods-slug-edit input[type=text]' )[ 0 ] ) { |
||
457 | last_slug = $sluggable.find( '.pods-slug-edit input[type=text]' ).val(); |
||
458 | |||
459 | last_slug = last_slug.replace( /<(?:.)*?>/g, '' ).replace( /([^0-9a-zA-Z\_\- ])/g, '' ); |
||
460 | |||
461 | $( '.pods-slugged-lower:not(.pods-slugged[data-sluggable])' ).html( last_slug.toLowerCase() ); |
||
462 | $( '.pods-slugged:not(.pods-slugged[data-sluggable])' ).html( last_slug.charAt( 0 ).toUpperCase() + last_slug.slice( 1 ) ); |
||
463 | } |
||
464 | |||
465 | // Handle click to edit |
||
466 | $sluggable.on( 'click', '.pods-slug em, .pods-slug input[type=button]', function () { |
||
467 | $( this ).css( 'cursor', 'default' ); |
||
468 | $( this ).prop( 'disabled', true ); |
||
469 | |||
470 | $( this ).closest( '.pods-sluggable' ).find( '.pods-slug, .pods-slug-edit' ).toggle(); |
||
471 | $( this ).closest( '.pods-sluggable' ).find( '.pods-slug-edit input[type=text]' ).focus(); |
||
472 | |||
473 | $( this ).css( 'cursor', 'pointer' ); |
||
474 | $( this ).prop( 'disabled', false ); |
||
475 | } ); |
||
476 | |||
477 | // Handle slug save |
||
478 | $sluggable.on( 'click', '.pods-slug-edit input[type=button]', function () { |
||
479 | $( this ).css( 'cursor', 'default' ); |
||
480 | $( this ).prop( 'disabled', true ); |
||
481 | |||
482 | last_slug = $( this ).parent().find( 'input[type=text]' ).val(); |
||
483 | |||
484 | last_slug = last_slug.replace( /<( ?:. )*?>/g, '' ).replace( /([^0-9a-zA-Z\_\- ])/g, '' ); |
||
485 | |||
486 | $( this ).closest( '.pods-sluggable' ).find( '.pods-slug em' ).html( last_slug ); |
||
487 | $( '.pods-slugged-lower:not(.pods-slugged[data-sluggable])' ).html( last_slug.toLowerCase() ); |
||
488 | $( '.pods-slugged:not(.pods-slugged[data-sluggable])' ).html( last_slug.charAt( 0 ).toUpperCase() + last_slug.slice( 1 ) ); |
||
489 | $( this ).closest( '.pods-sluggable' ).find( '.pods-slug, .pods-slug-edit' ).toggle(); |
||
490 | |||
491 | $( this ).css( 'cursor', 'pointer' ); |
||
492 | $( this ).prop( 'disabled', false ); |
||
493 | } ); |
||
494 | |||
495 | // Handle cancel slug edit |
||
496 | $sluggable.on( 'click', '.pods-slug-edit a.cancel', function ( e ) { |
||
497 | $( this ).css( 'cursor', 'default' ); |
||
498 | $( this ).prop( 'disabled', true ); |
||
499 | |||
500 | $( this ).parent().find( 'input[type=text]' ).val( last_slug ); |
||
501 | $( this ).closest( '.pods-sluggable' ).find( '.pods-slug, .pods-slug-edit' ).toggle(); |
||
502 | |||
503 | $( this ).css( 'cursor', 'pointer' ); |
||
504 | $( this ).prop( 'disabled', false ); |
||
505 | |||
506 | e.preventDefault(); |
||
507 | } ); |
||
508 | $sluggable.find( '.pods-slug-edit' ).hide(); |
||
509 | } |
||
510 | |||
511 | methods[ 'sluggables' ](); |
||
512 | }, |
||
513 | sluggable_single : function ( sluggable ) { |
||
514 | var $slug = $( 'input[name="' + sluggable.replace( '[', '\\[' ).replace( ']', '\\]' ) + '"]' ); |
||
515 | |||
516 | if ( $slug[ 0 ] ) { |
||
517 | $( 'form' ).on( 'change', 'input[name="' + sluggable.replace( '[', '\\[' ).replace( ']', '\\]' ) + '"]', function () { |
||
518 | if ( 0 < $( this ).val().length ) { |
||
519 | var slug = $( this ).val(); |
||
520 | |||
521 | slug = slug.replace( /<( ?:. )*?>/g, '' ).replace( /([^0-9a-zA-Z\_\- ])/g, '' ); |
||
522 | |||
523 | // update fields |
||
524 | $( 'input.pods-slugged[data-sluggable="' + $( this ).prop( 'name' ).replace( '[', '\\[' ).replace( ']', '\\]' ) + '"]' ).each( function () { |
||
525 | if ( '' === $( this ).val() ) { |
||
526 | $( this ).val( slug.charAt( 0 ).toUpperCase() + slug.slice( 1 ) ); |
||
527 | $( this ).trigger( 'change' ); |
||
528 | } |
||
529 | } ); |
||
530 | $( 'input.pods-slugged-lower[data-sluggable="' + $( this ).prop( 'name' ).replace( '[', '\\[' ).replace( ']', '\\]' ) + '"]' ).each( function () { |
||
531 | if ( '' === $( this ).val() ) { |
||
532 | $( this ).val( slug.toLowerCase() ); |
||
533 | $( this ).trigger( 'change' ); |
||
534 | } |
||
535 | } ); |
||
536 | |||
537 | // update elements and trigger change |
||
538 | $( '.pods-slugged-lower[data-sluggable="' + $( this ).prop( 'name' ).replace( '[', '\\[' ).replace( ']', '\\]' ) + '"]:not(input )' ) |
||
539 | .html( slug.toLowerCase() ) |
||
540 | .trigger( 'change' ); |
||
541 | |||
542 | // trigger change |
||
543 | $( '.pods-slugged[data-sluggable="' + $( this ).prop( 'name' ).replace( '[', '\\[' ).replace( ']', '\\]' ) + '"]:not(input )' ) |
||
544 | .html( slug.charAt( 0 ).toUpperCase() + slug.slice( 1 ) ) |
||
545 | .trigger( 'change' ); |
||
546 | } |
||
547 | } ); |
||
548 | |||
549 | if ( 0 < $slug.val().length ) { |
||
550 | $slug.trigger( 'change' ); |
||
551 | } |
||
552 | } |
||
553 | }, |
||
554 | sluggables : function ( parent ) { |
||
555 | var sluggables = []; |
||
556 | |||
557 | if ( 'undefined' == typeof parent ) |
||
558 | parent = '.pods-admin'; |
||
559 | |||
560 | $( parent ).find( '.pods-slugged[data-sluggable], .pods-slugged-lower[data-sluggable]' ).each( function () { |
||
561 | if ( -1 == jQuery.inArray( $( this ).data( 'sluggable' ), sluggables ) ) |
||
562 | sluggables.push( $( this ).data( 'sluggable' ) ); |
||
563 | } ); |
||
564 | |||
565 | for ( var i = 0; i < sluggables.length; i++ ) { |
||
566 | var sluggable = sluggables[ i ]; |
||
567 | |||
568 | methods[ 'sluggable_single' ]( sluggable ); |
||
569 | } |
||
570 | }, |
||
571 | tabbed : function () { |
||
572 | $( '.pods-admin' ).on( 'click', '.pods-tabs .pods-tab a.pods-tab-link', function ( e ) { |
||
573 | $( this ).css( 'cursor', 'default' ); |
||
574 | $( this ).prop( 'disabled', true ); |
||
575 | |||
576 | var tab_class = '.pods-tabbed'; |
||
577 | |||
578 | if ( 'undefined' != typeof $( this ).closest( '.pods-tabs' ).data( 'tabbed' ) ) |
||
579 | tab_class = $( this ).closest( '.pods-tabs' ).data( 'tabbed' ); |
||
580 | |||
581 | var $tabbed = $( this ).closest( tab_class ); |
||
582 | var tab_hash = this.hash; |
||
583 | |||
584 | if ( $tabbed.find( '.pods-tabs .pods-tab a[data-tabs]' )[ 0 ] ) { |
||
585 | $tabbed.find( '.pods-tabs .pods-tab a[data-tabs]' ).each( function () { |
||
586 | var tabs = $( this ).data( 'tabs' ), |
||
587 | this_tab_hash = this.hash; |
||
588 | |||
589 | if ( tab_hash != this_tab_hash ) |
||
590 | $tabbed.find( tabs ).hide(); |
||
591 | else |
||
592 | $tabbed.find( tabs ).show(); |
||
593 | } ); |
||
594 | } |
||
595 | else { |
||
596 | $.when( $tabbed.find( '.pods-tab-group .pods-tab' ).not( tab_hash ).slideUp() ).done( function () { |
||
597 | var $current_tab = $tabbed.find( '.pods-tab-group .pods-tab' + tab_hash ); |
||
598 | |||
599 | $( '.pods-dependent-toggle', $current_tab ).each( function () { |
||
600 | var elementId = $( this ).attr( 'id' ); |
||
601 | var runDependencies = true; |
||
602 | var selectionTypes = [ |
||
603 | { |
||
604 | name : 'single', |
||
605 | pickFormatRegex: /pick-format-single$/g |
||
606 | }, |
||
607 | { |
||
608 | name : 'multi', |
||
609 | pickFormatRegex: /pick-format-multi$/g |
||
610 | } |
||
611 | ]; |
||
612 | |||
613 | // Pick multi/single select: Bypass dependency checks on the format of selection types |
||
614 | // that aren't currently chosen. We shouldn't check dependencies against format_single |
||
615 | // if multi is selected and vice versa. |
||
616 | selectionTypes.forEach( function( thisSelectionType ) { |
||
617 | var pickSelectionTypeId = null; |
||
618 | |||
619 | // Is this the format list for one of the selection types? |
||
620 | if ( thisSelectionType.pickFormatRegex.test( elementId ) ) { |
||
621 | |||
622 | // Get the HTML ID of the "selection type" select box so we can check its value |
||
623 | pickSelectionTypeId = elementId.replace( thisSelectionType.pickFormatRegex, 'pick-format-type' ); |
||
624 | |||
625 | // Bypass dependency checks if this format value is for a selection type |
||
626 | // that isn't currently selected |
||
627 | if ( $( '#' + pickSelectionTypeId ).val() !== thisSelectionType.name ) { |
||
628 | runDependencies = false; |
||
629 | } |
||
630 | } |
||
631 | } ); |
||
632 | |||
633 | if ( runDependencies ) { |
||
634 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
635 | } |
||
636 | } ); |
||
637 | |||
638 | $current_tab.slideDown(); |
||
639 | } ); |
||
640 | } |
||
641 | |||
642 | $tabbed.find( '.pods-tabs .pods-tab a' ).removeClass( 'selected' ); |
||
643 | |||
644 | $( this ).addClass( 'selected' ); |
||
645 | |||
646 | $( this ).css( 'cursor', 'pointer' ); |
||
647 | $( this ).prop( 'disabled', false ); |
||
648 | |||
649 | e.preventDefault(); |
||
650 | } ); |
||
651 | |||
652 | $( '.pods-tabbed' ).each( function () { |
||
653 | $( 'ul.pods-tabs .pods-tab:first a', this ).addClass( 'selected' ); |
||
654 | $( '.pods-tab-group .pods-tab:first' ).each( function () { |
||
655 | $( '.pods-dependent-toggle', this ).trigger( 'change' ); |
||
656 | $( this ).show(); |
||
657 | } ) |
||
658 | } ); |
||
659 | }, |
||
660 | nav_tabbed : function () { |
||
661 | $( '.pods-admin' ).on( 'click', '.pods-nav-tabs a.pods-nav-tab-link', function ( e ) { |
||
662 | $( this ).css( 'cursor', 'default' ); |
||
663 | $( this ).prop( 'disabled', true ); |
||
664 | |||
665 | var tab_class = '.pods-nav-tabbed'; |
||
666 | |||
667 | if ( 'undefined' != typeof $( this ).closest( '.pods-nav-tabs' ).data( 'tabbed' ) ) |
||
668 | tab_class = $( this ).closest( '.pods-nav-tabs' ).data( 'tabbed' ); |
||
669 | |||
670 | var $tabbed = $( this ).closest( tab_class ); |
||
671 | var tab_hash = this.hash; |
||
672 | |||
673 | if ( $tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link[data-tabs]' )[ 0 ] ) { |
||
674 | $tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link[data-tabs]' ).each( function () { |
||
675 | var tabs = $( this ).data( 'tabs' ), |
||
676 | this_tab_hash = this.hash; |
||
677 | |||
678 | if ( tab_hash != this_tab_hash ) |
||
679 | $tabbed.find( tabs ).hide(); |
||
680 | else |
||
681 | $tabbed.find( tabs ).show(); |
||
682 | } ); |
||
683 | } |
||
684 | else { |
||
685 | $tabbed.find( '.pods-nav-tab-group .pods-nav-tab' ).not( tab_hash ).each( function () { |
||
686 | $( this ).hide(); |
||
687 | } ); |
||
688 | |||
689 | $tabbed.find( '.pods-nav-tab-group .pods-nav-tab' ).filter( tab_hash ).each( function () { |
||
690 | $( '.pods-dependent-toggle', this ).trigger( 'change' ); |
||
691 | |||
692 | $( this ).show(); |
||
693 | } ); |
||
694 | } |
||
695 | |||
696 | $tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link' ).removeClass( 'nav-tab-active' ); |
||
697 | |||
698 | $( this ).addClass( 'nav-tab-active' ); |
||
699 | |||
700 | $( this ).css( 'cursor', 'pointer' ); |
||
701 | $( this ).prop( 'disabled', false ); |
||
702 | |||
703 | e.preventDefault(); |
||
704 | } ); |
||
705 | |||
706 | $( '.pods-nav-tabbed' ).each( function () { |
||
707 | $nav_tabbed = $( this ); |
||
708 | $nav_tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link:first' ).addClass( 'nav-tab-active' ); |
||
709 | $nav_tabbed.find( '.pods-nav-tab-group .pods-nav-tab:first' ).each( function () { |
||
710 | $( '.pods-dependent-toggle', this ).trigger( 'change' ); |
||
711 | $( this ).show(); |
||
712 | } ) |
||
713 | } ); |
||
714 | }, |
||
715 | wizard : function () { |
||
716 | var methods = { |
||
717 | setFinished : function () { |
||
718 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'finished' ) ); |
||
719 | }, |
||
720 | setProgress : function () { |
||
721 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'next ' ) ); |
||
722 | }, |
||
723 | stepBackward : function () { |
||
724 | $( '#pods-wizard-next' ).css( 'cursor', 'pointer' ); |
||
725 | $( '#pods-wizard-next' ).prop( 'disabled', false ); |
||
726 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'next' ) ); |
||
727 | |||
728 | // Step toolbar menu state forwards |
||
729 | $( 'li.pods-wizard-menu-current' ) |
||
730 | .removeClass( 'pods-wizard-menu-current pods-wizard-menu-complete' ) |
||
731 | .prev( 'li' ) |
||
732 | .removeClass( 'pods-wizard-menu-complete' ) |
||
733 | .addClass( 'pods-wizard-menu-current' ); |
||
734 | |||
735 | // Get current step # |
||
736 | var step = false; |
||
737 | |||
738 | if ( $( 'li.pods-wizard-menu-current[data-step]' )[ 0 ] ) |
||
739 | step = $( 'li.pods-wizard-menu-current' ).data( 'step' ); |
||
740 | |||
741 | // Show start over button |
||
742 | if ( 1 == step ) |
||
743 | $( '#pods-wizard-start' ).hide(); |
||
744 | else |
||
745 | $( '#pods-wizard-start' ).show(); |
||
746 | |||
747 | // Check if last step |
||
748 | if ( $( 'div.pods-wizard-panel:visible' ).prev( 'div.pods-wizard-panel' ).length ) { |
||
749 | // Show next panel |
||
750 | $( 'div.pods-wizard-panel:visible' ) |
||
751 | .hide() |
||
752 | .prev() |
||
753 | .show(); |
||
754 | } |
||
755 | |||
756 | window.location.hash = ''; |
||
757 | }, |
||
758 | stepForward : function () { |
||
759 | // Show action bar for second panel if hidden |
||
760 | $( 'div.pods-wizard-hide-first' ) |
||
761 | .removeClass( 'pods-wizard-hide-first' ) |
||
762 | // Remember that first panel should hide action bar |
||
763 | .data( 'hide', 1 ); |
||
764 | |||
765 | // Step toolbar menu state forwards |
||
766 | $( 'li.pods-wizard-menu-current' ) |
||
767 | .removeClass( 'pods-wizard-menu-current' ) |
||
768 | .addClass( 'pods-wizard-menu-complete' ) |
||
769 | .next( 'li' ) |
||
770 | .addClass( 'pods-wizard-menu-current' ); |
||
771 | |||
772 | // Get current step # |
||
773 | var step = false; |
||
774 | |||
775 | if ( $( 'li.pods-wizard-menu-current[data-step]' )[ 0 ] ) |
||
776 | step = $( 'li.pods-wizard-menu-current' ).data( 'step' ); |
||
777 | |||
778 | // Show start over button |
||
779 | $( '#pods-wizard-start' ).show(); |
||
780 | |||
781 | // Allow for override |
||
782 | var check = true; |
||
783 | |||
784 | // Check if last step |
||
785 | if ( $( 'div.pods-wizard-panel:visible' ).next( 'div.pods-wizard-panel' ).length ) { |
||
786 | // Show next panel |
||
787 | $( 'div.pods-wizard-panel:visible' ) |
||
788 | .hide() |
||
789 | .next() |
||
790 | .show(); |
||
791 | |||
792 | // Allow for override |
||
793 | if ( 'undefined' != typeof pods_admin_wizard_callback ) |
||
794 | check = pods_admin_wizard_callback( step, false ); |
||
795 | |||
796 | if ( false === check ) |
||
797 | return check; |
||
798 | |||
799 | window.location.hash = ''; |
||
800 | } |
||
801 | else if ( $( '#pods-wizard-box' ).closest( 'form' )[ 0 ] ) { |
||
802 | $( '#pods-wizard-next' ).css( 'cursor', 'default' ); |
||
803 | $( '#pods-wizard-next' ).prop( 'disabled', true ); |
||
804 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'processing' ) ); |
||
805 | |||
806 | // Allow for override |
||
807 | if ( 'undefined' != typeof pods_admin_wizard_callback ) |
||
808 | check = pods_admin_wizard_callback( step, true ); |
||
809 | |||
810 | if ( false === check ) |
||
811 | return check; |
||
812 | |||
813 | $( '#pods-wizard-box' ).closest( 'form' ).submit(); |
||
814 | |||
815 | if ( $( '#pods-wizard-box' ).closest( 'form' ).hasClass( 'invalid-form' ) ) { |
||
816 | $( '#pods-wizard-next' ).css( 'cursor', 'pointer' ); |
||
817 | $( '#pods-wizard-next' ).prop( 'disabled', false ); |
||
818 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'next' ) ); |
||
819 | |||
820 | // Step toolbar menu state forwards |
||
821 | $( 'li.pods-wizard-menu-complete:last' ) |
||
822 | .removeClass( 'pods-wizard-menu-complete' ) |
||
823 | .addClass( 'pods-wizard-menu-current' ) |
||
824 | } |
||
825 | } |
||
826 | else { |
||
827 | // Allow for override |
||
828 | if ( 'undefined' != typeof pods_admin_wizard_callback ) |
||
829 | check = pods_admin_wizard_callback( step, true ); |
||
830 | |||
831 | if ( false === check ) |
||
832 | return check; |
||
833 | |||
834 | methods.setFinished(); |
||
835 | |||
836 | window.location.hash = ''; |
||
837 | } |
||
838 | }, |
||
839 | startOver : function () { |
||
840 | // Reset next button text |
||
841 | methods.setProgress(); |
||
842 | |||
843 | // If first panel and action bar is supposed to be hidden, hide it. |
||
844 | var $box = $( '#pods-wizard-box' ); |
||
845 | if ( $box.data( 'hide' ) ) |
||
846 | $box.addClass( 'pods-wizard-hide-first' ); |
||
847 | |||
848 | // Revert to first current menu item |
||
849 | $( '#pods-wizard-heading ul li' ) |
||
850 | .removeClass() |
||
851 | .first() |
||
852 | .addClass( 'pods-wizard-menu-current' ); |
||
853 | |||
854 | // Revert to first panel |
||
855 | $( 'div.pods-wizard-panel' ) |
||
856 | .hide() |
||
857 | .first() |
||
858 | .show(); |
||
859 | |||
860 | // Hide start over button |
||
861 | $( '.pods-wizard-option-selected' ).removeClass(); |
||
862 | $( '#pods-wizard-start' ).hide(); |
||
863 | $( 'div.pods-wizard-option-cont' ).hide(); |
||
864 | $( '#pods-wizard-choices' ).fadeIn( 'fast' ); |
||
865 | |||
866 | if ( 'undefined' != typeof pods_admin_wizard_startover_callback ) |
||
867 | pods_admin_wizard_startover_callback( $( this ) ); |
||
868 | |||
869 | window.location.hash = ''; |
||
870 | } |
||
871 | }; |
||
872 | |||
873 | // Next button event binding |
||
874 | $( '#pods-wizard-next' ).on( 'click', function ( e ) { |
||
875 | if ( $( this ).is( ':disabled' ) ) |
||
876 | return; |
||
877 | |||
878 | e.preventDefault(); |
||
879 | |||
880 | methods.stepForward(); |
||
881 | } ); |
||
882 | |||
883 | // Start over button event binding |
||
884 | $( '#pods-wizard-start' ).hide().on( 'click', function ( e ) { |
||
885 | e.preventDefault(); |
||
886 | methods.startOver(); |
||
887 | } ); |
||
888 | |||
889 | // Upgrade choice button event binding |
||
890 | $( '.pods-choice-button' ).on( 'click', function ( e ) { |
||
891 | e.preventDefault(); |
||
892 | |||
893 | var target = $( this ).attr( 'href' ); |
||
894 | $( '#pods-wizard-choices' ).slideUp( 'fast' ); |
||
895 | $( target ).slideDown( 'fast' ); |
||
896 | } ); |
||
897 | |||
898 | // Create/extend option event binding |
||
899 | $( '.pods-wizard-option a' ).on( 'click', function ( e ) { |
||
900 | e.preventDefault(); |
||
901 | |||
902 | $( '.pods-wizard-option-content' ).hide(); |
||
903 | |||
904 | var target = $( this ).attr( 'href' ); |
||
905 | |||
906 | $( target ).show(); |
||
907 | $( '.pods-wizard-option-content-' + target.replace( '#pods-wizard-', '' ) ).show(); |
||
908 | |||
909 | if ( 'undefined' != typeof pods_admin_option_select_callback ) |
||
910 | pods_admin_option_select_callback( $( this ) ); |
||
911 | |||
912 | methods.stepForward(); |
||
913 | } ); |
||
914 | |||
915 | // Initial step panel setup |
||
916 | $( '.pods-wizard .pods-wizard-step' ).hide(); |
||
917 | $( '.pods-wizard .pods-wizard-step:first' ).show(); |
||
918 | }, |
||
919 | setup_dependencies : function( $el ) { |
||
920 | var $current = $el.closest( '.pods-dependency' ), |
||
921 | $field = $el, |
||
922 | val = $el.val(), |
||
923 | $field_type, |
||
924 | dependent_flag, |
||
925 | dependent_specific, |
||
926 | exclude_flag, |
||
927 | exclude_specific, |
||
928 | wildcard_target, |
||
929 | wildcard_target_value; |
||
930 | |||
931 | /** |
||
932 | * Check if this element is a child from an 'advanced field options' group. |
||
933 | * If so, set the value to empty if this is not the current field type group |
||
934 | * Fixes dependency compatibility |
||
935 | * |
||
936 | * @todo Validate & improve this |
||
937 | */ |
||
938 | // Are we in the "Fields" tab? |
||
939 | if ( $current.parents('#pods-manage-fields').length ) { |
||
940 | // And are we also in the "Additional Field Options" tab? |
||
941 | if ( $el.parents('.pods-additional-field-options').length ) { |
||
942 | // Get this field's type |
||
943 | $field_type = $current.find( '.pods-form-ui-field-name-field-data-type' ).val(); |
||
944 | // Check if this element resides within the correct "Additional Field Options" tab |
||
945 | if ( ! $el.parents( '.pods-additional-field-options > .pods-depends-on-field-data-type-' + $field_type ).length ) { |
||
946 | // This is not an option for this field. Empty the value |
||
947 | val = ''; |
||
948 | } |
||
949 | } |
||
950 | } |
||
951 | |||
952 | if ( null === val ) { |
||
953 | val = ''; |
||
954 | } |
||
955 | |||
956 | dependent_flag = '.pods-depends-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
||
957 | dependent_specific = dependent_flag + '-' + val.replace( /\_/gi, '-' ); |
||
958 | |||
959 | $current.find( dependent_flag ).each( function () { |
||
960 | var $dependent_el = $( this ), |
||
961 | dependency_trigger; |
||
962 | |||
963 | if ( $dependent_el.parent().is( ':visible' ) ) { |
||
964 | if ( $field.is( 'input[type=checkbox]' ) ) { |
||
965 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent_el.is( dependent_specific ) ) ) { |
||
966 | if ( $dependent_el.is( 'tr' ) ) |
||
967 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
968 | else |
||
969 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
970 | |||
971 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
972 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
973 | |||
974 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
975 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
976 | } ); |
||
977 | |||
978 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
979 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
980 | |||
981 | dependency_trigger = window[ dependency_trigger ]; |
||
982 | |||
983 | dependency_trigger( $dependent_el ); |
||
984 | } |
||
985 | } |
||
986 | else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent_el.is( dependent_specific ) ) ) { |
||
987 | if ( $dependent_el.is( 'tr' ) ) |
||
988 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
989 | else |
||
990 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
991 | } |
||
992 | } |
||
993 | else if ( $dependent_el.is( dependent_specific ) ) { |
||
994 | if ( $dependent_el.is( 'tr' ) ) |
||
995 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
996 | else |
||
997 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
998 | |||
999 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1000 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1001 | |||
1002 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1003 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1004 | } ); |
||
1005 | |||
1006 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1007 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1008 | |||
1009 | dependency_trigger = window[ dependency_trigger ]; |
||
1010 | |||
1011 | dependency_trigger( $dependent_el ); |
||
1012 | } |
||
1013 | } |
||
1014 | else { |
||
1015 | if ( $dependent_el.is( 'tr' ) ) |
||
1016 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1017 | else |
||
1018 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1019 | } |
||
1020 | } |
||
1021 | else { |
||
1022 | if ( $field.is( 'input[type=checkbox]' ) ) { |
||
1023 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent_el.is( dependent_specific ) ) ) { |
||
1024 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1025 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1026 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1027 | |||
1028 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1029 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1030 | } ); |
||
1031 | |||
1032 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1033 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1034 | |||
1035 | dependency_trigger = window[ dependency_trigger ]; |
||
1036 | |||
1037 | dependency_trigger( $dependent_el ); |
||
1038 | } |
||
1039 | } |
||
1040 | else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent_el.is( dependent_specific ) ) ) |
||
1041 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1042 | } |
||
1043 | else if ( $dependent_el.is( dependent_specific ) ) { |
||
1044 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1045 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1046 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1047 | |||
1048 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1049 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1050 | } ); |
||
1051 | |||
1052 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1053 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1054 | |||
1055 | dependency_trigger = window[ dependency_trigger ]; |
||
1056 | |||
1057 | dependency_trigger( $dependent_el ); |
||
1058 | } |
||
1059 | } |
||
1060 | else |
||
1061 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1062 | } |
||
1063 | } ); |
||
1064 | |||
1065 | exclude_flag = '.pods-excludes-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
||
1066 | exclude_specific = exclude_flag + '-' + val.replace( /\_/gi, '-' ); |
||
1067 | |||
1068 | $current.find( exclude_flag ).each( function () { |
||
1069 | var $dependent_el = $( this ), |
||
1070 | dependency_trigger; |
||
1071 | |||
1072 | if ( $dependent_el.parent().is( ':visible' ) ) { |
||
1073 | if ( $field.is( 'input[type=checkbox]' ) ) { |
||
1074 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent_el.is( exclude_specific ) ) ) { |
||
1075 | if ( $dependent_el.is( 'tr' ) ) |
||
1076 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1077 | else |
||
1078 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1079 | } |
||
1080 | else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent_el.is( exclude_specific ) ) ) { |
||
1081 | if ( $dependent_el.is( 'tr' ) ) |
||
1082 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1083 | else |
||
1084 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
1085 | |||
1086 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1087 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1088 | |||
1089 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1090 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1091 | } ); |
||
1092 | |||
1093 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1094 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1095 | |||
1096 | dependency_trigger = window[ dependency_trigger ]; |
||
1097 | |||
1098 | dependency_trigger( $dependent_el ); |
||
1099 | } |
||
1100 | } |
||
1101 | } |
||
1102 | else if ( $dependent_el.is( exclude_specific ) ) { |
||
1103 | if ( $dependent_el.is( 'tr' ) ) |
||
1104 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1105 | else |
||
1106 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1107 | } |
||
1108 | else { |
||
1109 | if ( $dependent_el.is( 'tr' ) ) |
||
1110 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1111 | else |
||
1112 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
1113 | |||
1114 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1115 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1116 | |||
1117 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1118 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1119 | } ); |
||
1120 | |||
1121 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1122 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1123 | |||
1124 | dependency_trigger = window[ dependency_trigger ]; |
||
1125 | |||
1126 | dependency_trigger( $dependent_el ); |
||
1127 | } |
||
1128 | } |
||
1129 | } |
||
1130 | else { |
||
1131 | if ( $field.is( 'input[type=checkbox]' ) ) { |
||
1132 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent_el.is( exclude_specific ) ) ) |
||
1133 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1134 | else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent_el.is( exclude_specific ) ) ) { |
||
1135 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1136 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1137 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1138 | |||
1139 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1140 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1141 | } ); |
||
1142 | |||
1143 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1144 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1145 | |||
1146 | dependency_trigger = window[ dependency_trigger ]; |
||
1147 | |||
1148 | dependency_trigger( $dependent_el ); |
||
1149 | } |
||
1150 | } |
||
1151 | } |
||
1152 | else if ( $dependent_el.is( exclude_specific ) ) |
||
1153 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1154 | else { |
||
1155 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1156 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1157 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1158 | |||
1159 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1160 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1161 | } ); |
||
1162 | |||
1163 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1164 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1165 | |||
1166 | dependency_trigger = window[ dependency_trigger ]; |
||
1167 | |||
1168 | dependency_trigger( $dependent_el ); |
||
1169 | } |
||
1170 | } |
||
1171 | } |
||
1172 | } ); |
||
1173 | |||
1174 | // Search for wildcard dependencies on this element's value |
||
1175 | wildcard_target = '.pods-wildcard-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
||
1176 | wildcard_target_value = val.replace( /\_/gi, '-' ); |
||
1177 | |||
1178 | $current.find( wildcard_target ).each( function () { |
||
1179 | var $dependent_el = $( this ), |
||
1180 | data_attribute = 'pods-wildcard-' + $field.data( 'name-clean' ), |
||
1181 | wildcard_data = $dependent_el.data( data_attribute ), |
||
1182 | match_found, |
||
1183 | dependency_trigger; |
||
1184 | |||
1185 | // Could support objects but limiting to a single string for now |
||
1186 | if ( 'string' !== typeof wildcard_data ) { |
||
1187 | return true; // Continues the outer each() loop |
||
1188 | } |
||
1189 | |||
1190 | // Check for a wildcard match. Can be multiple wildcards in a comma separated list |
||
1191 | match_found = false; |
||
1192 | $.each( wildcard_data.split( ',' ), function( index, this_wildcard ) { |
||
1193 | if ( null !== wildcard_target_value.match( this_wildcard ) ) { |
||
1194 | match_found = true; |
||
1195 | return false; // Stop iterating through further each() elements |
||
1196 | } |
||
1197 | } ); |
||
1198 | |||
1199 | // Set the state of the dependent element |
||
1200 | if ( $dependent_el.parent().is( ':visible' ) ) { |
||
1201 | if ( match_found ) { |
||
1202 | if ( $dependent_el.is( 'tr' ) ) { |
||
1203 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1204 | } |
||
1205 | else { |
||
1206 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
1207 | } |
||
1208 | |||
1209 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1210 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1211 | $dependent_el.find( '.pods-dependency .pods-wildcard-on' ).hide(); |
||
1212 | |||
1213 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1214 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1215 | } ); |
||
1216 | |||
1217 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1218 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1219 | |||
1220 | dependency_trigger = window[ dependency_trigger ]; |
||
1221 | |||
1222 | dependency_trigger( $dependent_el ); |
||
1223 | } |
||
1224 | } |
||
1225 | else { // No wildcard matches |
||
1226 | if ( $dependent_el.is( 'tr' ) ) { |
||
1227 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1228 | } |
||
1229 | else { |
||
1230 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1231 | } |
||
1232 | } |
||
1233 | } |
||
1234 | else { // Parent element wasn't visible |
||
1235 | if ( match_found ) { |
||
1236 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1237 | $dependent_el.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1238 | $dependent_el.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1239 | $dependent_el.find( '.pods-dependency .pods-wildcard-on' ).hide(); |
||
1240 | |||
1241 | $dependent_el.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1242 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1243 | } ); |
||
1244 | |||
1245 | if ( $dependent_el.is( '[data-dependency-trigger]' ) ) { |
||
1246 | dependency_trigger = $dependent_el.data( 'dependency-trigger' ); |
||
1247 | |||
1248 | dependency_trigger = window[ dependency_trigger ]; |
||
1249 | |||
1250 | dependency_trigger( $dependent_el ); |
||
1251 | } |
||
1252 | } |
||
1253 | else { // No wildcard matches |
||
1254 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1255 | } |
||
1256 | } |
||
1257 | } ); |
||
1258 | }, |
||
1259 | dependency : function ( init ) { |
||
1260 | // Hide all dependents |
||
1261 | $( '.pods-dependency .pods-depends-on, .pods-dependency .pods-excludes-on, .pods-dependency .pods-wildcard-on' ).hide(); |
||
1262 | |||
1263 | // Handle dependent toggle |
||
1264 | $( '.pods-admin' ).on( 'change', '.pods-dependent-toggle[data-name-clean]', function ( e ) { |
||
1265 | var selectionTypeRegex = /pick-format-type$/g; |
||
1266 | var elementId = $( this ).attr( 'id' ); |
||
1267 | var selectionType, selectionFormatId; |
||
1268 | |||
1269 | // Setup dependencies for the field that changed |
||
1270 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1271 | |||
1272 | // Also force a dependency update for the appropriate format when "selection type" changes |
||
1273 | if ( selectionTypeRegex.test( elementId ) ) { |
||
1274 | selectionType = $( this ).val(); |
||
1275 | selectionFormatId = elementId.replace( selectionTypeRegex, 'pick-format-' + selectionType ); |
||
1276 | methods[ 'setup_dependencies' ]( $( '#' + selectionFormatId ) ); |
||
1277 | } |
||
1278 | |||
1279 | } ); |
||
1280 | |||
1281 | if ( 'undefined' != typeof init && init ) { |
||
1282 | $( '.pods-dependency' ).find( '.pods-dependent-toggle' ).each( function () { |
||
1283 | $( this ).trigger( 'change' ); |
||
1284 | } ); |
||
1285 | } |
||
1286 | }, |
||
1287 | dependency_tabs : function () { |
||
1288 | // Hide all dependents |
||
1289 | $( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1290 | |||
1291 | // Handle dependent toggle |
||
1292 | $( '.pods-admin' ).on( 'click', '.pods-dependency-tabs .pods-dependent-tab', function ( e ) { |
||
1293 | var $el = $( this ); |
||
1294 | var $current = $el.closest( '.pods-dependency-tabs' ); |
||
1295 | var $field = $el; |
||
1296 | |||
1297 | var dependent_flag = '.pods-depends-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
||
1298 | var dependent_specific = dependent_flag + '-' + $el.val().replace( /\_/gi, '-' ); |
||
1299 | |||
1300 | $current.find( dependent_flag ).each( function () { |
||
1301 | var $dependent_el = $( this ); |
||
1302 | |||
1303 | if ( $dependent_el.parent().is( ':visible' ) ) { |
||
1304 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
||
1305 | if ( $dependent_el.is( 'tr' ) ) |
||
1306 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1307 | else |
||
1308 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
1309 | |||
1310 | $dependent_el.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1311 | $dependent_el.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
||
1312 | |||
1313 | $dependent_el.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1314 | $( this ).trigger( 'click' ); |
||
1315 | } ); |
||
1316 | } |
||
1317 | else if ( $dependent_el.is( dependent_specific ) ) { |
||
1318 | if ( $dependent_el.is( 'tr' ) ) |
||
1319 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1320 | else |
||
1321 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
1322 | |||
1323 | $dependent_el.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1324 | $dependent_el.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
||
1325 | |||
1326 | $dependent_el.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1327 | $( this ).trigger( 'click' ); |
||
1328 | } ); |
||
1329 | } |
||
1330 | else { |
||
1331 | if ( $dependent_el.is( 'tr' ) ) |
||
1332 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1333 | else |
||
1334 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1335 | } |
||
1336 | } |
||
1337 | else { |
||
1338 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
||
1339 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1340 | $dependent_el.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1341 | $dependent_el.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
||
1342 | |||
1343 | $dependent_el.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1344 | $( this ).trigger( 'click' ); |
||
1345 | } ); |
||
1346 | } |
||
1347 | else if ( $dependent_el.is( dependent_specific ) ) { |
||
1348 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1349 | $dependent_el.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1350 | $dependent_el.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
||
1351 | |||
1352 | $dependent_el.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1353 | $( this ).trigger( 'click' ); |
||
1354 | } ); |
||
1355 | } |
||
1356 | else |
||
1357 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1358 | } |
||
1359 | } ); |
||
1360 | |||
1361 | var exclude_flag = '.pods-excludes-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
||
1362 | var exclude_specific = exclude_flag + '-' + $el.val().replace( /\_/gi, '-' ); |
||
1363 | |||
1364 | $current.find( exclude_flag ).each( function () { |
||
1365 | var $dependent_el = $( this ); |
||
1366 | |||
1367 | if ( $dependent_el.parent().is( ':visible' ) ) { |
||
1368 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
||
1369 | if ( $dependent_el.is( 'tr' ) ) |
||
1370 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1371 | else |
||
1372 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1373 | } |
||
1374 | else if ( $dependent_el.is( exclude_specific ) ) { |
||
1375 | if ( $dependent_el.is( 'tr' ) ) |
||
1376 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1377 | else |
||
1378 | $dependent_el.slideUp().removeClass( 'pods-dependent-visible' ); |
||
1379 | } |
||
1380 | else { |
||
1381 | if ( $dependent_el.is( 'tr' ) ) |
||
1382 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1383 | else |
||
1384 | $dependent_el.slideDown().addClass( 'pods-dependent-visible' ); |
||
1385 | |||
1386 | $dependent_el.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1387 | $dependent_el.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
||
1388 | |||
1389 | $dependent_el.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1390 | $( this ).trigger( 'click' ); |
||
1391 | } ); |
||
1392 | } |
||
1393 | } |
||
1394 | else { |
||
1395 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) |
||
1396 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1397 | else if ( $dependent_el.is( exclude_specific ) ) |
||
1398 | $dependent_el.hide().removeClass( 'pods-dependent-visible' ); |
||
1399 | else { |
||
1400 | $dependent_el.show().addClass( 'pods-dependent-visible' ); |
||
1401 | $dependent_el.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
||
1402 | $dependent_el.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
||
1403 | |||
1404 | $dependent_el.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1405 | $( this ).trigger( 'click' ); |
||
1406 | } ); |
||
1407 | } |
||
1408 | } |
||
1409 | } ); |
||
1410 | } ); |
||
1411 | |||
1412 | $( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
||
1413 | $( this ).click(); |
||
1414 | } ); |
||
1415 | }, |
||
1416 | sortable : function () { |
||
1417 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
||
1418 | $( 'tbody.pods-manage-list' ).addClass( 'pods-manage-sortable' ).sortable( { |
||
1419 | items : 'tr.pods-manage-row', |
||
1420 | axis : 'y', |
||
1421 | handle : '.pods-manage-sort', |
||
1422 | stop : function ( event, ui ) { |
||
1423 | $( 'tr.pods-manage-row' ).removeClass( 'alternate' ); |
||
1424 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
||
1425 | } |
||
1426 | } ); |
||
1427 | }, |
||
1428 | advanced : function () { |
||
1429 | $( '.pods-advanced' ).hide(); |
||
1430 | |||
1431 | $( '.pods-admin' ).on( 'click', '.pods-advanced-toggle', function ( e ) { |
||
1432 | $advanced = $( this ).closest( 'div' ).find( '.pods-advanced' ); |
||
1433 | |||
1434 | if ( $advanced.is( ':visible' ) ) { |
||
1435 | $( this ).text( $( this ).text().replace( '-', '+' ) ); |
||
1436 | $advanced.slideUp(); |
||
1437 | } |
||
1438 | else { |
||
1439 | $( this ).text( $( this ).text().replace( '+', '-' ) ); |
||
1440 | $advanced.slideDown(); |
||
1441 | } |
||
1442 | |||
1443 | e.preventDefault(); |
||
1444 | } ); |
||
1445 | }, |
||
1446 | collapsible : function ( row ) { |
||
1447 | var new_row, orig_fields; |
||
1448 | |||
1449 | new_row = row; |
||
1450 | |||
1451 | if ( new_row[ 0 ] ) |
||
1452 | new_row = new_row.html(); |
||
1453 | |||
1454 | // Hide all rows |
||
1455 | $( 'div.pods-manage-row-wrapper' ).hide(); |
||
1456 | |||
1457 | orig_fields = {}; |
||
1458 | |||
1459 | // Handle 'Edit' action |
||
1460 | $( 'tbody.pods-manage-list' ).on( 'click', 'a.pods-manage-row-edit', function ( e ) { |
||
1461 | var $row, $row_label, $row_content, $tbody; |
||
1462 | var row_counter, edit_row, $field_wrapper, field_data, field_array_counter, json_name; |
||
1463 | |||
1464 | $( this ).css( 'cursor', 'default' ); |
||
1465 | $( this ).prop( 'disabled', true ); |
||
1466 | |||
1467 | $row = $( this ).closest( 'tr.pods-manage-row' ); |
||
1468 | $row_label = $row.find( 'td.pods-manage-row-label' ); |
||
1469 | $row_content = $row_label.find( 'div.pods-manage-row-wrapper' ); |
||
1470 | |||
1471 | if ( 'undefined' == typeof orig_fields[ $row.data( 'id' ) ] ) |
||
1472 | orig_fields[ $row.data( 'id' ) ] = {}; |
||
1473 | |||
1474 | // Row active, hide it |
||
1475 | if ( $row_content.is( ':visible' ) ) { |
||
1476 | if ( !$row.hasClass( 'pods-field-new' ) ) { |
||
1477 | $row_content.slideUp( 'slow', function () { |
||
1478 | $row.toggleClass( 'pods-manage-row-expanded' ); |
||
1479 | $row_label.prop( 'colspan', '1' ); |
||
1480 | |||
1481 | $row_content.find( 'input, select, textarea' ).each( function () { |
||
1482 | if ( 'undefined' != typeof orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] ) { |
||
1483 | if ( $( this ).is( 'input[type=checkbox]' ) ) |
||
1484 | $( this ).prop( 'checked', orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] ); |
||
1485 | else |
||
1486 | $( this ).val( orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] ); |
||
1487 | } |
||
1488 | } ); |
||
1489 | } ); |
||
1490 | } |
||
1491 | else { |
||
1492 | $tbody = $( this ).closest( 'tbody.pods-manage-list' ); |
||
1493 | |||
1494 | $row.animate( {backgroundColor : '#B80000'} ); |
||
1495 | |||
1496 | $row.fadeOut( 'slow', function () { |
||
1497 | $( this ).remove(); |
||
1498 | if ( 0 === $( 'tbody.pods-manage-list tr.pods-manage-row' ).length ) |
||
1499 | $tbody.find( 'tr.no-items' ).show(); |
||
1500 | } ); |
||
1501 | |||
1502 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) |
||
1503 | $( this ).closest( 'tbody.pods-manage-list' ).sortable( 'refresh' ); |
||
1504 | } |
||
1505 | } |
||
1506 | // Row inactive, show it |
||
1507 | else { |
||
1508 | if ( $row.hasClass( 'pods-field-init' ) && 'undefined' != typeof new_row && null !== new_row ) { |
||
1509 | row_counter = $row.data( 'row' ); |
||
1510 | |||
1511 | edit_row = new_row.replace( /\_\_1/gi, row_counter ).replace( /\-\-1/gi, row_counter ); |
||
1512 | $field_wrapper = $row_content.find( 'div.pods-manage-field' ); |
||
1513 | |||
1514 | if ( $row.hasClass( 'pods-field-duplicated' ) ) { |
||
1515 | $row.removeClass( 'pods-field-duplicated' ); |
||
1516 | } else { |
||
1517 | $field_wrapper.append( edit_row ); |
||
1518 | |||
1519 | // Duct tape to handle fields added dynamically |
||
1520 | PodsDFV.init(); |
||
1521 | } |
||
1522 | |||
1523 | $field_wrapper.find( '.pods-depends-on' ).hide(); |
||
1524 | $field_wrapper.find( '.pods-excludes-on' ).hide(); |
||
1525 | |||
1526 | $field_wrapper.find( '.pods-dependent-toggle' ).each( function () { |
||
1527 | $( this ).trigger( 'change' ); |
||
1528 | } ); |
||
1529 | |||
1530 | field_data = jQuery.parseJSON( $row_content.find( 'input.field_data' ).val() ); |
||
1531 | |||
1532 | field_array_counter = 0; |
||
1533 | |||
1534 | $field_wrapper.find( 'input, select, textarea' ).each( function () { |
||
1535 | json_name = $( this ).prop( 'name' ).replace( 'field_data[' + row_counter + '][', '' ).replace( /\[\d*\]/gi, '' ).replace( '[', '' ).replace( ']', '' ); |
||
1536 | |||
1537 | if ( 'undefined' == typeof field_data[ json_name ] ) |
||
1538 | return; |
||
1539 | |||
1540 | if ( 0 < $( this ).prop( 'name' ).indexOf( '[]' ) || $( this ).prop( 'name' ).replace( 'field_data[' + row_counter + ']', '' ).match( /\[\d*\]/ ) ) { |
||
1541 | if ( $( this ).is( 'input[type=checkbox]' ) ) { |
||
1542 | $( this ).prop( 'checked', ( -1 < jQuery.inArray( $( this ).val(), field_data[ json_name ] ) ) ); |
||
1543 | |||
1544 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).prop( 'checked' ); |
||
1545 | } |
||
1546 | else if ( 'undefined' != typeof field_data[ json_name ][ field_array_counter ] ) { |
||
1547 | $( this ).val( field_data[ json_name ][ field_array_counter ] ); |
||
1548 | |||
1549 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).val(); |
||
1550 | } |
||
1551 | |||
1552 | field_array_counter++; |
||
1553 | } |
||
1554 | else { |
||
1555 | field_array_counter = 0; |
||
1556 | |||
1557 | if ( $( this ).is( 'input[type=checkbox]' ) ) { |
||
1558 | $( this ).prop( 'checked', ( $( this ).val() == field_data[ json_name ] ) ); |
||
1559 | |||
1560 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).prop( 'checked' ); |
||
1561 | } |
||
1562 | else { |
||
1563 | $( this ).val( field_data[ json_name ] ); |
||
1564 | |||
1565 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).val(); |
||
1566 | } |
||
1567 | } |
||
1568 | } ); |
||
1569 | |||
1570 | $field_wrapper.find( '.pods-tabbed ul.pods-tabs .pods-tab:first a' ).addClass( 'selected' ); |
||
1571 | $field_wrapper.find( '.pods-tabbed .pods-tab-group .pods-tab:first' ).show(); |
||
1572 | |||
1573 | $row.removeClass( 'pods-field-init' ); |
||
1574 | |||
1575 | $( document ).Pods( 'qtip', $row ); |
||
1576 | } |
||
1577 | else { |
||
1578 | $row_content.find( 'input, select, textarea' ).each( function () { |
||
1579 | if ( $( this ).is( 'input[type=checkbox]' ) ) |
||
1580 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).prop( 'checked' ); |
||
1581 | else |
||
1582 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).val(); |
||
1583 | } ); |
||
1584 | } |
||
1585 | |||
1586 | $row.toggleClass( 'pods-manage-row-expanded' ); |
||
1587 | $row_label.prop( 'colspan', '3' ); |
||
1588 | |||
1589 | methods[ 'scroll' ]( $row ); |
||
1590 | |||
1591 | $row_content.slideDown(); |
||
1592 | |||
1593 | |||
1594 | $row_content.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1595 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1596 | } ); |
||
1597 | |||
1598 | } |
||
1599 | |||
1600 | $( this ).css( 'cursor', 'pointer' ); |
||
1601 | $( this ).prop( 'disabled', false ); |
||
1602 | |||
1603 | e.preventDefault(); |
||
1604 | } ) |
||
1605 | // Handle 'Save' action |
||
1606 | .on( 'click', '.pods-manage-row-save a.button-primary', function ( e ) { |
||
1607 | $( this ).css( 'cursor', 'default' ); |
||
1608 | $( this ).prop( 'disabled', true ); |
||
1609 | |||
1610 | var $row = $( this ).closest( 'tr.pods-manage-row' ); |
||
1611 | var $row_label = $row.find( 'td.pods-manage-row-label' ); |
||
1612 | var $row_content = $row_label.find( 'div.pods-manage-row-wrapper' ); |
||
1613 | var $field_wrapper = $row_content.find( 'div.pods-manage-field' ); |
||
1614 | var $row_value = $row_content.find( 'input.field_data' ).val(); |
||
1615 | var color = ( $row.hasClass( 'alternate' ) ? '#F1F1F1' : '#FFFFFF' ); |
||
1616 | var row_id = $row.data( 'row' ); |
||
1617 | var field_data = {}; |
||
1618 | |||
1619 | if ( 'undefined' != typeof $row_value && null != $row_value && '' !== $row_value ) { |
||
1620 | field_data = jQuery.parseJSON( $row_value ); |
||
1621 | } |
||
1622 | |||
1623 | var valid_form = true; |
||
1624 | |||
1625 | $field_wrapper.find( 'input, select, textarea' ).each( function () { |
||
1626 | var $el = $( this ); |
||
1627 | |||
1628 | if ( '' !== $el.prop( 'name' ) ) { |
||
1629 | // TinyMCE support |
||
1630 | if ( 'object' == typeof( tinyMCE ) && -1 < $el.prop( 'class' ).indexOf( 'pods-ui-field-tinymce' ) ) { |
||
1631 | var ed = tinyMCE.get( $el.prop( 'id' ) ); |
||
1632 | |||
1633 | $el.val( ed.getContent() ); |
||
1634 | } |
||
1635 | |||
1636 | var val = $el.val(), |
||
1637 | field_array = $el.prop( 'name' ).match( /\[(\w*|)\]/gi ), |
||
1638 | field_name = ( ( null != field_array && 1 < field_array.length ) ? field_array[ 1 ].replace( '[', '' ).replace( ']', '' ) : '' ), |
||
1639 | field_found = -1; |
||
1640 | |||
1641 | if ( '' == field_name ) |
||
1642 | return; |
||
1643 | |||
1644 | if ( $el.is( 'input[type=checkbox]' ) && $el.is( '.pods-form-ui-field-type-pick' ) ) { |
||
1645 | if ( 'object' == typeof field_data[ field_name ] || 'array' == typeof field_data[ field_name ] ) { |
||
1646 | field_found = jQuery.inArray( val, field_data[ field_name ] ); |
||
1647 | |||
1648 | if ( -1 < field_found ) { |
||
1649 | if ( !$el.is( ':checked' ) ) |
||
1650 | field_data[ field_name ].splice( field_found, 1 ); |
||
1651 | } |
||
1652 | else if ( $el.is( ':checked' ) ) |
||
1653 | field_data[ field_name ].push( val ); |
||
1654 | } |
||
1655 | else { |
||
1656 | field_data[ field_name ] = []; |
||
1657 | |||
1658 | if ( $el.is( ':checked' ) ) |
||
1659 | field_data[ field_name ].push( val ); |
||
1660 | } |
||
1661 | |||
1662 | return; |
||
1663 | } |
||
1664 | else if ( $el.is( 'input[type=checkbox]' ) && !$el.is( ':checked' ) ) { |
||
1665 | if ( 1 == val ) |
||
1666 | val = 0; |
||
1667 | else |
||
1668 | val = ''; |
||
1669 | } |
||
1670 | else if ( $el.is( 'input[type=radio]' ) && !$el.is( ':checked' ) ) |
||
1671 | val = ''; |
||
1672 | |||
1673 | if ( $el.is( ':visible' ) && $el.hasClass( 'pods-validate pods-validate-required' ) && '' === $el.val() ) { |
||
1674 | $el.trigger( 'change' ); |
||
1675 | |||
1676 | if ( false !== valid_form ) |
||
1677 | $el.focus(); |
||
1678 | |||
1679 | valid_form = false; |
||
1680 | } |
||
1681 | |||
1682 | if ( $el.is( 'input[type=checkbox]' ) && $el.is( '.pods-form-ui-field-type-pick' ) ) { |
||
1683 | if ( -1 == field_found ) { |
||
1684 | if ( 'object' != typeof field_data[ field_name ] && 'array' != typeof field_data[ field_name ] ) |
||
1685 | field_data[ field_name ] = []; |
||
1686 | |||
1687 | if ( '' != val ) |
||
1688 | field_data[ field_name ].push( val ); |
||
1689 | } |
||
1690 | } |
||
1691 | else if ( 2 == field_array.length ) |
||
1692 | field_data[ field_name ] = val; |
||
1693 | else if ( 3 == field_array.length ) { |
||
1694 | the_field = parseInt( field_array[ 2 ].replace( '[', '' ).replace( ']', '' ) ); |
||
1695 | |||
1696 | if ( isNaN( the_field ) ) |
||
1697 | field_data[ field_name ] = val; |
||
1698 | else { |
||
1699 | if ( 'undefined' == typeof field_data[ field_name ] ) |
||
1700 | field_data[ field_name ] = {}; |
||
1701 | |||
1702 | while ( 'undefined' != typeof( field_data[ field_name ][ the_field ] ) ) { |
||
1703 | the_field++; |
||
1704 | } |
||
1705 | |||
1706 | field_data[ field_name ][ the_field ] = val; |
||
1707 | } |
||
1708 | } |
||
1709 | } |
||
1710 | } ); |
||
1711 | |||
1712 | if ( valid_form ) { |
||
1713 | $row_content.find( 'input.field_data' ).val( $.toJSON( field_data ) ); |
||
1714 | |||
1715 | $row.css( 'backgroundColor', '#FFFF33' ).animate( |
||
1716 | { backgroundColor : color }, |
||
1717 | { |
||
1718 | duration : 600, |
||
1719 | complete : function () { |
||
1720 | $( this ).css( 'backgroundColor', '' ); |
||
1721 | } |
||
1722 | } |
||
1723 | ); |
||
1724 | |||
1725 | if ( 'undefined' != typeof pods_field_types && null !== pods_field_types ) { |
||
1726 | $row.find( 'td.pods-manage-row-label a.row-label' ).html( $row_content.find( 'input#pods-form-ui-field-data-' + row_id + '-label' ).val() ); |
||
1727 | |||
1728 | if ( $row_content.find( 'input#pods-form-ui-field-data-' + row_id + '-required' ).is( ':checked' ) ) |
||
1729 | $row.find( 'td.pods-manage-row-label abbr.required' ).show(); |
||
1730 | else |
||
1731 | $row.find( 'td.pods-manage-row-label abbr.required' ).hide(); |
||
1732 | |||
1733 | $row.find( 'td.pods-manage-row-name a' ).html( $row_content.find( 'input#pods-form-ui-field-data-' + row_id + '-name' ).val() ); |
||
1734 | |||
1735 | var field_type = $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-type' ).val(); |
||
1736 | var pick_object = $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-pick-object' ).val(); |
||
1737 | var field_type_desc = ''; |
||
1738 | |||
1739 | if ( 'pick' == field_type && 0 != pick_object ) { |
||
1740 | $.each( pods_pick_objects, function ( i, n ) { |
||
1741 | if ( pick_object == i ) { |
||
1742 | field_type_desc = '<br /><span class="pods-manage-field-type-desc">› ' + n + '</span>'; |
||
1743 | return false; |
||
1744 | } |
||
1745 | } ); |
||
1746 | } |
||
1747 | $.each( pods_field_types, function ( i, n ) { |
||
1748 | if ( field_type == i ) { |
||
1749 | field_type = n; |
||
1750 | return false; |
||
1751 | } |
||
1752 | } ); |
||
1753 | |||
1754 | $row.find( 'td.pods-manage-row-type' ).html( field_type |
||
1755 | + field_type_desc |
||
1756 | + ' <span class="pods-manage-row-more">[type: ' + $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-type' ).val() + ']</span>' ); |
||
1757 | } |
||
1758 | |||
1759 | $row_content.slideUp( 'slow', function () { |
||
1760 | $row_label.prop( 'colspan', '1' ); |
||
1761 | $row.removeClass( 'pods-manage-row-expanded' ); |
||
1762 | $row.removeClass( 'pods-field-new' ); |
||
1763 | $row.addClass( 'pods-field-updated' ); |
||
1764 | } ); |
||
1765 | } |
||
1766 | |||
1767 | $( this ).css( 'cursor', 'pointer' ); |
||
1768 | $( this ).prop( 'disabled', false ); |
||
1769 | |||
1770 | e.preventDefault(); |
||
1771 | } ) |
||
1772 | // Handle 'Cancel' action |
||
1773 | .on( 'click', '.pods-manage-row-actions a.pods-manage-row-cancel', function ( e ) { |
||
1774 | $( this ).closest( 'tr.pods-manage-row' ).find( 'a.pods-manage-row-edit' ).click(); |
||
1775 | |||
1776 | e.preventDefault(); |
||
1777 | } ); |
||
1778 | }, |
||
1779 | toggled : function () { |
||
1780 | $( 'body' ).on( 'click', '.pods-toggled .handlediv, .pods-toggled h3', function () { |
||
1781 | $( this ).parent().find( '.inside' ).slideToggle(); |
||
1782 | return false; |
||
1783 | } ); |
||
1784 | }, |
||
1785 | flexible : function ( row ) { |
||
1786 | var new_row = row, |
||
1787 | row_counter = 0; |
||
1788 | |||
1789 | if ( new_row[ 0 ] ) { |
||
1790 | new_row = new_row.html(); |
||
1791 | |||
1792 | // Don't count flexible row |
||
1793 | row_counter = -1; |
||
1794 | } |
||
1795 | |||
1796 | row_counter += $( 'tr.pods-manage-row' ).length; |
||
1797 | |||
1798 | if ( 'undefined' != typeof new_row && null !== new_row ) { |
||
1799 | // Handle 'Add' action |
||
1800 | $( '.pods-manage-row-add' ).on( 'click', 'a', function ( e ) { |
||
1801 | var add_row, $new_row, $tbody; |
||
1802 | |||
1803 | e.preventDefault(); |
||
1804 | |||
1805 | $( this ).css( 'cursor', 'default' ); |
||
1806 | $( this ).prop( 'disabled', true ); |
||
1807 | |||
1808 | row_counter++; |
||
1809 | |||
1810 | add_row = new_row.replace( /__1/gi, row_counter ).replace( /--1/gi, row_counter ); |
||
1811 | $tbody = $( this ).parent().parent().find( 'tbody.pods-manage-list' ); |
||
1812 | |||
1813 | $tbody.find( 'tr.no-items' ).hide(); |
||
1814 | $tbody.append( '<tr id="row-' + row_counter + '" class="pods-manage-row pods-field-new pods-field-' + row_counter + ' pods-submittable-fields" valign="top">' + add_row + '</tr>' ); |
||
1815 | |||
1816 | $new_row = $tbody.find( 'tr#row-' + row_counter ); |
||
1817 | |||
1818 | // Duct tape to handle fields added dynamically |
||
1819 | PodsDFV.init(); |
||
1820 | |||
1821 | $new_row.data( 'row', row_counter ); |
||
1822 | $new_row.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1823 | $new_row.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1824 | |||
1825 | $new_row.find( '.pods-manage-row-wrapper' ).hide( 0, function () { |
||
1826 | $new_row.find( 'a.row-label.pods-manage-row-edit' ).click(); |
||
1827 | } ); |
||
1828 | |||
1829 | $( '.pods-tabs .pods-tab:first a', $new_row ).addClass( 'selected' ); |
||
1830 | $( '.pods-tab-group', $new_row ).find( '.pods-tab:first' ).show(); |
||
1831 | |||
1832 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) |
||
1833 | $tbody.sortable( 'refresh' ); |
||
1834 | |||
1835 | $( 'tr.pods-manage-row' ).removeClass( 'alternate' ); |
||
1836 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
||
1837 | |||
1838 | methods[ 'sluggables' ]( $new_row ); |
||
1839 | |||
1840 | $( this ).css( 'cursor', 'pointer' ); |
||
1841 | $( this ).prop( 'disabled', false ); |
||
1842 | |||
1843 | $( document ).Pods( 'qtip', $new_row ); |
||
1844 | |||
1845 | methods[ 'scroll' ]( $new_row ); |
||
1846 | } ); |
||
1847 | |||
1848 | // Handle 'Duplicate' action |
||
1849 | $( 'tbody.pods-manage-list' ).on( 'click', 'a.pods-manage-row-duplicate', function ( e ) { |
||
1850 | var add_row, field_data; |
||
1851 | var $tbody, $row, $row_label, $row_content, $new_row, $new_row_label, $new_row_content; |
||
1852 | |||
1853 | e.preventDefault(); |
||
1854 | |||
1855 | $( this ).css( 'cursor', 'default' ); |
||
1856 | $( this ).prop( 'disabled', true ); |
||
1857 | |||
1858 | $row = $( this ).closest( 'tr.pods-manage-row' ); |
||
1859 | $row_label = $row.find( 'td.pods-manage-row-label' ); |
||
1860 | $row_content = $row_label.find( 'div.pods-manage-row-wrapper' ); |
||
1861 | |||
1862 | field_data = jQuery.parseJSON( $row_content.find( 'input.field_data' ).val() ); |
||
1863 | |||
1864 | row_counter++; |
||
1865 | |||
1866 | add_row = new_row.replace( /__1/gi, row_counter ).replace( /--1/gi, row_counter ); |
||
1867 | $tbody = $( this ).closest( 'tbody.pods-manage-list' ); |
||
1868 | |||
1869 | $tbody.find( 'tr.no-items' ).hide(); |
||
1870 | $tbody.append( '<tr id="row-' + row_counter + '" class="pods-manage-row pods-field-init pods-field-new pods-field-duplicated pods-field-' + row_counter + ' pods-submittable-fields" valign="top">' + add_row + '</tr>' ); |
||
1871 | |||
1872 | $new_row = $tbody.find( 'tr#row-' + row_counter ); |
||
1873 | $new_row_label = $new_row.find( 'td.pods-manage-row-label' ); |
||
1874 | $new_row_content = $new_row_label.find( 'div.pods-manage-row-wrapper' ); |
||
1875 | |||
1876 | // Duct tape to handle fields added dynamically |
||
1877 | PodsDFV.init(); |
||
1878 | |||
1879 | field_data[ 'name' ] += '_copy'; |
||
1880 | field_data[ 'label' ] += ' (' + PodsI18n.__( 'Copy' ) + ')'; |
||
1881 | field_data[ 'id' ] = 0; |
||
1882 | |||
1883 | $new_row_label.find( 'a.pods-manage-row-edit.row-label' ).html( field_data[ 'label' ] ); |
||
1884 | |||
1885 | $new_row_content.find( 'input.field_data' ).val( $.toJSON( field_data ) ); |
||
1886 | |||
1887 | $new_row.data( 'row', row_counter ); |
||
1888 | $new_row.find( '.pods-dependency .pods-depends-on' ).hide(); |
||
1889 | $new_row.find( '.pods-dependency .pods-excludes-on' ).hide(); |
||
1890 | |||
1891 | $new_row.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
||
1892 | methods[ 'setup_dependencies' ]( $( this ) ); |
||
1893 | } ); |
||
1894 | |||
1895 | $new_row.find( '.pods-manage-row-wrapper' ).hide( 0, function () { |
||
1896 | $new_row.find( 'a.pods-manage-row-edit' ).click(); |
||
1897 | } ); |
||
1898 | |||
1899 | $( '.pods-tabs .pods-tab:first a', $new_row ).addClass( 'selected' ); |
||
1900 | $( '.pods-tab-group', $new_row ).find( '.pods-tab:first' ).show(); |
||
1901 | |||
1902 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) |
||
1903 | $tbody.sortable( 'refresh' ); |
||
1904 | |||
1905 | $( 'tr.pods-manage-row' ).removeClass( 'alternate' ); |
||
1906 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
||
1907 | |||
1908 | methods[ 'sluggables' ]( $new_row ); |
||
1909 | |||
1910 | $( this ).css( 'cursor', 'pointer' ); |
||
1911 | $( this ).prop( 'disabled', false ); |
||
1912 | |||
1913 | $( document ).Pods( 'qtip', $new_row ); |
||
1914 | |||
1915 | methods[ 'scroll' ]( $new_row ); |
||
1916 | } ); |
||
1917 | } |
||
1918 | |||
1919 | // Handle 'Delete' action |
||
1920 | $( 'tbody.pods-manage-list' ).on( 'click', 'a.submitdelete', function ( e ) { |
||
1921 | $( this ).css( 'cursor', 'default' ); |
||
1922 | $( this ).prop( 'disabled', true ); |
||
1923 | |||
1924 | // @todo: Make this confirm pretty so that it's inline instead of JS confirm |
||
1925 | if ( confirm( 'Are you sure you want to delete this field?' ) ) { |
||
1926 | var $row = $( this ).closest( 'tr.pods-manage-row' ); |
||
1927 | var $tbody = $( this ).closest( 'tbody.pods-manage-list' ); |
||
1928 | |||
1929 | $row.animate( {backgroundColor : '#B80000'} ); |
||
1930 | |||
1931 | $row.fadeOut( 'slow', function () { |
||
1932 | $( this ).remove(); |
||
1933 | if ( 0 === $( 'tbody.pods-manage-list tr.pods-manage-row' ).length ) |
||
1934 | $tbody.find( 'tr.no-items' ).show(); |
||
1935 | } ); |
||
1936 | |||
1937 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) |
||
1938 | $( this ).closest( 'tbody.pods-manage-list' ).sortable( 'refresh' ); |
||
1939 | |||
1940 | pods_changed = true; |
||
1941 | |||
1942 | //row_counter--; |
||
1943 | } |
||
1944 | |||
1945 | $( this ).css( 'cursor', 'pointer' ); |
||
1946 | $( this ).prop( 'disabled', false ); |
||
1947 | |||
1948 | e.preventDefault(); |
||
1949 | } ); |
||
1950 | }, |
||
1951 | confirm : function () { |
||
1952 | $( 'a.pods-confirm' ).on( 'click', function ( e ) { |
||
1953 | var $el = $( this ); |
||
1954 | |||
1955 | if ( 'undefined' != typeof $el.data( 'confirm' ) && !confirm( $el.data( 'confirm' ) ) ) |
||
1956 | return false; |
||
1957 | } ); |
||
1958 | }, |
||
1959 | exit_confirm : function () { |
||
1960 | $( 'form.pods-submittable' ).on( 'change', '.pods-submittable-fields input:not(:button,:submit), .pods-submittable-fields textarea, .pods-submittable-fields select', function () { |
||
1961 | pods_changed = true; |
||
1962 | |||
1963 | window.onbeforeunload = function () { |
||
1964 | if ( pods_changed ) |
||
1965 | return PodsI18n.__( 'Navigating away from this page will discard any changes you have made.' ); |
||
1966 | } |
||
1967 | } ); |
||
1968 | |||
1969 | $( 'form.pods-submittable' ).on( 'click', '.submitdelete', function () { |
||
1970 | pods_changed = false; |
||
1971 | } ); |
||
1972 | }, |
||
1973 | qtip: function ( element ) { |
||
1974 | $( element ).find( '.pods-qtip' ).each( function ( index, element ) { |
||
1975 | $( element ).qtip( { |
||
1976 | content: { |
||
1977 | attr: 'alt' |
||
1978 | }, |
||
1979 | style: { |
||
1980 | classes: 'ui-tooltip-light ui-tooltip-shadow ui-tooltip-rounded' |
||
1981 | }, |
||
1982 | show: { |
||
1983 | effect: function ( offset ) { |
||
1984 | $( this ).fadeIn( 'fast' ); |
||
1985 | } |
||
1986 | }, |
||
1987 | hide: { |
||
1988 | fixed: true, |
||
1989 | delay: 300 |
||
1990 | }, |
||
1991 | position: { |
||
1992 | container: $( element ).closest( '.pods-submittable' ), |
||
1993 | my: 'bottom left', |
||
1994 | adjust: { |
||
1995 | y: -14 |
||
1996 | } |
||
1997 | } |
||
1998 | } ); |
||
1999 | } ); |
||
2000 | }, |
||
2001 | scroll: function ( selector, callback ) { |
||
2002 | var offset = 10; |
||
2003 | |||
2004 | if ( $( '#wpadminbar' )[ 0 ] ) |
||
2005 | offset += $( '#wpadminbar' ).height(); |
||
2006 | |||
2007 | $( 'html, body' ).animate( { scrollTop : $( selector ).offset().top - offset }, 'slow', callback ); |
||
2008 | }, |
||
2009 | scroll_to : function () { |
||
2010 | $( '.pods-admin' ).on( 'click', 'a.pods-scroll-to', function ( e ) { |
||
2011 | e.preventDefault(); |
||
2012 | |||
2013 | methods[ 'scroll' ]( '#' + this.hash ); |
||
2014 | } ); |
||
2015 | } |
||
2016 | }; |
||
2017 | |||
2018 | $.fn.Pods = function ( method ) { |
||
2019 | if ( methods[ method ] ) { |
||
2020 | return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) ); |
||
2021 | } |
||
2022 | // Don't need this part (yet) |
||
2023 | /* |
||
2024 | else if ( typeof method === 'object' || !method ) { |
||
2025 | return methods.init.apply( this, arguments ); |
||
2026 | } |
||
2027 | */ |
||
2028 | else { |
||
2029 | $.error( 'Method ' + method + ' does not exist on jQuery.Pods' ); |
||
2030 | } |
||
2031 | }; |
||
2032 | } )( jQuery ); |
||
2033 |