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