| 1 |
jQuery( document ).ready( function() { |
| 2 |
wppb_le_chosen(); |
| 3 |
wppb_le_select_option(); |
| 4 |
wppb_le_textarea_option(); |
| 5 |
} ); |
| 6 |
|
| 7 |
function wppb_le_chosen() { |
| 8 |
jQuery( ".chosen-select, .mb-select" ).chosen( { |
| 9 |
disable_search_threshold: 5, |
| 10 |
no_results_text: "Nothing found!", |
| 11 |
width: "80%" |
| 12 |
} ); |
| 13 |
} |
| 14 |
|
| 15 |
function wppb_le_select_option() { |
| 16 |
jQuery( document ).on( 'change', '#pble-label', function() { |
| 17 |
wppb_le_description( jQuery( this ) ); |
| 18 |
} ); |
| 19 |
} |
| 20 |
|
| 21 |
function wppb_le_description( $this ) { |
| 22 |
if( $this.val() == "" ) { |
| 23 |
$this.siblings( '.description' ).text( "Here you will see the default label so you can copy it." ); |
| 24 |
} else { |
| 25 |
$this.siblings( '.description' ).text( $this.val() ); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
function wppb_le_textarea_option() { |
| 30 |
jQuery( document ).on( 'change', '.wck-add-form #pble-label', function() { |
| 31 |
wppb_le_textarea( jQuery( this ) ); |
| 32 |
} ); |
| 33 |
} |
| 34 |
|
| 35 |
function wppb_le_textarea( $this ) { |
| 36 |
jQuery( '.wck-add-form .mb-textarea' ).text( $this.val() ); |
| 37 |
} |
| 38 |
|
| 39 |
function wppb_le_delete_all_fields(event, delete_all_button_id, nonce) { |
| 40 |
event.preventDefault(); |
| 41 |
$deleteButton = jQuery('#' + delete_all_button_id); |
| 42 |
|
| 43 |
var response = confirm( "Are you sure you want to delete all items?" ); |
| 44 |
|
| 45 |
if( response == true ) { |
| 46 |
$tableParent = $deleteButton.parents('table'); |
| 47 |
|
| 48 |
var meta = $tableParent.attr('id').replace('container_', ''); |
| 49 |
var post_id = parseInt( $tableParent.attr('post') ); |
| 50 |
|
| 51 |
$tableParent.parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>'); |
| 52 |
|
| 53 |
jQuery.post( ajaxurl, { action: "pble_delete_all_fields", meta: meta, id: post_id, _ajax_nonce: nonce }, function(response) { |
| 54 |
|
| 55 |
/* refresh the list */ |
| 56 |
jQuery.post( wppbWckAjaxurl, { action: "wck_refresh_list"+meta, meta: meta, id: post_id}, function(response) { |
| 57 |
jQuery('#container_'+meta).replaceWith(response); |
| 58 |
$tableParent = jQuery('#container_'+meta); |
| 59 |
|
| 60 |
$tableParent.find('tbody td').css('width', function(){ return jQuery(this).width() }); |
| 61 |
|
| 62 |
mb_sortable_elements(); |
| 63 |
$tableParent.parent().css('opacity','1'); |
| 64 |
|
| 65 |
jQuery('#mb-ajax-loading').remove(); |
| 66 |
}); |
| 67 |
|
| 68 |
}); |
| 69 |
} |
| 70 |
} |