PluginProbe ʕ •ᴥ•ʔ
Linked Variations for WooCommerce – Link Separate Products by Attribute with Swatches, Quick View & Shortcodes / trunk
Linked Variations for WooCommerce – Link Separate Products by Attribute with Swatches, Quick View & Shortcodes vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5
linked-variation / admin / js / linked-variations-group-admin.js
linked-variation / admin / js Last commit date
linked-variations-admin.js 1 year ago linked-variations-group-admin.js 1 year ago select2.min.js 4 years ago
linked-variations-group-admin.js
146 lines
1 (function ($) {
2 'use strict';
3
4 $(function() {
5 dsalv_init();
6 });
7
8 $(document).ready(function() {
9 //$('.dsalv-product-search').select2();
10
11 $('.dsalv-tag-search').selectWoo();
12 $(document).on('change', '.dsalv-source', function() {
13 var source = $(this).find(':selected').val();
14
15 $(this).closest('.dsalv_link').find('.dsalv-source-hide').hide();
16 $(this).closest('.dsalv_link').find('.dsalv-source-' + source).show();
17 $('.dsalv-tag-search').selectWoo();
18 });
19 $(document).on('click', '#dsalv_delete', function() {
20 if (confirm('Are you sure what to delete?')) {
21 $(this).parents('.dsalv_link').remove();
22 }
23 });
24 $(document).on('click', '#dsalv_toggle', function() {
25 $(this).next('#dsalv_swtich').toggle();
26 if( $(this).find('span:visible').attr('class') === 'expand' ){
27 $(this).find('.collapse').show();
28 $(this).find('.expand').hide();
29 }else{
30 $(this).find('.expand').show();
31 $(this).find('.collapse').hide();
32 }
33 });
34 $(document).on('click', '#dsalv_add_lv', function () {
35 var index = $('#dsalv_configuration .form-table tr td .dsalv_links .dsalv_link:last-child').attr('data-index');
36 var newIndex = parseInt(index) + 1;
37 $.ajax({
38 type: 'POST',
39 url: coditional_vars.ajaxurl,
40 data: {
41 'action': 'dsalv_add_new_variation',
42 'security': coditional_vars.dsalv_ajax_nonce,
43 'index': newIndex
44 },
45 success: function(response) {
46 if ( '' !== response ) {
47 $('#dsalv_configuration .form-table tr td .dsalv_links').last().append( response );
48 dsalv_init();
49 }
50 },
51 });
52 });
53 });
54
55 // search product and save into hidden field
56 $(document).on('change', '.dsalv-product-search', function() {
57 var _val = $(this).val();
58
59 if (Array.isArray(_val)) {
60 $(this).
61 closest('.dsalv_link').
62 find('.dsalv-products').
63 val(_val.join()).trigger('change');
64 } else {
65 if (_val === null) {
66 $(this).
67 closest('.dsalv_link').
68 find('.dsalv-products').
69 val('').trigger('change');
70 } else {
71 $(this).
72 closest('.dsalv_link').
73 find('.dsalv-products').
74 val(String(_val)).trigger('change');
75 }
76 }
77 });
78
79 // search category and save into hidden field
80 $(document).on('change', '.dsalv-category-search', function() {
81 var _val = $(this).val();
82
83 if (Array.isArray(_val)) {
84 $(this).
85 closest('.dsalv_link').
86 find('.dsalv-categories').
87 val(_val.join()).trigger('change');
88 } else {
89 if (_val === null) {
90 $(this).
91 closest('.dsalv_link').
92 find('.dsalv-categories').
93 val('').trigger('change');
94 } else {
95 $(this).
96 closest('.dsalv_link').
97 find('.dsalv-categories').
98 val(String(_val)).trigger('change');
99 }
100 }
101 });
102
103 // search tag and save into hidden field
104 $(document).on('change', '.dsalv-tag-search', function() {
105 var _val = $(this).val();
106
107 if (Array.isArray(_val)) {
108 $(this).
109 closest('.dsalv_link').
110 find('.dsalv-tags').
111 val(_val.join()).trigger('change');
112 } else {
113 if (_val === null) {
114 $(this).
115 closest('.dsalv_link').
116 find('.dsalv-tags').
117 val('').trigger('change');
118 } else {
119 $(this).
120 closest('.dsalv_link').
121 find('.dsalv-tags').
122 val(String(_val)).trigger('change');
123 }
124 }
125 });
126
127 function dsalv_init() {
128 $('.dsalv-attributes').sortable({
129 items: '.dsalv-attribute',
130 cursor: 'move',
131 scrollSensitivity: 40,
132 forcePlaceholderSize: true,
133 forceHelperSize: false,
134 helper: 'clone',
135 opacity: 0.65,
136 });
137
138 $('.dsalv-source-hide').hide();
139
140 $('.dsalv-source').each(function() {
141 var source = $(this).find(':selected').val();
142
143 $(this).closest('.dsalv_link').find('.dsalv-source-' + source).show();
144 });
145 }
146 })(jQuery);