blocks
4 months ago
cleditor
4 years ago
codemirror
2 years ago
dfv
3 months 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
1 year ago
jquery.pods.upgrade.js
5 years ago
pods-i18n.js
8 years ago
pods-link-picker.js
11 months ago
qtip.js
3 years ago
react-jsx-runtime.js
3 months ago
react-jsx-runtime.js.LICENSE.txt
1 year ago
jquery.pods.js
2098 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( /([^0-9a-zA-Z\_\- ])/g, '' ), |
| 570 | nameRaw = $( this ).prop( 'name' ), |
| 571 | name = nameRaw.replace( /\[/g, '\\[' ).replace( /\]/g, '\\]' ); |
| 572 | |
| 573 | if ( slug.length ) { |
| 574 | slug = slug.replace(/_+/g, '_') |
| 575 | .replace(/\-+/g, '-'); |
| 576 | |
| 577 | var slug_lower = slug.toLowerCase(), |
| 578 | slug_sanitized = slug.replace(/([^0-9a-zA-Z\_\- ])/g, '') |
| 579 | .replace(/([_\- ]+)$/g, '') |
| 580 | .replace(/\s+/g, '_') |
| 581 | .replace(/-+/g, '-') |
| 582 | .replace(/_+/g, '_'); |
| 583 | |
| 584 | var slug_sanitized_lower = slug_sanitized.toLowerCase(); |
| 585 | |
| 586 | slug = slug.charAt( 0 ).toUpperCase() + slug.slice( 1 ); |
| 587 | |
| 588 | // Update elements and trigger change. |
| 589 | $( '.pods-slugged[data-sluggable="' + name + '"], .pods-slugged-lower[data-sluggable="' + name + '"]' ).each( function() { |
| 590 | var $this = $( this ), |
| 591 | lowercase = $this.hasClass( 'pods-slugged-lower' ), |
| 592 | sanitize_title = $this.hasClass( 'pods-slugged-sanitize-title' ), |
| 593 | val = slug; |
| 594 | |
| 595 | if ( sanitize_title ) { |
| 596 | val = slug_sanitized; |
| 597 | if ( lowercase ) { |
| 598 | val = slug_sanitized_lower; |
| 599 | } |
| 600 | } else if ( lowercase ) { |
| 601 | val = slug_lower; |
| 602 | } |
| 603 | |
| 604 | switch ( this.nodeName.toLowerCase() ) { |
| 605 | case 'input': |
| 606 | case 'textarea': |
| 607 | // Update fields. |
| 608 | if ( '' === $this.val() ) { |
| 609 | $this.val(val); |
| 610 | |
| 611 | if ( 'undefined' !== typeof window.PodsDFVAPI ) { |
| 612 | window.PodsDFVAPI.setFieldValue($this.prop('name'), val); |
| 613 | } |
| 614 | } |
| 615 | break; |
| 616 | default: |
| 617 | // Update html. |
| 618 | $this.html( val ); |
| 619 | break; |
| 620 | } |
| 621 | $this.trigger( 'change' ); |
| 622 | } ); |
| 623 | } |
| 624 | } ); |
| 625 | |
| 626 | if ( $slug.val().length ) { |
| 627 | $slug.trigger( 'change' ); |
| 628 | } |
| 629 | } |
| 630 | }, |
| 631 | sluggables : function ( parent ) { |
| 632 | var sluggables = []; |
| 633 | |
| 634 | if ( 'undefined' == typeof parent ) |
| 635 | parent = '.pods-admin'; |
| 636 | |
| 637 | $( parent ).find( '.pods-slugged[data-sluggable], .pods-slugged-lower[data-sluggable]' ).each( function () { |
| 638 | if ( -1 == jQuery.inArray( $( this ).data( 'sluggable' ), sluggables ) ) |
| 639 | sluggables.push( $( this ).data( 'sluggable' ) ); |
| 640 | } ); |
| 641 | |
| 642 | for ( var i = 0; i < sluggables.length; i++ ) { |
| 643 | var sluggable = sluggables[ i ]; |
| 644 | |
| 645 | methods[ 'sluggable_single' ]( sluggable ); |
| 646 | } |
| 647 | }, |
| 648 | tabbed : function () { |
| 649 | $( '.pods-admin' ).on( 'click', '.pods-tabs .pods-tab a.pods-tab-link', function ( e ) { |
| 650 | var $this = $( this ), |
| 651 | tab_class = '.pods-tabbed', |
| 652 | tab_hash = this.hash, |
| 653 | $tabbed; |
| 654 | |
| 655 | $this.css( 'cursor', 'default' ); |
| 656 | $this.prop( 'disabled', true ); |
| 657 | |
| 658 | if ( 'undefined' != typeof $this.closest( '.pods-tabs' ).data( 'tabbed' ) ) { |
| 659 | tab_class = $this.closest( '.pods-tabs' ).data( 'tabbed' ); |
| 660 | } |
| 661 | |
| 662 | $tabbed = $this.closest( tab_class ); |
| 663 | |
| 664 | if ( $tabbed.find( '.pods-tabs .pods-tab a[data-tabs]' )[ 0 ] ) { |
| 665 | $tabbed.find( '.pods-tabs .pods-tab a[data-tabs]' ).each( function () { |
| 666 | var tabs = $( this ).data( 'tabs' ), |
| 667 | this_tab_hash = this.hash; |
| 668 | |
| 669 | if ( tab_hash != this_tab_hash ) { |
| 670 | $tabbed.find( tabs ).hide(); |
| 671 | } else { |
| 672 | $tabbed.find( tabs ).show(); |
| 673 | } |
| 674 | } ); |
| 675 | } |
| 676 | else { |
| 677 | $.when( $tabbed.find( '.pods-tab-group .pods-tab' ).not( tab_hash ).slideUp() ).done( function () { |
| 678 | var $current_tab = $tabbed.find( '.pods-tab-group .pods-tab' + tab_hash ); |
| 679 | |
| 680 | $( '.pods-dependent-toggle', $current_tab ).each( function () { |
| 681 | var elementId = $( this ).attr( 'id' ), |
| 682 | runDependencies = true, |
| 683 | selectionTypes = [ |
| 684 | { |
| 685 | name : 'single', |
| 686 | pickFormatRegex: /pick-format-single$/g |
| 687 | }, |
| 688 | { |
| 689 | name : 'multi', |
| 690 | pickFormatRegex: /pick-format-multi$/g |
| 691 | } |
| 692 | ]; |
| 693 | |
| 694 | // Pick multi/single select: Bypass dependency checks on the format of selection types |
| 695 | // that aren't currently chosen. We shouldn't check dependencies against format_single |
| 696 | // if multi is selected and vice versa. |
| 697 | selectionTypes.forEach( function( thisSelectionType ) { |
| 698 | var pickSelectionTypeId = null; |
| 699 | |
| 700 | // Is this the format list for one of the selection types? |
| 701 | if ( thisSelectionType.pickFormatRegex.test( elementId ) ) { |
| 702 | |
| 703 | // Get the HTML ID of the "selection type" select box so we can check its value |
| 704 | pickSelectionTypeId = elementId.replace( thisSelectionType.pickFormatRegex, 'pick-format-type' ); |
| 705 | |
| 706 | // Bypass dependency checks if this format value is for a selection type |
| 707 | // that isn't currently selected |
| 708 | if ( $( '#' + pickSelectionTypeId ).val() !== thisSelectionType.name ) { |
| 709 | runDependencies = false; |
| 710 | } |
| 711 | } |
| 712 | } ); |
| 713 | |
| 714 | if ( runDependencies ) { |
| 715 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 716 | } |
| 717 | } ); |
| 718 | |
| 719 | $current_tab.slideDown(); |
| 720 | } ); |
| 721 | } |
| 722 | |
| 723 | $tabbed.find( '.pods-tabs .pods-tab a' ).removeClass( 'selected' ); |
| 724 | |
| 725 | $this.addClass( 'selected' ); |
| 726 | |
| 727 | $this.css( 'cursor', 'pointer' ); |
| 728 | $this.prop( 'disabled', false ); |
| 729 | |
| 730 | e.preventDefault(); |
| 731 | } ); |
| 732 | |
| 733 | $( '.pods-tabbed' ).each( function () { |
| 734 | $( 'ul.pods-tabs .pods-tab:first a', this ).addClass( 'selected' ); |
| 735 | $( '.pods-tab-group .pods-tab:first' ).each( function () { |
| 736 | $( '.pods-dependent-toggle', this ).trigger( 'change' ); |
| 737 | $( this ).show(); |
| 738 | } ); |
| 739 | } ); |
| 740 | }, |
| 741 | nav_tabbed : function () { |
| 742 | $( '.pods-admin' ).on( 'click', '.pods-nav-tabs a.pods-nav-tab-link', function ( e ) { |
| 743 | var $this = $( this ), |
| 744 | tab_class = '.pods-nav-tabbed', |
| 745 | tab_hash = this.hash, |
| 746 | $tabbed; |
| 747 | |
| 748 | $this.css( 'cursor', 'default' ); |
| 749 | $this.prop( 'disabled', true ); |
| 750 | |
| 751 | if ( 'undefined' != typeof $this.closest( '.pods-nav-tabs' ).data( 'tabbed' ) ) { |
| 752 | tab_class = $this.closest( '.pods-nav-tabs' ).data( 'tabbed' ); |
| 753 | } |
| 754 | |
| 755 | $tabbed = $this.closest( tab_class ); |
| 756 | |
| 757 | if ( $tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link[data-tabs]' )[ 0 ] ) { |
| 758 | $tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link[data-tabs]' ).each( function () { |
| 759 | var tabs = $( this ).data( 'tabs' ), |
| 760 | this_tab_hash = this.hash; |
| 761 | |
| 762 | if ( tab_hash != this_tab_hash ) { |
| 763 | $tabbed.find( tabs ).hide(); |
| 764 | } else { |
| 765 | $tabbed.find( tabs ).show(); |
| 766 | } |
| 767 | } ); |
| 768 | } |
| 769 | else { |
| 770 | $tabbed.find( '.pods-nav-tab-group .pods-nav-tab' ).not( tab_hash ).each( function () { |
| 771 | $( this ).hide(); |
| 772 | } ); |
| 773 | |
| 774 | $tabbed.find( '.pods-nav-tab-group .pods-nav-tab' ).filter( tab_hash ).each( function () { |
| 775 | $( '.pods-dependent-toggle', this ).trigger( 'change' ); |
| 776 | |
| 777 | $( this ).show(); |
| 778 | } ); |
| 779 | } |
| 780 | |
| 781 | $tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link' ).removeClass( 'nav-tab-active' ); |
| 782 | |
| 783 | $this.addClass( 'nav-tab-active' ); |
| 784 | |
| 785 | $this.css( 'cursor', 'pointer' ); |
| 786 | $this.prop( 'disabled', false ); |
| 787 | |
| 788 | e.preventDefault(); |
| 789 | } ); |
| 790 | |
| 791 | $( '.pods-nav-tabbed' ).each( function () { |
| 792 | $nav_tabbed = $( this ); |
| 793 | $nav_tabbed.find( '.pods-nav-tabs a.pods-nav-tab-link:first' ).addClass( 'nav-tab-active' ); |
| 794 | $nav_tabbed.find( '.pods-nav-tab-group .pods-nav-tab:first' ).each( function () { |
| 795 | $( '.pods-dependent-toggle', this ).trigger( 'change' ); |
| 796 | $( this ).show(); |
| 797 | } ); |
| 798 | } ); |
| 799 | }, |
| 800 | wizard : function () { |
| 801 | var methods = { |
| 802 | setFinished : function () { |
| 803 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'finished' ) ); |
| 804 | $( '#pods-wizard-next' ).show().removeClass( 'hidden' ); |
| 805 | }, |
| 806 | setProgress : function () { |
| 807 | $( '#pods-wizard-next' ).text( $( '#pods-wizard-next' ).data( 'next' ) ); |
| 808 | $( '#pods-wizard-next' ).show().removeClass( 'hidden' ); |
| 809 | }, |
| 810 | stepBackward : function () { |
| 811 | $( '#pods-wizard-next' ) |
| 812 | .css( 'cursor', 'pointer' ) |
| 813 | .prop( 'disabled', false ) |
| 814 | .text( $( '#pods-wizard-next' ).data( 'next' ) ); |
| 815 | $( '#pods-wizard-next' ).show().removeClass( 'hidden' ); |
| 816 | |
| 817 | // Step toolbar menu state forwards |
| 818 | $( 'li.pods-wizard-menu-current' ) |
| 819 | .removeClass( 'pods-wizard-menu-current pods-wizard-menu-complete' ) |
| 820 | .prev( 'li' ) |
| 821 | .removeClass( 'pods-wizard-menu-complete' ) |
| 822 | .addClass( 'pods-wizard-menu-current' ); |
| 823 | |
| 824 | // Get current step # |
| 825 | var step = false; |
| 826 | |
| 827 | if ( $( 'li.pods-wizard-menu-current[data-step]' )[ 0 ] ) |
| 828 | step = $( 'li.pods-wizard-menu-current' ).data( 'step' ); |
| 829 | |
| 830 | // Show start over button |
| 831 | if ( 1 == step ) { |
| 832 | $( '#pods-wizard-start' ).hide(); |
| 833 | } else { |
| 834 | $( '#pods-wizard-start' ).show().removeClass( 'hidden' ); |
| 835 | } |
| 836 | |
| 837 | // Check if last step |
| 838 | if ( $( 'div.pods-wizard-panel:visible' ).prev( 'div.pods-wizard-panel' ).length ) { |
| 839 | // Show next panel |
| 840 | $( 'div.pods-wizard-panel:visible' ).hide().prev().show(); |
| 841 | } |
| 842 | |
| 843 | window.location.hash = ''; |
| 844 | }, |
| 845 | stepForward : function () { |
| 846 | // Show action bar for second panel if hidden |
| 847 | $( 'div.pods-wizard-hide-first' ) |
| 848 | .removeClass( 'pods-wizard-hide-first' ) |
| 849 | // Remember that first panel should hide action bar |
| 850 | .data( 'hide', 1 ); |
| 851 | |
| 852 | // Step toolbar menu state forwards |
| 853 | $( 'li.pods-wizard-menu-current' ) |
| 854 | .removeClass( 'pods-wizard-menu-current' ) |
| 855 | .addClass( 'pods-wizard-menu-complete' ) |
| 856 | .next( 'li' ) |
| 857 | .addClass( 'pods-wizard-menu-current' ); |
| 858 | |
| 859 | var step = false, // Get current step #. |
| 860 | check = true; // Allow for override. |
| 861 | |
| 862 | if ( $( 'li.pods-wizard-menu-current[data-step]' )[ 0 ] ) { |
| 863 | step = $( 'li.pods-wizard-menu-current' ).data( 'step' ); |
| 864 | } |
| 865 | |
| 866 | // Show start over button. |
| 867 | $( '#pods-wizard-start' ).show().removeClass( 'hidden' ); |
| 868 | |
| 869 | // Check if last step. |
| 870 | if ( $( 'div.pods-wizard-panel:visible' ).next( 'div.pods-wizard-panel' ).length ) { |
| 871 | // Show next panel |
| 872 | $( 'div.pods-wizard-panel:visible' ).hide().next().show(); |
| 873 | |
| 874 | // Allow for override |
| 875 | if ( 'undefined' != typeof pods_admin_wizard_callback ) { |
| 876 | check = pods_admin_wizard_callback( step, false ); |
| 877 | } |
| 878 | |
| 879 | if ( false === check ) { |
| 880 | return check; |
| 881 | } |
| 882 | |
| 883 | window.location.hash = ''; |
| 884 | } |
| 885 | else if ( $( '#pods-wizard-box' ).closest( 'form' )[ 0 ] ) { |
| 886 | $( '#pods-wizard-next' ) |
| 887 | .css( 'cursor', 'default' ) |
| 888 | .prop( 'disabled', true ) |
| 889 | .text( $( '#pods-wizard-next' ).data( 'processing' ) ); |
| 890 | $( '#pods-wizard-next' ).show().removeClass( 'hidden' ); |
| 891 | |
| 892 | // Allow for override |
| 893 | if ( 'undefined' != typeof pods_admin_wizard_callback ) { |
| 894 | check = pods_admin_wizard_callback( step, true ); |
| 895 | } |
| 896 | |
| 897 | if ( false === check ) { |
| 898 | return check; |
| 899 | } |
| 900 | |
| 901 | $( '#pods-wizard-box' ).closest( 'form' ).submit(); |
| 902 | |
| 903 | if ( $( '#pods-wizard-box' ).closest( 'form' ).hasClass( 'invalid-form' ) ) { |
| 904 | $( '#pods-wizard-next' ) |
| 905 | .css( 'cursor', 'pointer' ) |
| 906 | .prop( 'disabled', false ) |
| 907 | .text( $( '#pods-wizard-next' ).data( 'next' ) ); |
| 908 | $( '#pods-wizard-next' ).show().removeClass( 'hidden' ); |
| 909 | |
| 910 | // Step toolbar menu state forwards |
| 911 | $( 'li.pods-wizard-menu-complete:last' ) |
| 912 | .removeClass( 'pods-wizard-menu-complete' ) |
| 913 | .addClass( 'pods-wizard-menu-current' ) |
| 914 | } |
| 915 | } else { |
| 916 | // Allow for override |
| 917 | if ( 'undefined' != typeof pods_admin_wizard_callback ) { |
| 918 | check = pods_admin_wizard_callback( step, true ); |
| 919 | } |
| 920 | |
| 921 | if ( false === check ) { |
| 922 | return check; |
| 923 | } |
| 924 | |
| 925 | methods.setFinished(); |
| 926 | |
| 927 | window.location.hash = ''; |
| 928 | } |
| 929 | }, |
| 930 | startOver : function () { |
| 931 | // Reset next button text |
| 932 | methods.setProgress(); |
| 933 | |
| 934 | // If first panel and action bar is supposed to be hidden, hide it. |
| 935 | var $box = $( '#pods-wizard-box' ); |
| 936 | if ( $box.data( 'hide' ) ) { |
| 937 | $box.addClass( 'pods-wizard-hide-first' ); |
| 938 | } |
| 939 | |
| 940 | // Revert to first current menu item |
| 941 | $( '#pods-wizard-heading ul li' ) |
| 942 | .removeClass() |
| 943 | .first() |
| 944 | .addClass( 'pods-wizard-menu-current' ); |
| 945 | |
| 946 | // Revert to first panel |
| 947 | $( 'div.pods-wizard-panel' ).hide().first().show(); |
| 948 | |
| 949 | // Hide start over button |
| 950 | $( '.pods-wizard-option-selected' ).removeClass(); |
| 951 | $( '#pods-wizard-start' ).hide(); |
| 952 | $( 'div.pods-wizard-option-cont' ).hide(); |
| 953 | $( '#pods-wizard-choices' ).fadeIn( 'fast' ); |
| 954 | |
| 955 | if ( 'undefined' != typeof pods_admin_wizard_startover_callback ) { |
| 956 | pods_admin_wizard_startover_callback( $( this ) ); |
| 957 | } |
| 958 | |
| 959 | window.location.hash = ''; |
| 960 | } |
| 961 | }; |
| 962 | |
| 963 | // Next button event binding |
| 964 | $( '#pods-wizard-next' ).on( 'click', function ( e ) { |
| 965 | if ( $( this ).is( ':disabled' ) ) { |
| 966 | return; |
| 967 | } |
| 968 | |
| 969 | e.preventDefault(); |
| 970 | |
| 971 | methods.stepForward(); |
| 972 | } ); |
| 973 | |
| 974 | // Start over button event binding |
| 975 | $( '#pods-wizard-start' ).hide().on( 'click', function ( e ) { |
| 976 | e.preventDefault(); |
| 977 | methods.startOver(); |
| 978 | } ); |
| 979 | |
| 980 | // Upgrade choice button event binding |
| 981 | $( '.pods-choice-button' ).on( 'click', function ( e ) { |
| 982 | e.preventDefault(); |
| 983 | |
| 984 | var target = $( this ).attr( 'href' ); |
| 985 | $( '#pods-wizard-choices' ).slideUp( 'fast' ); |
| 986 | $( target ).slideDown( 'fast' ); |
| 987 | } ); |
| 988 | |
| 989 | // Create/extend option event binding |
| 990 | $( '.pods-wizard-option a' ).on( 'click', function ( e ) { |
| 991 | e.preventDefault(); |
| 992 | |
| 993 | $( '.pods-wizard-option-content' ).hide(); |
| 994 | |
| 995 | var target = $( this ).attr( 'href' ); |
| 996 | |
| 997 | $( target ).show(); |
| 998 | $( '.pods-wizard-option-content-' + target.replace( '#pods-wizard-', '' ) ).show(); |
| 999 | |
| 1000 | if ( 'undefined' != typeof pods_admin_option_select_callback ) { |
| 1001 | pods_admin_option_select_callback( $( this ) ); |
| 1002 | } |
| 1003 | |
| 1004 | methods.stepForward(); |
| 1005 | } ); |
| 1006 | |
| 1007 | // Initial step panel setup |
| 1008 | $( '.pods-wizard .pods-wizard-step' ).hide(); |
| 1009 | $( '.pods-wizard .pods-wizard-step:first' ).show(); |
| 1010 | }, |
| 1011 | setup_dependencies : function( $el ) { |
| 1012 | var $current = $el.closest( '.pods-dependency' ), |
| 1013 | $field = $el, |
| 1014 | val = $el.val(), |
| 1015 | $field_type, |
| 1016 | dependent_flag, |
| 1017 | dependent_specific, |
| 1018 | exclude_flag, |
| 1019 | exclude_specific, |
| 1020 | wildcard_target, |
| 1021 | wildcard_target_value; |
| 1022 | |
| 1023 | /** |
| 1024 | * Check if this element is a child from an 'advanced field options' group. |
| 1025 | * If so, set the value to empty if this is not the current field type group |
| 1026 | * Fixes dependency compatibility |
| 1027 | * |
| 1028 | * @todo Validate & improve this |
| 1029 | */ |
| 1030 | |
| 1031 | // Are we in the "Fields" tab? |
| 1032 | if ( $current.parents('#pods-manage-fields').length ) { |
| 1033 | // And are we also in the "Additional Field Options" tab? |
| 1034 | if ( $el.parents('.pods-additional-field-options').length ) { |
| 1035 | // Get this field's type |
| 1036 | $field_type = $current.find( '.pods-form-ui-field-name-field-data-type' ).val(); |
| 1037 | // Check if this element resides within the correct "Additional Field Options" tab |
| 1038 | if ( ! $el.parents( '.pods-additional-field-options > .pods-depends-on-field-data-type-' + $field_type ).length ) { |
| 1039 | // This is not an option for this field. Empty the value |
| 1040 | val = ''; |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | if ( null === val ) { |
| 1046 | val = ''; |
| 1047 | } |
| 1048 | |
| 1049 | dependent_flag = '.pods-depends-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
| 1050 | dependent_specific = dependent_flag + '-' + val.replace( /\_/gi, '-' ); |
| 1051 | |
| 1052 | $current.find( dependent_flag ).each( function () { |
| 1053 | var $dependent = $( this ), |
| 1054 | dependency_trigger; |
| 1055 | |
| 1056 | if ( $dependent.parent().is( ':visible' ) ) { |
| 1057 | if ( $field.is( 'input[type=checkbox]' ) ) { |
| 1058 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent.is( dependent_specific ) ) ) { |
| 1059 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1060 | |
| 1061 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1062 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1063 | |
| 1064 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1065 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1066 | } ); |
| 1067 | |
| 1068 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1069 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1070 | dependency_trigger( $dependent ); |
| 1071 | } |
| 1072 | } |
| 1073 | else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent.is( dependent_specific ) ) ) { |
| 1074 | if ( $dependent.is( 'tr' ) ) { |
| 1075 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1076 | } else { |
| 1077 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1078 | } |
| 1079 | } |
| 1080 | } else if ( $dependent.is( dependent_specific ) ) { |
| 1081 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1082 | |
| 1083 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1084 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1085 | |
| 1086 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1087 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1088 | } ); |
| 1089 | |
| 1090 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1091 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1092 | dependency_trigger( $dependent ); |
| 1093 | } |
| 1094 | } |
| 1095 | else { |
| 1096 | if ( $dependent.is( 'tr' ) ) { |
| 1097 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1098 | } else { |
| 1099 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | else { |
| 1104 | if ( $field.is( 'input[type=checkbox]' ) ) { |
| 1105 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent.is( dependent_specific ) ) ) { |
| 1106 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1107 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1108 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1109 | |
| 1110 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1111 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1112 | } ); |
| 1113 | |
| 1114 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1115 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1116 | dependency_trigger( $dependent ); |
| 1117 | } |
| 1118 | } else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent.is( dependent_specific ) ) ) { |
| 1119 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1120 | } |
| 1121 | } else if ( $dependent.is( dependent_specific ) ) { |
| 1122 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1123 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1124 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1125 | |
| 1126 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1127 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1128 | } ); |
| 1129 | |
| 1130 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1131 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1132 | dependency_trigger( $dependent ); |
| 1133 | } |
| 1134 | } else { |
| 1135 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1136 | } |
| 1137 | } |
| 1138 | } ); |
| 1139 | |
| 1140 | exclude_flag = '.pods-excludes-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
| 1141 | exclude_specific = exclude_flag + '-' + val.replace( /\_/gi, '-' ); |
| 1142 | |
| 1143 | $current.find( exclude_flag ).each( function () { |
| 1144 | var $dependent = $( this ), |
| 1145 | dependency_trigger; |
| 1146 | |
| 1147 | if ( $dependent.parent().is( ':visible' ) ) { |
| 1148 | if ( $field.is( 'input[type=checkbox]' ) ) { |
| 1149 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent.is( exclude_specific ) ) ) { |
| 1150 | if ( $dependent.is( 'tr' ) ) { |
| 1151 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1152 | } else { |
| 1153 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1154 | } |
| 1155 | } |
| 1156 | else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent.is( exclude_specific ) ) ) { |
| 1157 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1158 | |
| 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 | } |
| 1172 | else if ( $dependent.is( exclude_specific ) ) { |
| 1173 | if ( $dependent.is( 'tr' ) ) { |
| 1174 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1175 | } else { |
| 1176 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1177 | } |
| 1178 | } |
| 1179 | else { |
| 1180 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1181 | |
| 1182 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1183 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1184 | |
| 1185 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1186 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1187 | } ); |
| 1188 | |
| 1189 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1190 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1191 | dependency_trigger( $dependent ); |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | else { |
| 1196 | if ( $field.is( 'input[type=checkbox]' ) ) { |
| 1197 | if ( $field.is( ':checked' ) && ( 1 == $field.val() || $dependent.is( exclude_specific ) ) ) { |
| 1198 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1199 | } else if ( !$field.is( ':checked' ) && ( !$field.is( '.pods-dependent-multi' ) || $dependent.is( exclude_specific ) ) ) { |
| 1200 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1201 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1202 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1203 | |
| 1204 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1205 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1206 | } ); |
| 1207 | |
| 1208 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1209 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1210 | dependency_trigger( $dependent ); |
| 1211 | } |
| 1212 | } |
| 1213 | } else if ( $dependent.is( exclude_specific ) ) { |
| 1214 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1215 | } else { |
| 1216 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1217 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1218 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1219 | |
| 1220 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1221 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1222 | } ); |
| 1223 | |
| 1224 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1225 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1226 | dependency_trigger( $dependent ); |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | } ); |
| 1231 | |
| 1232 | // Search for wildcard dependencies on this element's value |
| 1233 | wildcard_target = '.pods-wildcard-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
| 1234 | wildcard_target_value = val.replace( /\_/gi, '-' ); |
| 1235 | |
| 1236 | $current.find( wildcard_target ).each( function () { |
| 1237 | var $dependent = $( this ), |
| 1238 | data_attribute = 'pods-wildcard-' + $field.data( 'name-clean' ), |
| 1239 | wildcard_data = $dependent.data( data_attribute ), |
| 1240 | match_found, |
| 1241 | dependency_trigger; |
| 1242 | |
| 1243 | // Could support objects but limiting to a single string for now |
| 1244 | if ( 'string' !== typeof wildcard_data ) { |
| 1245 | return true; // Continues the outer each() loop |
| 1246 | } |
| 1247 | |
| 1248 | // Check for a wildcard match. Can be multiple wildcards in a comma separated list |
| 1249 | match_found = false; |
| 1250 | $.each( wildcard_data.split( ',' ), function( index, this_wildcard ) { |
| 1251 | if ( null !== wildcard_target_value.match( this_wildcard ) ) { |
| 1252 | match_found = true; |
| 1253 | return false; // Stop iterating through further each() elements |
| 1254 | } |
| 1255 | } ); |
| 1256 | |
| 1257 | // Set the state of the dependent element |
| 1258 | if ( $dependent.parent().is( ':visible' ) ) { |
| 1259 | if ( match_found ) { |
| 1260 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1261 | |
| 1262 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1263 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1264 | $dependent.find( '.pods-dependency .pods-wildcard-on' ).hide(); |
| 1265 | |
| 1266 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1267 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1268 | } ); |
| 1269 | |
| 1270 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1271 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1272 | dependency_trigger( $dependent ); |
| 1273 | } |
| 1274 | } |
| 1275 | else { // No wildcard matches |
| 1276 | if ( $dependent.is( 'tr' ) ) { |
| 1277 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1278 | } |
| 1279 | else { |
| 1280 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | else { // Parent element wasn't visible |
| 1285 | if ( match_found ) { |
| 1286 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1287 | $dependent.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1288 | $dependent.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1289 | $dependent.find( '.pods-dependency .pods-wildcard-on' ).hide(); |
| 1290 | |
| 1291 | $dependent.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1292 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1293 | } ); |
| 1294 | |
| 1295 | if ( $dependent.is( '[data-dependency-trigger]' ) ) { |
| 1296 | dependency_trigger = window[ $dependent.data( 'dependency-trigger' ) ]; |
| 1297 | dependency_trigger( $dependent ); |
| 1298 | } |
| 1299 | } |
| 1300 | else { // No wildcard matches |
| 1301 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1302 | } |
| 1303 | } |
| 1304 | } ); |
| 1305 | }, |
| 1306 | dependency : function ( init ) { |
| 1307 | // Hide all dependents |
| 1308 | $( '.pods-dependency .pods-depends-on, .pods-dependency .pods-excludes-on, .pods-dependency .pods-wildcard-on' ).hide(); |
| 1309 | |
| 1310 | // Handle dependent toggle |
| 1311 | $( '.pods-admin, .pods-form-front, .pods-form-settings' ).on( 'change', '.pods-dependent-toggle[data-name-clean]', function ( e ) { |
| 1312 | var selectionTypeRegex = /pick-format-type$/g, |
| 1313 | elementId = $( this ).attr( 'id' ), |
| 1314 | selectionType, selectionFormatId; |
| 1315 | |
| 1316 | // Setup dependencies for the field that changed |
| 1317 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1318 | |
| 1319 | // Also force a dependency update for the appropriate format when "selection type" changes |
| 1320 | if ( selectionTypeRegex.test( elementId ) ) { |
| 1321 | selectionType = $( this ).val(); |
| 1322 | selectionFormatId = elementId.replace( selectionTypeRegex, 'pick-format-' + selectionType ); |
| 1323 | methods[ 'setup_dependencies' ]( $( '#' + selectionFormatId ) ); |
| 1324 | } |
| 1325 | |
| 1326 | } ); |
| 1327 | |
| 1328 | if ( 'undefined' != typeof init && init ) { |
| 1329 | $( '.pods-dependency' ).find( '.pods-dependent-toggle' ).trigger( 'change' ); |
| 1330 | // DFV fields load later. |
| 1331 | $( window ).on( 'load', function() { |
| 1332 | $( '.pods-dependency' ).find( '.pods-dependent-toggle' ).trigger( 'change' ); |
| 1333 | } ); |
| 1334 | } |
| 1335 | }, |
| 1336 | dependency_tabs : function () { |
| 1337 | // Hide all dependents |
| 1338 | $( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1339 | |
| 1340 | // Handle dependent toggle |
| 1341 | $( '.pods-admin' ).on( 'click', '.pods-dependency-tabs .pods-dependent-tab', function ( e ) { |
| 1342 | var $el = $( this ), |
| 1343 | $current = $el.closest( '.pods-dependency-tabs' ), |
| 1344 | $field = $el, |
| 1345 | dependent_flag = '.pods-depends-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ), |
| 1346 | dependent_specific = dependent_flag + '-' + $el.val().replace( /\_/gi, '-' ); |
| 1347 | |
| 1348 | $current.find( dependent_flag ).each( function () { |
| 1349 | var $dependent = $( this ); |
| 1350 | |
| 1351 | if ( $dependent.parent().is( ':visible' ) ) { |
| 1352 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
| 1353 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1354 | |
| 1355 | $dependent.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1356 | $dependent.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
| 1357 | |
| 1358 | $dependent.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1359 | $( this ).trigger( 'click' ); |
| 1360 | } ); |
| 1361 | } |
| 1362 | else if ( $dependent.is( dependent_specific ) ) { |
| 1363 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1364 | |
| 1365 | $dependent.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1366 | $dependent.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
| 1367 | |
| 1368 | $dependent.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1369 | $( this ).trigger( 'click' ); |
| 1370 | } ); |
| 1371 | } |
| 1372 | else { |
| 1373 | if ( $dependent.is( 'tr' ) ) { |
| 1374 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1375 | } else { |
| 1376 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | else { |
| 1381 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
| 1382 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1383 | $dependent.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1384 | $dependent.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
| 1385 | |
| 1386 | $dependent.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1387 | $( this ).trigger( 'click' ); |
| 1388 | } ); |
| 1389 | } |
| 1390 | else if ( $dependent.is( dependent_specific ) ) { |
| 1391 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1392 | $dependent.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1393 | $dependent.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
| 1394 | |
| 1395 | $dependent.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1396 | $( this ).trigger( 'click' ); |
| 1397 | } ); |
| 1398 | } |
| 1399 | else |
| 1400 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1401 | } |
| 1402 | } ); |
| 1403 | |
| 1404 | var exclude_flag = '.pods-excludes-on-' + $el.data( 'name-clean' ).replace( /\_/gi, '-' ); |
| 1405 | var exclude_specific = exclude_flag + '-' + $el.val().replace( /\_/gi, '-' ); |
| 1406 | |
| 1407 | $current.find( exclude_flag ).each( function () { |
| 1408 | var $dependent = $( this ); |
| 1409 | |
| 1410 | if ( $dependent.parent().is( ':visible' ) ) { |
| 1411 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
| 1412 | if ( $dependent.is( 'tr' ) ) { |
| 1413 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1414 | } else { |
| 1415 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1416 | } |
| 1417 | } else if ( $dependent.is( exclude_specific ) ) { |
| 1418 | if ( $dependent.is( 'tr' ) ) { |
| 1419 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1420 | } else { |
| 1421 | $dependent.slideUp().removeClass( 'pods-dependent-visible' ); |
| 1422 | } |
| 1423 | } |
| 1424 | else { |
| 1425 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1426 | |
| 1427 | $dependent.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1428 | $dependent.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
| 1429 | |
| 1430 | $dependent.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1431 | $( this ).trigger( 'click' ); |
| 1432 | } ); |
| 1433 | } |
| 1434 | } |
| 1435 | else { |
| 1436 | if ( $field.is( 'input[type=checkbox]' ) && $field.is( ':checked' ) && 1 == $field.val() ) { |
| 1437 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1438 | } else if ( $dependent.is( exclude_specific ) ) { |
| 1439 | $dependent.hide().removeClass( 'pods-dependent-visible' ); |
| 1440 | } else { |
| 1441 | $dependent.show().addClass( 'pods-dependent-visible' ); |
| 1442 | $dependent.find( '.pods-dependency-tabs .pods-depends-on' ).hide(); |
| 1443 | $dependent.find( '.pods-dependency-tabs .pods-excludes-on' ).hide(); |
| 1444 | |
| 1445 | $dependent.find( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1446 | $( this ).trigger( 'click' ); |
| 1447 | } ); |
| 1448 | } |
| 1449 | } |
| 1450 | } ); |
| 1451 | } ); |
| 1452 | |
| 1453 | $( '.pods-dependency-tabs .pods-dependent-tab.pods-dependent-tab-active' ).each( function () { |
| 1454 | $( this ).trigger( 'click' ); |
| 1455 | } ); |
| 1456 | }, |
| 1457 | sortable : function () { |
| 1458 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
| 1459 | $( 'tbody.pods-manage-list' ).addClass( 'pods-manage-sortable' ).sortable( { |
| 1460 | items : 'tr.pods-manage-row', |
| 1461 | axis : 'y', |
| 1462 | handle : '.pods-manage-sort', |
| 1463 | stop : function ( event, ui ) { |
| 1464 | $( 'tr.pods-manage-row' ).removeClass( 'alternate' ); |
| 1465 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
| 1466 | } |
| 1467 | } ); |
| 1468 | }, |
| 1469 | advanced : function () { |
| 1470 | $( '.pods-advanced' ).hide(); |
| 1471 | |
| 1472 | $( '.pods-admin' ).on( 'click', '.pods-advanced-toggle', function ( e ) { |
| 1473 | var $advanced = $( this ).closest( 'div' ).find( '.pods-advanced' ); |
| 1474 | |
| 1475 | if ( $advanced.is( ':visible' ) ) { |
| 1476 | $( this ).text( $( this ).text().replace( '-', '+' ) ); |
| 1477 | $advanced.slideUp(); |
| 1478 | } else { |
| 1479 | $( this ).text( $( this ).text().replace( '+', '-' ) ); |
| 1480 | $advanced.slideDown(); |
| 1481 | } |
| 1482 | |
| 1483 | e.preventDefault(); |
| 1484 | } ); |
| 1485 | }, |
| 1486 | collapsible : function ( row ) { |
| 1487 | var new_row = row, |
| 1488 | orig_fields = {}; |
| 1489 | |
| 1490 | if ( new_row[ 0 ] ) { |
| 1491 | new_row = new_row.html(); |
| 1492 | } |
| 1493 | |
| 1494 | // Hide all rows |
| 1495 | $( 'div.pods-manage-row-wrapper' ).hide(); |
| 1496 | |
| 1497 | // Handle 'Edit' action |
| 1498 | $( 'tbody.pods-manage-list' ).on( 'click', 'a.pods-manage-row-edit', function ( e ) { |
| 1499 | var $this = $( this ), |
| 1500 | $row, $row_label, $row_content, $tbody, |
| 1501 | row_counter, edit_row, $field_wrapper, field_data, field_array_counter, json_name; |
| 1502 | |
| 1503 | $this.css( 'cursor', 'default' ); |
| 1504 | $this.prop( 'disabled', true ); |
| 1505 | |
| 1506 | $row = $this.closest( 'tr.pods-manage-row' ); |
| 1507 | $row_label = $row.find( 'td.pods-manage-row-label' ); |
| 1508 | $row_content = $row_label.find( 'div.pods-manage-row-wrapper' ); |
| 1509 | |
| 1510 | if ( 'undefined' == typeof orig_fields[ $row.data( 'id' ) ] ) |
| 1511 | orig_fields[ $row.data( 'id' ) ] = {}; |
| 1512 | |
| 1513 | // Row active, hide it |
| 1514 | if ( $row_content.is( ':visible' ) ) { |
| 1515 | if ( !$row.hasClass( 'pods-field-new' ) ) { |
| 1516 | $row_content.slideUp( 'slow', function () { |
| 1517 | $row.toggleClass( 'pods-manage-row-expanded' ); |
| 1518 | $row_label.prop( 'colspan', '1' ); |
| 1519 | |
| 1520 | $row_content.find( 'input, select, textarea' ).each( function () { |
| 1521 | var $this = $( this ); |
| 1522 | if ( 'undefined' != typeof orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] ) { |
| 1523 | if ( $this.is( 'input[type=checkbox]' ) ) |
| 1524 | $this.prop( 'checked', orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] ); |
| 1525 | else |
| 1526 | $this.val( orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] ); |
| 1527 | } |
| 1528 | } ); |
| 1529 | } ); |
| 1530 | } |
| 1531 | else { |
| 1532 | $tbody = $this.closest( 'tbody.pods-manage-list' ); |
| 1533 | |
| 1534 | $row.animate( {backgroundColor : '#B80000'} ); |
| 1535 | |
| 1536 | $row.fadeOut( 'slow', function () { |
| 1537 | $( this ).remove(); |
| 1538 | if ( 0 === $( 'tbody.pods-manage-list tr.pods-manage-row' ).length ) { |
| 1539 | $tbody.find( 'tr.no-items' ).show(); |
| 1540 | } |
| 1541 | } ); |
| 1542 | |
| 1543 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) { |
| 1544 | $this.closest( 'tbody.pods-manage-list' ).sortable( 'refresh' ); |
| 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | // Row inactive, show it |
| 1549 | else { |
| 1550 | if ( $row.hasClass( 'pods-field-init' ) && 'undefined' != typeof new_row && null !== new_row ) { |
| 1551 | row_counter = $row.data( 'row' ); |
| 1552 | |
| 1553 | edit_row = new_row.replace( /\_\_1/gi, row_counter ).replace( /\-\-1/gi, row_counter ); |
| 1554 | $field_wrapper = $row_content.find( 'div.pods-manage-field' ); |
| 1555 | |
| 1556 | if ( $row.hasClass( 'pods-field-duplicated' ) ) { |
| 1557 | $row.removeClass( 'pods-field-duplicated' ); |
| 1558 | } else { |
| 1559 | $field_wrapper.append( edit_row ); |
| 1560 | |
| 1561 | // Duct tape to handle fields added dynamically |
| 1562 | window.PodsDFV.init(); |
| 1563 | } |
| 1564 | |
| 1565 | $field_wrapper.find( '.pods-depends-on' ).hide(); |
| 1566 | $field_wrapper.find( '.pods-excludes-on' ).hide(); |
| 1567 | |
| 1568 | $field_wrapper.find( '.pods-dependent-toggle' ).each( function () { |
| 1569 | $( this ).trigger( 'change' ); |
| 1570 | } ); |
| 1571 | |
| 1572 | field_data = jQuery.parseJSON( $row_content.find( 'input.field_data' ).val() ); |
| 1573 | |
| 1574 | field_array_counter = 0; |
| 1575 | |
| 1576 | $field_wrapper.find( 'input, select, textarea' ).each( function () { |
| 1577 | var $this = $( this ); |
| 1578 | |
| 1579 | json_name = $this.prop( 'name' ).replace( 'field_data[' + row_counter + '][', '' ).replace( /\[\d*\]/gi, '' ).replace( '[', '' ).replace( ']', '' ); |
| 1580 | |
| 1581 | if ( 'undefined' == typeof field_data[ json_name ] ) |
| 1582 | return; |
| 1583 | |
| 1584 | if ( 0 < $this.prop( 'name' ).indexOf( '[]' ) || $this.prop( 'name' ).replace( 'field_data[' + row_counter + ']', '' ).match( /\[\d*\]/ ) ) { |
| 1585 | if ( $this.is( 'input[type=checkbox]' ) ) { |
| 1586 | $this.prop( 'checked', ( -1 < jQuery.inArray( $this.val(), field_data[ json_name ] ) ) ); |
| 1587 | |
| 1588 | orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] = $this.prop( 'checked' ); |
| 1589 | |
| 1590 | } else if ( 'undefined' != typeof field_data[ json_name ][ field_array_counter ] ) { |
| 1591 | $this.val( field_data[ json_name ][ field_array_counter ] ); |
| 1592 | |
| 1593 | orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] = $this.val(); |
| 1594 | } |
| 1595 | |
| 1596 | field_array_counter++; |
| 1597 | } else { |
| 1598 | field_array_counter = 0; |
| 1599 | |
| 1600 | if ( $this.is( 'input[type=checkbox]' ) ) { |
| 1601 | $this.prop( 'checked', ( $this.val() == field_data[ json_name ] ) ); |
| 1602 | |
| 1603 | orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] = $this.prop( 'checked' ); |
| 1604 | |
| 1605 | } else { |
| 1606 | $this.val( field_data[ json_name ] ); |
| 1607 | |
| 1608 | orig_fields[ $row.data( 'id' ) ][ $this.prop( 'name' ) ] = $( this ).val(); |
| 1609 | } |
| 1610 | } |
| 1611 | } ); |
| 1612 | |
| 1613 | $field_wrapper.find( '.pods-tabbed ul.pods-tabs .pods-tab:first a' ).addClass( 'selected' ); |
| 1614 | $field_wrapper.find( '.pods-tabbed .pods-tab-group .pods-tab:first' ).show(); |
| 1615 | |
| 1616 | $row.removeClass( 'pods-field-init' ); |
| 1617 | |
| 1618 | $( document ).Pods( 'qtip', $row ); |
| 1619 | } |
| 1620 | else { |
| 1621 | $row_content.find( 'input, select, textarea' ).each( function () { |
| 1622 | if ( $( this ).is( 'input[type=checkbox]' ) ) { |
| 1623 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).prop( 'checked' ); |
| 1624 | } else { |
| 1625 | orig_fields[ $row.data( 'id' ) ][ $( this ).prop( 'name' ) ] = $( this ).val(); |
| 1626 | } |
| 1627 | } ); |
| 1628 | } |
| 1629 | |
| 1630 | $row.toggleClass( 'pods-manage-row-expanded' ); |
| 1631 | $row_label.prop( 'colspan', '3' ); |
| 1632 | |
| 1633 | methods[ 'scroll' ]( $row ); |
| 1634 | |
| 1635 | $row_content.slideDown().find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1636 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1637 | } ); |
| 1638 | } |
| 1639 | |
| 1640 | $this.css( 'cursor', 'pointer' ); |
| 1641 | $this.prop( 'disabled', false ); |
| 1642 | |
| 1643 | e.preventDefault(); |
| 1644 | } ) |
| 1645 | // Handle 'Save' action |
| 1646 | .on( 'click', '.pods-manage-row-save a.button-primary', function ( e ) { |
| 1647 | var $this = $( this ), |
| 1648 | $row = $this.closest( 'tr.pods-manage-row' ), |
| 1649 | $row_label = $row.find( 'td.pods-manage-row-label' ), |
| 1650 | $row_content = $row_label.find( 'div.pods-manage-row-wrapper' ), |
| 1651 | $field_wrapper = $row_content.find( 'div.pods-manage-field' ), |
| 1652 | $row_value = $row_content.find( 'input.field_data' ).val(), |
| 1653 | color = ( $row.hasClass( 'alternate' ) ? '#F1F1F1' : '#FFFFFF' ), |
| 1654 | row_id = $row.data( 'row' ), |
| 1655 | field_data = {}, |
| 1656 | valid_form = true; |
| 1657 | |
| 1658 | $this.css( 'cursor', 'default' ); |
| 1659 | $this.prop( 'disabled', true ); |
| 1660 | |
| 1661 | if ( 'undefined' != typeof $row_value && null != $row_value && '' !== $row_value ) { |
| 1662 | field_data = jQuery.parseJSON( $row_value ); |
| 1663 | } |
| 1664 | |
| 1665 | $field_wrapper.find( 'input, select, textarea' ).each( function () { |
| 1666 | var $el = $( this ); |
| 1667 | |
| 1668 | if ( '' !== $el.prop( 'name' ) ) { |
| 1669 | // TinyMCE support. |
| 1670 | if ( 'object' == typeof( tinyMCE ) && -1 < $el.prop( 'class' ).indexOf( 'pods-ui-field-tinymce' ) ) { |
| 1671 | var ed = tinyMCE.get( $el.prop( 'id' ) ); |
| 1672 | |
| 1673 | $el.val( ed.getContent() ); |
| 1674 | } |
| 1675 | |
| 1676 | var val = $el.val(), |
| 1677 | field_array = $el.prop( 'name' ).match( /\[(\w*|)\]/gi ), |
| 1678 | field_name = ( ( null != field_array && 1 < field_array.length ) ? field_array[ 1 ].replace( '[', '' ).replace( ']', '' ) : '' ), |
| 1679 | field_found = -1; |
| 1680 | |
| 1681 | if ( '' == field_name ) { |
| 1682 | return; |
| 1683 | } |
| 1684 | |
| 1685 | if ( $el.is( 'input[type=checkbox]' ) && $el.is( '.pods-form-ui-field-type-pick' ) ) { |
| 1686 | if ( 'object' == typeof field_data[ field_name ] || 'array' == typeof field_data[ field_name ] ) { |
| 1687 | field_found = jQuery.inArray( val, field_data[ field_name ] ); |
| 1688 | |
| 1689 | if ( -1 < field_found ) { |
| 1690 | if ( !$el.is( ':checked' ) ) { |
| 1691 | field_data[ field_name ].splice( field_found, 1 ); |
| 1692 | } |
| 1693 | } else if ( $el.is( ':checked' ) ) { |
| 1694 | field_data[ field_name ].push( val ); |
| 1695 | } |
| 1696 | } else { |
| 1697 | field_data[ field_name ] = []; |
| 1698 | |
| 1699 | if ( $el.is( ':checked' ) ) { |
| 1700 | field_data[ field_name ].push( val ); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | return; |
| 1705 | } else if ( $el.is( 'input[type=checkbox]' ) && !$el.is( ':checked' ) ) { |
| 1706 | val = ( 1 == val ) ? 0 : ''; |
| 1707 | } else if ( $el.is( 'input[type=radio]' ) && !$el.is( ':checked' ) ) { |
| 1708 | val = ''; |
| 1709 | } |
| 1710 | |
| 1711 | if ( $el.is( ':visible' ) && $el.hasClass( 'pods-validate pods-validate-required' ) && '' === $el.val() ) { |
| 1712 | $el.trigger( 'change' ); |
| 1713 | |
| 1714 | if ( false !== valid_form ) { |
| 1715 | $el.trigger( 'focus' ); |
| 1716 | } |
| 1717 | |
| 1718 | valid_form = false; |
| 1719 | } |
| 1720 | |
| 1721 | if ( $el.is( 'input[type=checkbox]' ) && $el.is( '.pods-form-ui-field-type-pick' ) ) { |
| 1722 | if ( -1 == field_found ) { |
| 1723 | if ( 'object' != typeof field_data[ field_name ] && 'array' != typeof field_data[ field_name ] ) { |
| 1724 | field_data[ field_name ] = []; |
| 1725 | } |
| 1726 | |
| 1727 | if ( '' != val ) { |
| 1728 | field_data[ field_name ].push( val ); |
| 1729 | } |
| 1730 | } |
| 1731 | } else if ( 2 == field_array.length ) { |
| 1732 | field_data[ field_name ] = val; |
| 1733 | } else if ( 3 == field_array.length ) { |
| 1734 | the_field = parseInt( field_array[ 2 ].replace( '[', '' ).replace( ']', '' ) ); |
| 1735 | |
| 1736 | if ( isNaN( the_field ) ) { |
| 1737 | field_data[ field_name ] = val; |
| 1738 | } else { |
| 1739 | if ( 'undefined' == typeof field_data[ field_name ] ) { |
| 1740 | field_data[ field_name ] = {}; |
| 1741 | } |
| 1742 | |
| 1743 | while ( 'undefined' != typeof( field_data[ field_name ][ the_field ] ) ) { |
| 1744 | the_field++; |
| 1745 | } |
| 1746 | |
| 1747 | field_data[ field_name ][ the_field ] = val; |
| 1748 | } |
| 1749 | } |
| 1750 | } |
| 1751 | } ); |
| 1752 | |
| 1753 | if ( valid_form ) { |
| 1754 | $row_content.find( 'input.field_data' ).val( JSON.stringify( field_data ) ); |
| 1755 | |
| 1756 | $row.css( 'backgroundColor', '#FFFF33' ).animate( |
| 1757 | { backgroundColor : color }, |
| 1758 | { |
| 1759 | duration : 600, |
| 1760 | complete : function () { |
| 1761 | $( this ).css( 'backgroundColor', '' ); |
| 1762 | } |
| 1763 | } |
| 1764 | ); |
| 1765 | |
| 1766 | if ( 'undefined' != typeof pods_field_types && null !== pods_field_types ) { |
| 1767 | $row.find( 'td.pods-manage-row-label a.row-label' ).html( $row_content.find( 'input#pods-form-ui-field-data-' + row_id + '-label' ).val() ); |
| 1768 | |
| 1769 | if ( $row_content.find( 'input#pods-form-ui-field-data-' + row_id + '-required' ).is( ':checked' ) ) { |
| 1770 | $row.find( 'td.pods-manage-row-label abbr.required' ).show(); |
| 1771 | } else { |
| 1772 | $row.find( 'td.pods-manage-row-label abbr.required' ).hide(); |
| 1773 | } |
| 1774 | |
| 1775 | $row.find( 'td.pods-manage-row-name a' ).html( $row_content.find( 'input#pods-form-ui-field-data-' + row_id + '-name' ).val() ); |
| 1776 | |
| 1777 | var field_type = $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-type' ).val(), |
| 1778 | pick_object = $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-pick-object' ).val(), |
| 1779 | field_type_desc = ''; |
| 1780 | |
| 1781 | if ( 'pick' == field_type && 0 != pick_object ) { |
| 1782 | $.each( pods_pick_objects, function ( i, n ) { |
| 1783 | if ( pick_object == i ) { |
| 1784 | field_type_desc = '<br /><span class="pods-manage-field-type-desc">› ' + n + '</span>'; |
| 1785 | return false; |
| 1786 | } |
| 1787 | } ); |
| 1788 | } |
| 1789 | |
| 1790 | $.each( pods_field_types, function ( i, n ) { |
| 1791 | if ( field_type == i ) { |
| 1792 | field_type = n; |
| 1793 | if ( 'pick' == i ) { |
| 1794 | if ( $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-sister-id' ).val() ) { |
| 1795 | field_type += ' <small>(' + $row_content.find( 'label[for="pods-form-ui-field-data-' + row_id + '-sister-id"]' ).text().trim() + ')</small>' |
| 1796 | } |
| 1797 | } |
| 1798 | return false; |
| 1799 | } |
| 1800 | } ); |
| 1801 | |
| 1802 | $row.find( 'td.pods-manage-row-type' ).html( field_type |
| 1803 | + field_type_desc |
| 1804 | + ' <span class="pods-manage-row-more">[type: ' + $row_content.find( 'select#pods-form-ui-field-data-' + row_id + '-type' ).val() + ']</span>' ); |
| 1805 | } |
| 1806 | |
| 1807 | $row_content.slideUp( 'slow', function () { |
| 1808 | $row_label.prop( 'colspan', '1' ); |
| 1809 | $row.removeClass( 'pods-manage-row-expanded' ); |
| 1810 | $row.removeClass( 'pods-field-new' ); |
| 1811 | $row.addClass( 'pods-field-updated' ); |
| 1812 | } ); |
| 1813 | } |
| 1814 | |
| 1815 | $this.css( 'cursor', 'pointer' ); |
| 1816 | $this.prop( 'disabled', false ); |
| 1817 | |
| 1818 | e.preventDefault(); |
| 1819 | } ) |
| 1820 | // Handle 'Cancel' action |
| 1821 | .on( 'click', '.pods-manage-row-actions a.pods-manage-row-cancel', function ( e ) { |
| 1822 | $( this ).closest( 'tr.pods-manage-row' ).find( 'a.pods-manage-row-edit' ).trigger( 'click' ); |
| 1823 | |
| 1824 | e.preventDefault(); |
| 1825 | } ); |
| 1826 | }, |
| 1827 | toggled : function () { |
| 1828 | $( 'body' ).on( 'click', '.pods-toggled .handlediv, .pods-toggled h3', function () { |
| 1829 | $( this ).parent().find( '.inside' ).slideToggle(); |
| 1830 | return false; |
| 1831 | } ); |
| 1832 | }, |
| 1833 | flexible : function ( row ) { |
| 1834 | var new_row = row, |
| 1835 | row_counter = 0; |
| 1836 | |
| 1837 | if ( new_row[ 0 ] ) { |
| 1838 | new_row = new_row.html(); |
| 1839 | |
| 1840 | // Don't count flexible row |
| 1841 | row_counter = -1; |
| 1842 | } |
| 1843 | |
| 1844 | row_counter += $( 'tr.pods-manage-row' ).length; |
| 1845 | |
| 1846 | if ( 'undefined' != typeof new_row && null !== new_row ) { |
| 1847 | // Handle 'Add' action |
| 1848 | $( '.pods-manage-row-add' ).on( 'click', 'a', function ( e ) { |
| 1849 | var $this = $( this ), |
| 1850 | add_row, $new_row, $tbody; |
| 1851 | |
| 1852 | e.preventDefault(); |
| 1853 | |
| 1854 | $this.css( 'cursor', 'default' ); |
| 1855 | $this.prop( 'disabled', true ); |
| 1856 | |
| 1857 | row_counter++; |
| 1858 | |
| 1859 | add_row = new_row.replace( /__1/gi, row_counter ).replace( /--1/gi, row_counter ); |
| 1860 | $tbody = $this.parent().parent().find( 'tbody.pods-manage-list' ); |
| 1861 | |
| 1862 | $tbody.find( 'tr.no-items' ).hide(); |
| 1863 | $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>' ); |
| 1864 | |
| 1865 | $new_row = $tbody.find( 'tr#row-' + row_counter ); |
| 1866 | |
| 1867 | // Duct tape to handle fields added dynamically |
| 1868 | window.PodsDFV.init(); |
| 1869 | |
| 1870 | $new_row.data( 'row', row_counter ); |
| 1871 | $new_row.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1872 | $new_row.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1873 | |
| 1874 | $new_row.find( '.pods-manage-row-wrapper' ).hide( 0, function () { |
| 1875 | $new_row.find( 'a.row-label.pods-manage-row-edit' ).trigger( 'click' ); |
| 1876 | } ); |
| 1877 | |
| 1878 | $( '.pods-tabs .pods-tab:first a', $new_row ).addClass( 'selected' ); |
| 1879 | $( '.pods-tab-group', $new_row ).find( '.pods-tab:first' ).show(); |
| 1880 | |
| 1881 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) { |
| 1882 | $tbody.sortable( 'refresh' ); |
| 1883 | } |
| 1884 | |
| 1885 | $( 'tr.pods-manage-row' ).removeClass( 'alternate' ); |
| 1886 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
| 1887 | |
| 1888 | methods[ 'sluggables' ]( $new_row ); |
| 1889 | |
| 1890 | $this.css( 'cursor', 'pointer' ); |
| 1891 | $this.prop( 'disabled', false ); |
| 1892 | |
| 1893 | $( document ).Pods( 'qtip', $new_row ); |
| 1894 | |
| 1895 | methods[ 'scroll' ]( $new_row ); |
| 1896 | } ); |
| 1897 | |
| 1898 | // Handle 'Duplicate' action |
| 1899 | $( 'tbody.pods-manage-list' ).on( 'click', 'a.pods-manage-row-duplicate', function ( e ) { |
| 1900 | var $this = $( this ), |
| 1901 | add_row, field_data, |
| 1902 | $tbody, $row, $row_label, $row_content, $new_row, $new_row_label, $new_row_content; |
| 1903 | |
| 1904 | e.preventDefault(); |
| 1905 | |
| 1906 | $this.css( 'cursor', 'default' ); |
| 1907 | $this.prop( 'disabled', true ); |
| 1908 | |
| 1909 | $row = $this.closest( 'tr.pods-manage-row' ); |
| 1910 | $row_label = $row.find( 'td.pods-manage-row-label' ); |
| 1911 | $row_content = $row_label.find( 'div.pods-manage-row-wrapper' ); |
| 1912 | |
| 1913 | field_data = jQuery.parseJSON( $row_content.find( 'input.field_data' ).val() ); |
| 1914 | |
| 1915 | row_counter++; |
| 1916 | |
| 1917 | add_row = new_row.replace( /__1/gi, row_counter ).replace( /--1/gi, row_counter ); |
| 1918 | $tbody = $this.closest( 'tbody.pods-manage-list' ); |
| 1919 | |
| 1920 | $tbody.find( 'tr.no-items' ).hide(); |
| 1921 | $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>' ); |
| 1922 | |
| 1923 | $new_row = $tbody.find( 'tr#row-' + row_counter ); |
| 1924 | $new_row_label = $new_row.find( 'td.pods-manage-row-label' ); |
| 1925 | $new_row_content = $new_row_label.find( 'div.pods-manage-row-wrapper' ); |
| 1926 | |
| 1927 | // Duct tape to handle fields added dynamically |
| 1928 | window.PodsDFV.init(); |
| 1929 | |
| 1930 | field_data[ 'name' ] += '_copy'; |
| 1931 | field_data[ 'label' ] += ' (' + PodsI18n.__( 'Copy' ) + ')'; |
| 1932 | field_data[ 'id' ] = 0; |
| 1933 | |
| 1934 | $new_row_label.find( 'a.pods-manage-row-edit.row-label' ).html( field_data[ 'label' ] ); |
| 1935 | |
| 1936 | $new_row_content.find( 'input.field_data' ).val( JSON.stringify( field_data ) ); |
| 1937 | |
| 1938 | $new_row.data( 'row', row_counter ); |
| 1939 | $new_row.find( '.pods-dependency .pods-depends-on' ).hide(); |
| 1940 | $new_row.find( '.pods-dependency .pods-excludes-on' ).hide(); |
| 1941 | |
| 1942 | $new_row.find( '.pods-dependency .pods-dependent-toggle' ).each( function () { |
| 1943 | methods[ 'setup_dependencies' ]( $( this ) ); |
| 1944 | } ); |
| 1945 | |
| 1946 | $new_row.find( '.pods-manage-row-wrapper' ).hide( 0, function () { |
| 1947 | $new_row.find( 'a.pods-manage-row-edit' ).trigger( 'click' ); |
| 1948 | } ); |
| 1949 | |
| 1950 | $( '.pods-tabs .pods-tab:first a', $new_row ).addClass( 'selected' ); |
| 1951 | $( '.pods-tab-group', $new_row ).find( '.pods-tab:first' ).show(); |
| 1952 | |
| 1953 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) { |
| 1954 | $tbody.sortable( 'refresh' ); |
| 1955 | } |
| 1956 | |
| 1957 | $( 'tr.pods-manage-row' ).removeClass( 'alternate' ); |
| 1958 | $( 'tr.pods-manage-row:even' ).addClass( 'alternate' ); |
| 1959 | |
| 1960 | methods[ 'sluggables' ]( $new_row ); |
| 1961 | |
| 1962 | $this.css( 'cursor', 'pointer' ); |
| 1963 | $this.prop( 'disabled', false ); |
| 1964 | |
| 1965 | $( document ).Pods( 'qtip', $new_row ); |
| 1966 | |
| 1967 | methods[ 'scroll' ]( $new_row ); |
| 1968 | } ); |
| 1969 | } |
| 1970 | |
| 1971 | // Handle 'Delete' action |
| 1972 | $( 'tbody.pods-manage-list' ).on( 'click', 'a.submitdelete', function ( e ) { |
| 1973 | var $this = $( this ); |
| 1974 | |
| 1975 | $this.css( 'cursor', 'default' ); |
| 1976 | $this.prop( 'disabled', true ); |
| 1977 | |
| 1978 | // @todo: Make this confirm pretty so that it's inline instead of JS confirm |
| 1979 | if ( confirm( 'Are you sure you want to delete this field?' ) ) { |
| 1980 | var $row = $this.closest( 'tr.pods-manage-row' ), |
| 1981 | $tbody = $this.closest( 'tbody.pods-manage-list' ); |
| 1982 | |
| 1983 | $row.animate( {backgroundColor : '#B80000'} ); |
| 1984 | |
| 1985 | $row.fadeOut( 'slow', function () { |
| 1986 | $( this ).remove(); |
| 1987 | if ( 0 === $( 'tbody.pods-manage-list tr.pods-manage-row' ).length ) |
| 1988 | $tbody.find( 'tr.no-items' ).show(); |
| 1989 | } ); |
| 1990 | |
| 1991 | if ( $.fn.sortable && $tbody.hasClass( 'pods-manage-sortable' ) ) { |
| 1992 | $this.closest( 'tbody.pods-manage-list' ).sortable( 'refresh' ); |
| 1993 | } |
| 1994 | |
| 1995 | pods_changed = true; |
| 1996 | |
| 1997 | //row_counter--; |
| 1998 | } |
| 1999 | |
| 2000 | $this.css( 'cursor', 'pointer' ); |
| 2001 | $this.prop( 'disabled', false ); |
| 2002 | |
| 2003 | e.preventDefault(); |
| 2004 | } ); |
| 2005 | }, |
| 2006 | confirm : function () { |
| 2007 | $( 'a.pods-confirm' ).on( 'click', function ( e ) { |
| 2008 | var $el = $( this ); |
| 2009 | |
| 2010 | if ( 'undefined' != typeof $el.data( 'confirm' ) && !confirm( $el.data( 'confirm' ) ) ) { |
| 2011 | return false; |
| 2012 | } |
| 2013 | } ); |
| 2014 | }, |
| 2015 | exit_confirm : function () { |
| 2016 | $( 'form.pods-submittable' ).on( 'change', '.pods-submittable-fields input:not(:button,:submit), .pods-submittable-fields textarea, .pods-submittable-fields select', function () { |
| 2017 | pods_changed = true; |
| 2018 | |
| 2019 | window.onbeforeunload = function () { |
| 2020 | if ( pods_changed ) |
| 2021 | return PodsI18n.__( 'Navigating away from this page will discard any changes you have made.' ); |
| 2022 | } |
| 2023 | } ); |
| 2024 | |
| 2025 | $( 'form.pods-submittable' ).on( 'click', '.submitdelete', function () { |
| 2026 | pods_changed = false; |
| 2027 | } ); |
| 2028 | }, |
| 2029 | qtip: function ( parentElement ) { |
| 2030 | let $parentElement = $( parentElement ); |
| 2031 | let $submittable; |
| 2032 | |
| 2033 | if ( $parentElement.hasClass( 'pods-submittable' ) ) { |
| 2034 | $submittable = $parentElement; |
| 2035 | } else { |
| 2036 | $submittable = $parentElement.closest( '.pods-submittable' ); |
| 2037 | } |
| 2038 | |
| 2039 | $parentElement.find( '.pods-qtip' ).each( function ( index, element ) { |
| 2040 | $( element ).qtip( { |
| 2041 | content: { |
| 2042 | attr: 'alt' |
| 2043 | }, |
| 2044 | style: { |
| 2045 | classes: 'ui-tooltip-light ui-tooltip-shadow ui-tooltip-rounded' |
| 2046 | }, |
| 2047 | show: { |
| 2048 | effect: function ( offset ) { |
| 2049 | $( this ).fadeIn( 'fast' ); |
| 2050 | } |
| 2051 | }, |
| 2052 | hide: { |
| 2053 | fixed: true, |
| 2054 | delay: 300 |
| 2055 | }, |
| 2056 | position: { |
| 2057 | container: $submittable, |
| 2058 | my: 'bottom left', |
| 2059 | adjust: { |
| 2060 | y: -14 |
| 2061 | } |
| 2062 | } |
| 2063 | } ); |
| 2064 | } ); |
| 2065 | }, |
| 2066 | scroll: function ( selector, callback ) { |
| 2067 | var offset = 10; |
| 2068 | |
| 2069 | if ( $( '#wpadminbar' )[ 0 ] ) |
| 2070 | offset += $( '#wpadminbar' ).height(); |
| 2071 | |
| 2072 | $( 'html, body' ).animate( { scrollTop : $( selector ).offset().top - offset }, 'slow', callback ); |
| 2073 | }, |
| 2074 | scroll_to : function () { |
| 2075 | $( '.pods-admin' ).on( 'click', 'a.pods-scroll-to', function ( e ) { |
| 2076 | e.preventDefault(); |
| 2077 | |
| 2078 | methods[ 'scroll' ]( '#' + this.hash ); |
| 2079 | } ); |
| 2080 | } |
| 2081 | }; |
| 2082 | |
| 2083 | $.fn.Pods = function ( method ) { |
| 2084 | if ( methods[ method ] ) { |
| 2085 | return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) ); |
| 2086 | } |
| 2087 | // Don't need this part (yet) |
| 2088 | /* |
| 2089 | else if ( typeof method === 'object' || !method ) { |
| 2090 | return methods.init.apply( this, arguments ); |
| 2091 | } |
| 2092 | */ |
| 2093 | else { |
| 2094 | $.error( 'Method ' + method + ' does not exist on jQuery.Pods' ); |
| 2095 | } |
| 2096 | }; |
| 2097 | } )( jQuery ); |
| 2098 |