PluginProbe ʕ •ᴥ•ʔ
Bopo – WooCommerce Product Bundle Builder / trunk
Bopo – WooCommerce Product Bundle Builder vtrunk
bopo-woo-product-bundle-builder / js / bopo-product.js
bopo-woo-product-bundle-builder / js Last commit date
bopo-frontend.js 3 years ago bopo-frontend.min.js 3 years ago bopo-product.js 2 weeks ago bopo-product.min.js 3 years ago bopo-settings.js 4 years ago bopo-settings.min.js 4 years ago dropdown.min.js 4 years ago select2.js 4 years ago select2.min.js 4 years ago shortcode-scripts.js 3 years ago shortcode-scripts.min.js 4 years ago transition.min.js 4 years ago
bopo-product.js
269 lines
1 jQuery(document).ready(function ($) {
2 'use strict';
3 let move = false;
4 let bopobb_active_select = '';
5 bopobb_sortable();
6 bopobb_active_settings();
7
8 $(document).on('click', '.bopobb_shortcode_show', function () {
9 let $this = $(this),
10 this_copied_text = $this.parent().find('.bopobb_copy_tooltip');
11 /*Copy event*/
12 $this.select();
13 document.execCommand('copy');
14 /*Show tooltip and auto hide it */
15 this_copied_text.css('visibility', 'visible');
16 setTimeout(function () {
17 this_copied_text.css('visibility', 'hidden');
18 }, 1000);
19 });
20
21 $(document).on('change', '#product-type', function () {
22 if (typeof bopobb_get_type !== 'undefined') {
23 bopobb_init_new_bopo(bopobb_get_type);
24 } else {
25 bopobb_active_settings();
26 }
27 });
28
29 function bopobb_init_new_bopo(type = 'bopobb') {
30 if (type === 'bopobb') {
31 $('#product-type').val('bopobb');
32
33 $('li.general_tab').addClass('show_if_bopobb');
34 $('#_downloadable').closest('label').addClass('show_if_bopobb').removeClass('show_if_simple');
35 $('#_virtual').closest('label').addClass('show_if_bopobb').removeClass('show_if_simple');
36
37 $('.show_if_external').hide();
38 $('.show_if_simple').show();
39 $('.show_if_bopobb').show();
40
41 $('.product_data_tabs li').removeClass('active');
42 $('.product_data_tabs li.bopobb_tab').addClass('active');
43
44 $('.panel-wrap .panel').hide();
45 $('#bopobb-settings').show();
46
47 }
48 }
49
50 function bopobb_active_settings() {
51 if ($('#product-type').val() == 'bopobb') {
52 $('li.general_tab').addClass('show_if_bopobb');
53 $('#_downloadable').closest('label').addClass('show_if_bopobb').removeClass('show_if_simple');
54 $('#_virtual').closest('label').addClass('show_if_bopobb').removeClass('show_if_simple');
55
56 $('.show_if_external').hide();
57 $('.show_if_simple').show();
58 $('.show_if_bopobb').show();
59
60 $('.product_data_tabs li').removeClass('active');
61 $('.product_data_tabs li.bopobb_tab').addClass('active');
62
63 $('.panel-wrap .panel').hide();
64 $('#bopobb-settings').show();
65
66 } else {
67 $('li.general_tab').removeClass('show_if_bopobb');
68 $('#_downloadable').closest('label').removeClass('show_if_bopobb').addClass('show_if_simple');
69 $('#_virtual').closest('label').removeClass('show_if_bopobb').addClass('show_if_simple');
70
71 if ($('#product-type').val() != 'grouped') {
72 $('.general_tab').show();
73 }
74
75 if ($('#product-type').val() == 'simple') {
76 $('#_downloadable').closest('label').show();
77 $('#_virtual').closest('label').show();
78 }
79 }
80 }
81
82 function bopobb_sortable() {
83 $('.bopobb-pbi-contain').sortable({
84 items: '.bopobb-pbi',
85 placeholder: 'bopobb-pbi-place-holder',
86 cursor: 'move',
87 connectWith: '.bopobb-pbi-contain',
88 axis: 'y',
89 handle: '.bopobb-pbi-anchor',
90 start: function (event, ui) {
91 },
92 over: function (event, ui) {
93 },
94 receive: function (event, ui) {
95 move = true;
96 },
97 stop: function (event, ui) {
98 bopobb_ApplyChange();
99 }
100 }).disableSelection();
101 }
102
103 function bopobb_ApplyChange() {
104 let index = 0;
105 $('.bopobb-pbi-contain .bopobb-pbi .bopobb-pbi-index').each(function () {
106 $(this).val(index);
107 index = index + 1;
108 });
109 move = false;
110 }
111
112 function bopobb_ResetDefault() {
113 let _index = bopobb_active_select.closest('.bopobb-pbi').querySelector('.bopobb-pbi-index').value;
114 $('#bopobb_bpi_default_product_' + _index).val("").trigger("change");
115 }
116
117 $(".bopobb-pbi-category-search").select2({
118 closeOnSelect: false,
119 placeholder: "Please enter category title",
120 ajax: {
121 url: "admin-ajax.php?action=bopobb_search_cat",
122 dataType: 'json',
123 type: "GET",
124 quietMillis: 50,
125 delay: 250,
126 data: function (params) {
127 return {
128 nonce: bopobbProductVars.bopobb_nonce,
129 keyword: params.term
130 };
131 },
132 processResults: function (data) {
133 return {
134 results: data
135 };
136 },
137 cache: true
138 },
139 escapeMarkup: function (markup) {
140 return markup;
141 },
142 minimumInputLength: 1
143 }).on('select2:open', function (e) {
144 bopobb_active_select = e.currentTarget;
145 }).on("select2:selecting", function(e) {
146 bopobb_active_select = e.currentTarget;
147 bopobb_ResetDefault();
148 }).on("select2:unselecting", function(e) {
149 bopobb_active_select = e.currentTarget;
150 bopobb_ResetDefault();
151 });
152
153 $(".bopobb-pbi-tag-search").select2({
154 closeOnSelect: false,
155 placeholder: "Please enter category title",
156 ajax: {
157 url: "admin-ajax.php?action=bopobb_search_tag",
158 dataType: 'json',
159 type: "GET",
160 quietMillis: 50,
161 delay: 250,
162 data: function (params) {
163 return {
164 nonce: bopobbProductVars.bopobb_nonce,
165 keyword: params.term
166 };
167 },
168 processResults: function (data) {
169 return {
170 results: data
171 };
172 },
173 cache: true
174 },
175 escapeMarkup: function (markup) {
176 return markup;
177 },
178 minimumInputLength: 1
179 }).on('select2:open', function (e) {
180 bopobb_active_select = e.currentTarget;
181 }).on("select2:selecting", function(e) {
182 bopobb_active_select = e.currentTarget;
183 bopobb_ResetDefault();
184 }).on("select2:unselecting", function(e) {
185 bopobb_active_select = e.currentTarget;
186 bopobb_ResetDefault();
187 });
188
189 $(".bopobb-pbi-product-search").select2({
190 closeOnSelect: false,
191 placeholder: "Please fill in your product title",
192 ajax: {
193 url: "admin-ajax.php?action=bopobb_search_product",
194 dataType: 'json',
195 type: "GET",
196 quietMillis: 50,
197 delay: 250,
198 data: function (params) {
199 return {
200 nonce: bopobbProductVars.bopobb_nonce,
201 keyword: params.term
202 };
203 },
204 processResults: function (data) {
205 return {
206 results: data
207 };
208 },
209 cache: true
210 },
211 escapeMarkup: function (markup) {
212 return markup;
213 },
214 minimumInputLength: 1
215 }).on('select2:open', function (e) {
216 bopobb_active_select = e.currentTarget;
217 }).on("select2:selecting", function(e) {
218 bopobb_active_select = e.currentTarget;
219 bopobb_ResetDefault();
220 }).on("select2:unselecting", function(e) {
221 bopobb_active_select = e.currentTarget;
222 bopobb_ResetDefault();
223 });
224
225 $(".bopobb-pbi-default-search").select2({
226 closeOnSelect: true,
227 placeholder: "Please fill in your product title",
228 ajax: {
229 url: "admin-ajax.php?action=bopobb_default_product",
230 dataType: 'json',
231 type: "GET",
232 quietMillis: 50,
233 delay: 250,
234 data: function (params) {
235 return {
236 nonce: bopobbProductVars.bopobb_nonce,
237 keyword: params.term,
238 cat: $(this).closest('tbody').find('.bopobb-pbi-category.bopobb-pbi-category-search').val(),
239 ex_cat: $(this).closest('tbody').find('.bopobb-pbi-category-exclude.bopobb-pbi-category-search').val(),
240 tag: $(this).closest('tbody').find('.bopobb-pbi-tag.bopobb-pbi-tag-search').val(),
241 ex_tag: $(this).closest('tbody').find('.bopobb-pbi-tag-exclude.bopobb-pbi-tag-search').val(),
242 prod: $(this).closest('tbody').find('.bopobb-pbi-title.bopobb-pbi-product-search').val(),
243 ex_prod: $(this).closest('tbody').find('.bopobb-pbi-input .bopobb-pbi-title-exclude').val()
244 };
245 },
246 processResults: function (data) {
247 return {
248 results: data
249 };
250 },
251 cache: true
252 },
253 escapeMarkup: function (markup) {
254 return markup;
255 },
256 minimumInputLength: 0,
257 allowClear: true
258 });
259
260 $(document).on('click touch', '.bopobb-pbi', function (e) {
261 e.stopPropagation();
262 if ($(this).hasClass('wc-metabox closed')) {
263 $(this).find('.bopobb-pbi-slide-arrow').addClass('dashicons-arrow-down-alt2').removeClass('dashicons-arrow-up-alt2');
264 } else {
265 $(this).find('.bopobb-pbi-slide-arrow').removeClass('dashicons-arrow-down-alt2').addClass('dashicons-arrow-up-alt2');
266 }
267 });
268
269 });