| 1 |
(function($){ |
| 2 |
|
| 3 |
CartFlowsAdminEdit = { |
| 4 |
|
| 5 |
/** |
| 6 |
* Init |
| 7 |
*/ |
| 8 |
init: function() |
| 9 |
{ |
| 10 |
this._bind(); |
| 11 |
this._set_font_weigths(); |
| 12 |
}, |
| 13 |
|
| 14 |
/** |
| 15 |
* Binds events |
| 16 |
*/ |
| 17 |
_bind: function() |
| 18 |
{ |
| 19 |
$( document ).on('click', '.wcf-cpf-add', CartFlowsAdminEdit._add_custom_field ); |
| 20 |
$( document ).on('click', '.wcf-cpf-action-remove', CartFlowsAdminEdit._remove_custom_field ); |
| 21 |
|
| 22 |
$( document ).on('change', '.wcf-field-font-family', CartFlowsAdminEdit._set_font_weight_select_options ); |
| 23 |
$( document ).on('change', '.wcf-field-font-weight', CartFlowsAdminEdit._set_font_weight_val ); |
| 24 |
}, |
| 25 |
|
| 26 |
_set_font_weight_val: function(event) { |
| 27 |
event.preventDefault(); |
| 28 |
$(this).attr( 'data-selected', $(this).val() ); |
| 29 |
|
| 30 |
CartFlowsAdminEdit._set_google_url(); |
| 31 |
}, |
| 32 |
|
| 33 |
_set_font_weigths: function() { |
| 34 |
|
| 35 |
$('.wcf-field-font-family').select2(); |
| 36 |
|
| 37 |
var google_url = ''; |
| 38 |
var google_font_families = {}; |
| 39 |
|
| 40 |
$('.wcf-field-font-family').each(function(index, el) { |
| 41 |
var font_family = $(el).val(); |
| 42 |
var id = $(el).data('for'); |
| 43 |
|
| 44 |
var temp = font_family.match("'(.*)'"); |
| 45 |
|
| 46 |
if( temp && temp[1] ) { |
| 47 |
font_family = temp[1]; |
| 48 |
} |
| 49 |
|
| 50 |
var new_font_weights = {}; |
| 51 |
if( wcf.google_fonts[ font_family ] ) { |
| 52 |
|
| 53 |
var variants = wcf.google_fonts[ font_family ][0]; |
| 54 |
|
| 55 |
$.each( variants, function(index, weight) { |
| 56 |
if( ! weight.includes( 'italic' ) ) { |
| 57 |
new_font_weights[ weight ] = wcf.font_weights[ weight ]; |
| 58 |
} |
| 59 |
}); |
| 60 |
|
| 61 |
var weight = $( '.wcf-field-font-weight[data-for="'+id+'"]' ); |
| 62 |
if( weight.length ) { |
| 63 |
|
| 64 |
weight.empty(); // remove old options |
| 65 |
var current_selected = weight.attr('data-selected'); |
| 66 |
var selected = ""; |
| 67 |
|
| 68 |
$.each(new_font_weights, function(key,value) { |
| 69 |
|
| 70 |
if( key == current_selected ) { |
| 71 |
var selected = "selected='selected'"; |
| 72 |
} |
| 73 |
|
| 74 |
weight.append($("<option "+selected+"></option>").attr("value", key).text(value)); |
| 75 |
}); |
| 76 |
} |
| 77 |
|
| 78 |
temp_font_family = font_family.replace(' ', '+'); |
| 79 |
google_font_families[ temp_font_family ] = new_font_weights; |
| 80 |
|
| 81 |
} else if( wcf.system_fonts[ font_family ] ) { |
| 82 |
|
| 83 |
var variants = wcf.system_fonts[ font_family ]['variants']; |
| 84 |
|
| 85 |
$.each( variants, function(index, weight) { |
| 86 |
if( ! weight.includes( 'italic' ) ) { |
| 87 |
new_font_weights[ weight ] = wcf.font_weights[ weight ]; |
| 88 |
} |
| 89 |
}); |
| 90 |
|
| 91 |
var weight = $( '.wcf-field-font-weight[data-for="'+id+'"]' ); |
| 92 |
|
| 93 |
if( weight.length ) { |
| 94 |
var current_selected = weight.attr('data-selected'); |
| 95 |
|
| 96 |
weight.empty(); // remove old options |
| 97 |
var selected = ""; |
| 98 |
$.each(new_font_weights, function(key,value) { |
| 99 |
|
| 100 |
if( key == current_selected ) { |
| 101 |
var selected = "selected='selected'"; |
| 102 |
} else { |
| 103 |
} |
| 104 |
weight.append($("<option "+selected+"></option>").attr("value", key).text(value)); |
| 105 |
}); |
| 106 |
} |
| 107 |
} |
| 108 |
}); |
| 109 |
|
| 110 |
CartFlowsAdminEdit._set_google_url(); |
| 111 |
}, |
| 112 |
|
| 113 |
_set_google_url: function() { |
| 114 |
var google_url = ''; |
| 115 |
$('.wcf-field-font-family').each(function(index, el) { |
| 116 |
|
| 117 |
var font_family = $(el).val(); |
| 118 |
var id = $(el).data('for'); |
| 119 |
|
| 120 |
var temp = font_family.match("'(.*)'"); |
| 121 |
|
| 122 |
if( temp && temp[1] ) { |
| 123 |
font_family = temp[1]; |
| 124 |
} |
| 125 |
|
| 126 |
if( ( 'inherit' != font_family ) && ( 'Helvetica' !== font_family ) && ( 'Verdana' !== font_family ) && ( 'Arial' !== font_family ) && ( 'Times' !== font_family ) && ( 'Georgia' !== font_family ) && ( 'Courier' !== font_family ) ) { |
| 127 |
font_family = font_family.replace(' ', '+'); |
| 128 |
|
| 129 |
var weight = $( '.wcf-field-font-weight[data-for="'+id+'"]' ); |
| 130 |
var font_weight = weight.val(); |
| 131 |
|
| 132 |
if( typeof font_weight == 'undefined' && id == 'wcf-base' ){ |
| 133 |
font_weight = ''; |
| 134 |
} |
| 135 |
var bar = '', |
| 136 |
colon = ''; |
| 137 |
|
| 138 |
if( google_url ) { |
| 139 |
if( font_weight != ''){ |
| 140 |
bar = '|'; |
| 141 |
colon = ':'; |
| 142 |
} |
| 143 |
google_url = google_url + bar + font_family + colon + font_weight; |
| 144 |
} else { |
| 145 |
google_url = font_family; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
}); |
| 150 |
|
| 151 |
$('#wcf-field-google-font-url').val( '//fonts.googleapis.com/css?family=' + google_url ); |
| 152 |
}, |
| 153 |
|
| 154 |
_set_font_weight_select_options: function(event) { |
| 155 |
event.preventDefault(); |
| 156 |
|
| 157 |
CartFlowsAdminEdit._set_font_weigths(); |
| 158 |
}, |
| 159 |
|
| 160 |
_remove_custom_field: function(e) { |
| 161 |
|
| 162 |
e.preventDefault(); |
| 163 |
|
| 164 |
var $this = $(this), |
| 165 |
wrap = $this.closest('.wcf-cpf-actions'), |
| 166 |
post_id = $('#post_ID').val(), |
| 167 |
type = wrap.data('type'), |
| 168 |
key = wrap.data('key'), |
| 169 |
row = $this.parents('.wcf-field-row'); |
| 170 |
|
| 171 |
var delete_status = confirm( "This action will delete this field. Are you sure?" ); |
| 172 |
if (true == delete_status) { |
| 173 |
$this.addClass('wp-ui-text-notification').text('Removing..'); |
| 174 |
|
| 175 |
$.ajax({ |
| 176 |
url: wcf.ajax_url, |
| 177 |
data: { |
| 178 |
action: "wcf_delete_checkout_custom_field", |
| 179 |
post_id: post_id, |
| 180 |
type : type, |
| 181 |
key : key, |
| 182 |
security: cartflows_admin.wcf_delete_checkout_custom_field_nonce |
| 183 |
}, |
| 184 |
dataType: 'json', |
| 185 |
type: 'POST', |
| 186 |
success: function ( data ) { |
| 187 |
row.slideUp(400, 'swing', function() { |
| 188 |
row.remove(); |
| 189 |
}); |
| 190 |
} |
| 191 |
}); |
| 192 |
} |
| 193 |
}, |
| 194 |
|
| 195 |
_add_custom_field: function(e) { |
| 196 |
|
| 197 |
e.preventDefault(); |
| 198 |
|
| 199 |
var $this = $(this), |
| 200 |
wrap = $this.closest('.wcf-cpf-wrap'), |
| 201 |
post_id = $('#post_ID').val(), |
| 202 |
add_to = wrap.find( '.wcf-cpf-fields.wcf-cpf-add_to select' ).val() || '', |
| 203 |
type = wrap.find( '.wcf-cpf-fields.wcf-cpf-type select' ).val() || '', |
| 204 |
label = wrap.find( '.wcf-cpf-fields.wcf-cpf-label input' ).val() || '', |
| 205 |
name = wrap.find( '.wcf-cpf-fields.wcf-cpf-name input' ).val() || ''; |
| 206 |
|
| 207 |
if( '' === label ) { |
| 208 |
wrap.find( '.wcf-cpf-fields.wcf-cpf-label input' ).focus(); |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
if( '' === name ) { |
| 213 |
wrap.find( '.wcf-cpf-fields.wcf-cpf-name input' ).focus(); |
| 214 |
return; |
| 215 |
} |
| 216 |
|
| 217 |
$this.addClass('updating-message').text('Adding Field..'); |
| 218 |
|
| 219 |
$.ajax({ |
| 220 |
url: wcf.ajax_url, |
| 221 |
data: { |
| 222 |
action : "wcf_add_checkout_custom_field", |
| 223 |
post_id : post_id, |
| 224 |
add_to : add_to, |
| 225 |
type : type, |
| 226 |
label : label, |
| 227 |
name : name, |
| 228 |
security: cartflows_admin.wcf_add_checkout_custom_field_nonce |
| 229 |
}, |
| 230 |
dataType: 'json', |
| 231 |
type: 'POST', |
| 232 |
success: function ( data ) { |
| 233 |
|
| 234 |
if( $('.' + data.add_to_class ).length ) { |
| 235 |
$('.' + data.add_to_class ).append( data.markup ); |
| 236 |
|
| 237 |
var new_row = $('.wcf-field-row.field-'+data.field_args.name ); |
| 238 |
|
| 239 |
$this.removeClass('updating-message').text('Added Field!'); |
| 240 |
setTimeout(function() { |
| 241 |
$this.text('Add New Field'); |
| 242 |
}, 1500); |
| 243 |
|
| 244 |
|
| 245 |
if( $('.wcf-field-row.field-'+data.field_args.name ).length ) { |
| 246 |
$('html, body').animate({ |
| 247 |
scrollTop: $('.wcf-field-row.field-'+data.field_args.name ).offset().top |
| 248 |
}, 800); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
}); |
| 253 |
|
| 254 |
}, |
| 255 |
}; |
| 256 |
|
| 257 |
/** |
| 258 |
* Initialization |
| 259 |
*/ |
| 260 |
$(function(){ |
| 261 |
CartFlowsAdminEdit.init(); |
| 262 |
}); |
| 263 |
|
| 264 |
})(jQuery); |
| 265 |
|
| 266 |
(function($){ |
| 267 |
|
| 268 |
if ( typeof getEnhancedSelectFormatString == "undefined" ) { |
| 269 |
function getEnhancedSelectFormatString() { |
| 270 |
var formatString = { |
| 271 |
noResults: function() { |
| 272 |
return wc_enhanced_select_params.i18n_no_matches; |
| 273 |
}, |
| 274 |
errorLoading: function() { |
| 275 |
return wc_enhanced_select_params.i18n_ajax_error; |
| 276 |
}, |
| 277 |
inputTooShort: function( args ) { |
| 278 |
var remainingChars = args.minimum - args.input.length; |
| 279 |
|
| 280 |
if ( 1 === remainingChars ) { |
| 281 |
return wc_enhanced_select_params.i18n_input_too_short_1; |
| 282 |
} |
| 283 |
|
| 284 |
return wc_enhanced_select_params.i18n_input_too_short_n.replace( '%qty%', remainingChars ); |
| 285 |
}, |
| 286 |
inputTooLong: function( args ) { |
| 287 |
var overChars = args.input.length - args.maximum; |
| 288 |
|
| 289 |
if ( 1 === overChars ) { |
| 290 |
return wc_enhanced_select_params.i18n_input_too_long_1; |
| 291 |
} |
| 292 |
|
| 293 |
return wc_enhanced_select_params.i18n_input_too_long_n.replace( '%qty%', overChars ); |
| 294 |
}, |
| 295 |
maximumSelected: function( args ) { |
| 296 |
if ( args.maximum === 1 ) { |
| 297 |
return wc_enhanced_select_params.i18n_selection_too_long_1; |
| 298 |
} |
| 299 |
|
| 300 |
return wc_enhanced_select_params.i18n_selection_too_long_n.replace( '%qty%', args.maximum ); |
| 301 |
}, |
| 302 |
loadingMore: function() { |
| 303 |
return wc_enhanced_select_params.i18n_load_more; |
| 304 |
}, |
| 305 |
searching: function() { |
| 306 |
return wc_enhanced_select_params.i18n_searching; |
| 307 |
} |
| 308 |
}; |
| 309 |
|
| 310 |
var language = { 'language' : formatString }; |
| 311 |
|
| 312 |
return language; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
var wcf_init_color_fields = function() { |
| 317 |
|
| 318 |
// Call color picker |
| 319 |
$('.wcf-color-picker').wpColorPicker(); |
| 320 |
} |
| 321 |
var wcf_woo_product_search_init = function() { |
| 322 |
|
| 323 |
var $product_search = $('.wcf-product-search:not(.wc-product-search)'); |
| 324 |
|
| 325 |
if( $product_search.length > 0 ) { |
| 326 |
|
| 327 |
$product_search.addClass('wc-product-search'); |
| 328 |
|
| 329 |
$(document.body).trigger('wc-enhanced-select-init'); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
var wcf_woo_coupon_search_init = function() { |
| 334 |
|
| 335 |
$( ':input.wc-coupon-search' ).filter( ':not(.enhanced)' ).each( function() { |
| 336 |
var select2_args = { |
| 337 |
allowClear: $( this ).data( 'allow_clear' ) ? true : false, |
| 338 |
placeholder: $( this ).data( 'placeholder' ), |
| 339 |
minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3', |
| 340 |
escapeMarkup: function( m ) { |
| 341 |
return m; |
| 342 |
}, |
| 343 |
ajax: { |
| 344 |
url: wc_enhanced_select_params.ajax_url, |
| 345 |
dataType: 'json', |
| 346 |
quietMillis: 250, |
| 347 |
data: function( params, page ) { |
| 348 |
return { |
| 349 |
term: params.term, |
| 350 |
action: $( this ).data( 'action' ) || 'wcf_json_search_coupons', |
| 351 |
security: cartflows_admin.wcf_json_search_coupons_nonce |
| 352 |
}; |
| 353 |
}, |
| 354 |
processResults: function( data, page ) { |
| 355 |
var terms = []; |
| 356 |
if ( data ) { |
| 357 |
$.each( data, function( id, text ) { |
| 358 |
terms.push( { id: id, text: text } ); |
| 359 |
}); |
| 360 |
} |
| 361 |
return { results: terms }; |
| 362 |
}, |
| 363 |
cache: true |
| 364 |
} |
| 365 |
}; |
| 366 |
|
| 367 |
select2_args = $.extend( select2_args, getEnhancedSelectFormatString() ); |
| 368 |
|
| 369 |
$( this ).select2( select2_args ).addClass( 'enhanced' ); |
| 370 |
}); |
| 371 |
}; |
| 372 |
var wcf_pages_search_init = function() { |
| 373 |
|
| 374 |
|
| 375 |
$( 'select.wcf-search-pages' ).each( function() { |
| 376 |
|
| 377 |
var select2_args = { |
| 378 |
allowClear: $( this ).data( 'allow_clear' ) ? true : false, |
| 379 |
placeholder: $( this ).data( 'placeholder' ) ? $( this ).data( 'placeholder' ): '', |
| 380 |
minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3', |
| 381 |
escapeMarkup: function( m ) { |
| 382 |
return m; |
| 383 |
}, |
| 384 |
ajax: { |
| 385 |
url: wc_enhanced_select_params.ajax_url, |
| 386 |
dataType: 'json', |
| 387 |
quietMillis: 250, |
| 388 |
data: function( params, page ) { |
| 389 |
return { |
| 390 |
term: params.term, |
| 391 |
action: $( this ).data( 'action' ) || 'wcf_json_search_pages', |
| 392 |
security: cartflows_admin.wcf_json_search_pages_nonce |
| 393 |
}; |
| 394 |
}, |
| 395 |
processResults: function( data, page ) { |
| 396 |
|
| 397 |
return { results: data }; |
| 398 |
}, |
| 399 |
cache: true |
| 400 |
} |
| 401 |
}; |
| 402 |
|
| 403 |
select2_args = $.extend( select2_args, getEnhancedSelectFormatString() ); |
| 404 |
|
| 405 |
$( this ).select2( select2_args ).addClass( 'enhanced' ); |
| 406 |
}); |
| 407 |
}; |
| 408 |
|
| 409 |
var wcf_add_repeatable_product = function() { |
| 410 |
|
| 411 |
$('.wcf-add-repeatable').on('click', function(e) { |
| 412 |
|
| 413 |
var $this = $(this), |
| 414 |
field_name = $this.data('name'), |
| 415 |
wrap = $this.closest('.wcf-repeatables-wrap'), |
| 416 |
template = $('#tmpl-wcf-product-repeater').html(), |
| 417 |
highest = 0, |
| 418 |
new_key = 0; |
| 419 |
|
| 420 |
wrap.find('.wcf-repeatable-row').each(function(er) { |
| 421 |
var r_row = $(this), |
| 422 |
key = r_row.data('key'); |
| 423 |
|
| 424 |
if ( key > highest ) { |
| 425 |
highest = key; |
| 426 |
} |
| 427 |
}); |
| 428 |
|
| 429 |
new_key = highest + 1; |
| 430 |
|
| 431 |
template = template.replace( /{{id}}/g, new_key ); |
| 432 |
|
| 433 |
|
| 434 |
$( template ).insertBefore( ".wcf-add-repeatable-row" ); |
| 435 |
|
| 436 |
/* Woo Product Search */ |
| 437 |
wcf_woo_product_search_init(); |
| 438 |
|
| 439 |
e.preventDefault(); |
| 440 |
}); |
| 441 |
|
| 442 |
} |
| 443 |
|
| 444 |
var wcf_remove_repeatable_product = function() { |
| 445 |
$(document).on( 'click', '.wcf-repeatable-remove', function(e) { |
| 446 |
|
| 447 |
var $this = $(this), |
| 448 |
deletable_row = $this.closest('.wcf-repeatable-row'), |
| 449 |
wrap = $this.closest('.wcf-repeatables-wrap'); |
| 450 |
|
| 451 |
var all_rows = wrap.find('.wcf-repeatable-row'); |
| 452 |
|
| 453 |
if ( all_rows.length === 1 ) { |
| 454 |
alert("You cannot remove this product."); |
| 455 |
}else{ |
| 456 |
deletable_row.remove(); |
| 457 |
} |
| 458 |
} ); |
| 459 |
} |
| 460 |
|
| 461 |
/* Simple Quantity */ |
| 462 |
var wcf_set_variation_mode_option = function() { |
| 463 |
|
| 464 |
$('.wcf-variation-mode select').each(function(e) { |
| 465 |
var $this = $(this), |
| 466 |
variation_mode = $this.val(), |
| 467 |
wrap = $this.closest('.wcf-repeatable-row-standard-fields'), |
| 468 |
quantity_data = wrap.find('.wcf-quantity-data'); |
| 469 |
|
| 470 |
if ( 'simple-quantity' === variation_mode ) { |
| 471 |
quantity_data.show(); |
| 472 |
}else{ |
| 473 |
quantity_data.hide(); |
| 474 |
} |
| 475 |
}); |
| 476 |
|
| 477 |
$(document).on( 'change', '.wcf-variation-mode select', function(e) { |
| 478 |
var $this = $(this), |
| 479 |
variation_mode = $this.val(), |
| 480 |
wrap = $this.closest('.wcf-repeatable-row-standard-fields'), |
| 481 |
quantity_data = wrap.find('.wcf-quantity-data'); |
| 482 |
|
| 483 |
if ( 'simple-quantity' === variation_mode ) { |
| 484 |
quantity_data.show(); |
| 485 |
}else{ |
| 486 |
quantity_data.hide(); |
| 487 |
} |
| 488 |
}); |
| 489 |
} |
| 490 |
|
| 491 |
var wcf_add_quantity_data = function() { |
| 492 |
|
| 493 |
$(document).on('click', '.wcf-quantity-add-option', function(e) { |
| 494 |
|
| 495 |
e.preventDefault(); |
| 496 |
|
| 497 |
var $this = $(this), |
| 498 |
wrap = $this.closest('.wcf-quantity-data'), |
| 499 |
template = $('#tmpl-wcf-product-simple-quantity').html(), |
| 500 |
highest = 0, |
| 501 |
new_key = 0, |
| 502 |
main_wrap = $this.closest('.wcf-repeatable-row'), |
| 503 |
main_key = main_wrap.data('key'); |
| 504 |
|
| 505 |
wrap.find('.wcf-quantity-repeatable-row').each(function(er) { |
| 506 |
var r_row = $(this), |
| 507 |
key = r_row.data('key'); |
| 508 |
|
| 509 |
if ( key > highest ) { |
| 510 |
highest = key; |
| 511 |
} |
| 512 |
}); |
| 513 |
|
| 514 |
new_key = highest + 1; |
| 515 |
|
| 516 |
template = template.replace( /{{id}}/g, main_key ); |
| 517 |
template = template.replace( /{{data_id}}/g, new_key ); |
| 518 |
|
| 519 |
$( template ).insertAfter( wrap.find('.wcf-quantity-repeatable-row').last() ); |
| 520 |
}); |
| 521 |
} |
| 522 |
|
| 523 |
var wcf_remove_quantity_data = function() { |
| 524 |
|
| 525 |
$(document).on( 'click', '.wcf-quanity-remove', function(e) { |
| 526 |
|
| 527 |
var $this = $(this), |
| 528 |
deletable_row = $this.closest('.wcf-quantity-repeatable-row'), |
| 529 |
wrap = $this.closest('.wcf-quantity-data'); |
| 530 |
|
| 531 |
var all_rows = wrap.find('.wcf-quantity-repeatable-row'); |
| 532 |
|
| 533 |
if ( all_rows.length === 1 ) { |
| 534 |
alert("You cannot remove this product."); |
| 535 |
}else{ |
| 536 |
deletable_row.remove(); |
| 537 |
} |
| 538 |
} ); |
| 539 |
} |
| 540 |
|
| 541 |
/* Custom Fields Hide / Show */ |
| 542 |
var wcf_custom_fields_events = function() { |
| 543 |
|
| 544 |
/* Ready */ |
| 545 |
wcf_custom_fields(); |
| 546 |
|
| 547 |
/* Change Custom Field*/ |
| 548 |
$('.wcf-column-right .wcf-checkout-custom-fields .wcf-cc-fields .wcf-cc-checkbox-field input:checkbox').on('change', function(e) { |
| 549 |
wcf_custom_fields(); |
| 550 |
}); |
| 551 |
} |
| 552 |
|
| 553 |
/* Advance Style Fields Hide / Show */ |
| 554 |
var wcf_advance_style_fields_events = function() { |
| 555 |
|
| 556 |
/* Ready */ |
| 557 |
wcf_advance_style_fields(); |
| 558 |
wcf_thankyou_advance_style_fields(); |
| 559 |
|
| 560 |
/* Change Advance Style Field*/ |
| 561 |
$('.wcf-column-right .wcf-checkout-style .wcf-cs-fields .wcf-cs-checkbox-field input:checkbox').on('change', function(e) { |
| 562 |
wcf_advance_style_fields(); |
| 563 |
}); |
| 564 |
|
| 565 |
/* Change Advance Style Field*/ |
| 566 |
$('.wcf-thankyou-table [name="wcf-tq-advance-options-fields"]').on('change', function(e) { |
| 567 |
wcf_thankyou_advance_style_fields(); |
| 568 |
}); |
| 569 |
} |
| 570 |
|
| 571 |
var wcf_thankyou_advance_style_fields = function() { |
| 572 |
var wrap = $('.wcf-thankyou-table'), |
| 573 |
checkbox_field = $('.wcf-thankyou-table [name="wcf-tq-advance-options-fields"]'); |
| 574 |
|
| 575 |
var field_names = [ |
| 576 |
'.field-wcf-tq-container-width', |
| 577 |
'.field-wcf-tq-section-bg-color' |
| 578 |
]; |
| 579 |
|
| 580 |
if ( checkbox_field.is(":checked") ) { |
| 581 |
$.each( field_names, function(i, val) { |
| 582 |
wrap.find( val ).show(); |
| 583 |
}) |
| 584 |
} else { |
| 585 |
$.each( field_names, function(i, val) { |
| 586 |
wrap.find( val ).hide(); |
| 587 |
}); |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
/* Disable/Enable Advance Style Field section*/ |
| 592 |
var wcf_advance_style_fields = function() { |
| 593 |
|
| 594 |
var wrap = $('.wcf-checkout-table'), |
| 595 |
custom_fields = wrap.find('.wcf-column-right .wcf-checkout-style .wcf-cs-fields .wcf-cs-checkbox-field input:checkbox'); |
| 596 |
|
| 597 |
var field_names = [ |
| 598 |
'.wcf-cs-fields-options', |
| 599 |
'.wcf-cs-button-options', |
| 600 |
'.wcf-cs-section-options', |
| 601 |
]; |
| 602 |
|
| 603 |
// console.log(custom_fields); |
| 604 |
|
| 605 |
if ( custom_fields.is(":checked") ) { |
| 606 |
$.each( field_names, function(i, val) { |
| 607 |
wrap.find( val ).show(); |
| 608 |
}) |
| 609 |
} else { |
| 610 |
$.each( field_names, function(i, val) { |
| 611 |
wrap.find( val ).hide(); |
| 612 |
}); |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
/* Disable/Enable Custom Field section*/ |
| 617 |
var wcf_custom_fields = function() { |
| 618 |
|
| 619 |
var wrap = $('.wcf-checkout-table'), |
| 620 |
custom_fields = wrap.find('.wcf-column-right .wcf-checkout-custom-fields .wcf-cc-fields .wcf-cc-checkbox-field .field-wcf-custom-checkout-fields input:checkbox'); |
| 621 |
|
| 622 |
var field_names = [ |
| 623 |
'.wcf-custom-field-box', |
| 624 |
'.wcf-cb-fields', |
| 625 |
'.wcf-sb-fields', |
| 626 |
]; |
| 627 |
|
| 628 |
if ( custom_fields.is(":checked") ) { |
| 629 |
$.each( field_names, function(i, val) { |
| 630 |
wrap.find( val ).show(); |
| 631 |
}) |
| 632 |
} else { |
| 633 |
$.each( field_names, function(i, val) { |
| 634 |
wrap.find( val ).hide(); |
| 635 |
}); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
var wcf_settings_tab = function() { |
| 640 |
|
| 641 |
if( $('.wcf-tab.active').length ) { |
| 642 |
$active_tab = $('.wcf-tab.active'); |
| 643 |
|
| 644 |
$active_tab_markup = '.' + $active_tab.data('tab'); |
| 645 |
|
| 646 |
if( $( $active_tab_markup ).length ) { |
| 647 |
$( $active_tab_markup ).siblings().removeClass('active'); |
| 648 |
$( $active_tab_markup ).addClass('active'); |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
$('.wcf-tab').on('click', function(e) { |
| 653 |
e.preventDefault(); |
| 654 |
|
| 655 |
$this = $(this), |
| 656 |
tab_class = $this.data('tab'); |
| 657 |
|
| 658 |
$('#wcf-active-tab').val( tab_class ); |
| 659 |
|
| 660 |
$this.siblings().removeClass('wp-ui-text-highlight active'); |
| 661 |
$this.addClass('wp-ui-text-highlight active'); |
| 662 |
|
| 663 |
if( $( '.' + tab_class ).length ) { |
| 664 |
$( '.' + tab_class ).siblings().removeClass('active'); |
| 665 |
$( '.' + tab_class ).addClass('active'); |
| 666 |
} |
| 667 |
}); |
| 668 |
} |
| 669 |
|
| 670 |
var wcf_offer_fields_events = function() { |
| 671 |
|
| 672 |
/* Ready */ |
| 673 |
wcf_offer_fields(); |
| 674 |
|
| 675 |
/* Change Discount Type*/ |
| 676 |
$('.wcf-offer-table .field-wcf-offer-discount select').on('change', function(e) { |
| 677 |
wcf_offer_fields(); |
| 678 |
}); |
| 679 |
} |
| 680 |
|
| 681 |
var wcf_offer_fields = function() { |
| 682 |
|
| 683 |
var wrap = $('.wcf-offer-table'); |
| 684 |
|
| 685 |
if ( wrap.length < 1 ) { |
| 686 |
return; |
| 687 |
} |
| 688 |
|
| 689 |
var field_names = [ |
| 690 |
'.field-wcf-offer-discount-value', |
| 691 |
]; |
| 692 |
|
| 693 |
$.each( field_names, function(i, val) { |
| 694 |
|
| 695 |
if ( '.field-wcf-offer-discount-value' === val ) { |
| 696 |
|
| 697 |
var discount_type = wrap.find('.field-wcf-offer-discount select').val(); |
| 698 |
|
| 699 |
if ( 'discount_percent' === discount_type || 'discount_price' === discount_type ) { |
| 700 |
wrap.find( val ).show(); |
| 701 |
}else{ |
| 702 |
wrap.find( val ).hide(); |
| 703 |
} |
| 704 |
} |
| 705 |
}); |
| 706 |
|
| 707 |
} |
| 708 |
|
| 709 |
var wcf_input_file_init = function() { |
| 710 |
|
| 711 |
var file_frame; |
| 712 |
window.inputWrapper = ''; |
| 713 |
|
| 714 |
$( document.body ).on('click', '.wcf-select-image', function(e) { |
| 715 |
|
| 716 |
e.preventDefault(); |
| 717 |
|
| 718 |
var button = $(this); |
| 719 |
window.inputWrapper = $(this).closest('.wcf-field-row'); |
| 720 |
if ( file_frame ) { |
| 721 |
file_frame.open(); |
| 722 |
return; |
| 723 |
} |
| 724 |
|
| 725 |
// Create the media frame. |
| 726 |
file_frame = wp.media( { |
| 727 |
multiple: false |
| 728 |
} ); |
| 729 |
|
| 730 |
// When an image is selected, run a callback. |
| 731 |
file_frame.on( 'select', function() { |
| 732 |
|
| 733 |
var attachment = file_frame.state().get( 'selection' ).first().toJSON(); |
| 734 |
// place first attachment in field |
| 735 |
window.inputWrapper.find( '#wcf-image-preview' ).show(); |
| 736 |
|
| 737 |
window.inputWrapper.find( '#wcf-image-preview' ).children('.saved-image').remove(); |
| 738 |
|
| 739 |
window.inputWrapper.find( '#wcf-image-preview' ).append('<img src="' + attachment.url + '" width="150" class="saved-image" style="margin-bottom:12px;" />'); |
| 740 |
|
| 741 |
window.inputWrapper.find( '#wcf-image-value' ).val( attachment.url ); |
| 742 |
|
| 743 |
// window.inputWrapper.find( '.wcf-image-id' ).val( attachment.id ); |
| 744 |
|
| 745 |
// window.inputWrapper.find( '.wcf-image-value' ).val( attachment.url ); |
| 746 |
|
| 747 |
$('.wcf-remove-image').show(); |
| 748 |
}); |
| 749 |
|
| 750 |
// Finally, open the modal |
| 751 |
file_frame.open(); |
| 752 |
}); |
| 753 |
|
| 754 |
$( '.wcf-remove-image' ).on( 'click', function( e ) { |
| 755 |
e.preventDefault(); |
| 756 |
|
| 757 |
var button = $(this), |
| 758 |
closeRow = $(this).closest('.wcf-field-row'); |
| 759 |
|
| 760 |
closeRow.find( '#wcf-image-preview img' ).hide(); |
| 761 |
closeRow.find( '.wcf-image-id' ).val(''); |
| 762 |
closeRow.find( '.wcf-image' ).val(''); |
| 763 |
button.hide(); |
| 764 |
|
| 765 |
}); |
| 766 |
} |
| 767 |
|
| 768 |
$(document).ready(function($) { |
| 769 |
|
| 770 |
wcf_settings_tab(); |
| 771 |
|
| 772 |
wcf_init_color_fields(); |
| 773 |
|
| 774 |
/* Woo Product Search */ |
| 775 |
wcf_woo_product_search_init(); |
| 776 |
|
| 777 |
/* Woo Coupon Search */ |
| 778 |
wcf_woo_coupon_search_init(); |
| 779 |
|
| 780 |
/* Pages Search */ |
| 781 |
wcf_pages_search_init(); |
| 782 |
|
| 783 |
/* Select Image Field */ |
| 784 |
wcf_input_file_init(); |
| 785 |
|
| 786 |
/* Set Variation Mode Data */ |
| 787 |
wcf_set_variation_mode_option(); |
| 788 |
|
| 789 |
/* Repeateble Product */ |
| 790 |
wcf_add_repeatable_product(); |
| 791 |
|
| 792 |
/* Remove Repeatable Product */ |
| 793 |
wcf_remove_repeatable_product(); |
| 794 |
|
| 795 |
/* Custom Fields Show Hide */ |
| 796 |
wcf_custom_fields_events(); |
| 797 |
|
| 798 |
/* Advance Style Fields Show Hide */ |
| 799 |
wcf_advance_style_fields_events(); |
| 800 |
|
| 801 |
/* Upsell/Downsell Show Hide Fields */ |
| 802 |
wcf_offer_fields_events(); |
| 803 |
|
| 804 |
/* Quantity Data */ |
| 805 |
wcf_add_quantity_data(); |
| 806 |
wcf_remove_quantity_data(); |
| 807 |
}); |
| 808 |
|
| 809 |
|
| 810 |
})(jQuery); |
| 811 |
|