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