PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.11
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.11
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / admin / meta-assets / js / admin-edit.js

admin-edit.js in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.1.11, at admin/meta-assets/js/admin-edit.js

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