· 5 years ago · Jul 18, 2020, 07:56 AM
1jQuery(function($) {
2
3 $('.tips').tooltip();
4
5 $('ul.order-status').on('click', 'a.dokan-edit-status', function(e) {
6 $(this).addClass('dokan-hide').closest('li').next('li').removeClass('dokan-hide');
7
8 return false;
9 });
10
11 $('ul.order-status').on('click', 'a.dokan-cancel-status', function(e) {
12 $(this).closest('li').addClass('dokan-hide').prev('li').find('a.dokan-edit-status').removeClass('dokan-hide');
13
14 return false;
15 });
16
17 $('form#dokan-order-status-form').on('submit', function(e) {
18 e.preventDefault();
19
20 var self = $(this),
21 li = self.closest('li');
22
23 li.block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
24
25 $.post( dokan.ajaxurl, self.serialize(), function(response) {
26 li.unblock();
27
28 if ( response.success ) {
29 var prev_li = li.prev();
30
31 li.addClass('dokan-hide');
32 prev_li.find('label').replaceWith(response.data);
33 prev_li.find('a.dokan-edit-status').removeClass('dokan-hide');
34 } else {
35 alert( response.data );
36 }
37 });
38 });
39
40 $('form#add-order-note').on( 'submit', function(e) {
41 e.preventDefault();
42
43 if (!$('textarea#add-note-content').val()) return;
44
45 $('#dokan-order-notes').block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
46
47 $.post( dokan.ajaxurl, $(this).serialize(), function(response) {
48 $('ul.order_notes').prepend( response );
49 $('#dokan-order-notes').unblock();
50 $('#add-note-content').val('');
51 });
52
53 return false;
54
55 })
56
57 $('#dokan-order-notes').on( 'click', 'a.delete_note', function() {
58
59 var note = $(this).closest('li.note');
60
61 $('#dokan-order-notes').block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
62
63 var data = {
64 action: 'dokan_delete_order_note',
65 note_id: $(note).attr('rel'),
66 security: $('#delete-note-security').val()
67 };
68
69 $.post( dokan.ajaxurl, data, function(response) {
70 $(note).remove();
71 $('#dokan-order-notes').unblock();
72 });
73
74 return false;
75
76 });
77
78 $('.order_download_permissions').on('click', 'button.grant_access', function() {
79 var self = $(this),
80 product = $('select.grant_access_id').val();
81
82 if (!product) return;
83
84 $('.order_download_permissions').block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
85
86 var data = {
87 action: 'dokan_grant_access_to_download',
88 product_ids: product,
89 loop: $('.order_download_permissions .panel').size(),
90 order_id: self.data('order-id'),
91 security: self.data('nonce')
92 };
93
94 $.post(dokan.ajaxurl, data, function( response ) {
95
96 if ( response ) {
97
98 $('#accordion').append( response );
99
100 } else {
101
102 alert('Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.');
103
104 }
105
106 $( '.datepicker' ).datepicker();
107 $('.order_download_permissions').unblock();
108
109 });
110
111 return false;
112 });
113
114 $('.order_download_permissions').on('click', 'button.revoke_access', function(e){
115 e.preventDefault();
116 var answer = confirm('Are you sure you want to revoke access to this download?');
117
118 if (answer){
119
120 var self = $(this),
121 el = self.closest('.dokan-panel');
122
123 var product = self.attr('rel').split(",")[0];
124 var file = self.attr('rel').split(",")[1];
125
126 if (product > 0) {
127
128 $(el).block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
129
130 var data = {
131 action: 'dokan_revoke_access_to_download',
132 product_id: product,
133 download_id: file,
134 order_id: self.data('order-id'),
135 permission_id: self.data('permission-id'),
136 security: self.data('nonce')
137 };
138
139 $.post(dokan.ajaxurl, data, function(response) {
140 // Success
141 $(el).fadeOut('300', function(){
142 $(el).remove();
143 });
144 });
145
146 } else {
147 $(el).fadeOut('300', function(){
148 $(el).remove();
149 });
150 }
151
152 }
153
154 return false;
155 });
156
157});
158
159/*global woocommerce_admin_meta_boxes, woocommerce_admin, accounting */
160;(function($) {
161 /**
162 * Order Items Panel
163 */
164 var dokan_seller_meta_boxes_order_items = {
165 init: function() {
166
167 let formatMap = {
168 // Day
169 d: 'dd',
170 D: 'D',
171 j: 'd',
172 l: 'DD',
173
174 // Month
175 F: 'MM',
176 m: 'mm',
177 M: 'M',
178 n: 'm',
179
180 // Year
181 o: 'yy', // not exactly same. see php date doc for details
182 Y: 'yy',
183 y: 'y'
184 }
185
186 let i = 0;
187 let char = '';
188 let datepickerFormat = '';
189
190 for (i = 0; i < dokan.i18n_date_format.length; i++) {
191 char = dokan.i18n_date_format[i];
192
193 if (char in formatMap) {
194 datepickerFormat += formatMap[char];
195 } else {
196 datepickerFormat += char;
197 }
198 }
199
200 $( "#shipped-date" ).datepicker({
201 dateFormat: datepickerFormat
202 });
203
204 //saving note
205 $( 'body' ).on('click','#dokan-add-tracking-number', this.showTrackingForm );
206 $( 'body' ).on('click','#dokan-cancel-tracking-note', this.cancelTrackingForm );
207 $( 'body' ).on('click','#add-tracking-details', this.insertShippingTrackingInfo);
208
209 $( '#woocommerce-order-items' )
210 .on( 'click', 'button.refund-items', this.refund_items )
211 .on( 'click', '.cancel-action', this.cancel )
212
213 // Refunds
214 .on( 'click', 'button.do-api-refund, button.do-manual-refund', this.refunds.do_refund )
215 .on( 'change', '.refund input.refund_line_total, .refund input.refund_line_tax', this.refunds.input_changed )
216 .on( 'change keyup', '.wc-order-refund-items #refund_amount', this.refunds.amount_changed )
217 .on( 'change', 'input.refund_order_item_qty', this.refunds.refund_quantity_changed )
218
219 // Subtotal/total
220 .on( 'keyup', '.woocommerce_order_items .split-input input:eq(0)', function() {
221 var $subtotal = $( this ).next();
222 if ( $subtotal.val() === '' || $subtotal.is( '.match-total' ) ) {
223 $subtotal.val( $( this ).val() ).addClass( 'match-total' );
224 }
225 })
226
227 .on( 'keyup', '.woocommerce_order_items .split-input input:eq(1)', function() {
228 $( this ).removeClass( 'match-total' );
229 })
230 },
231
232 showTrackingForm: function(e) {
233 e.preventDefault();
234 var self = $(this);
235
236 self.closest('div').find('form#add-shipping-tracking-form').slideDown( 300, function() {
237 $(this).removeClass('dokan-hide');
238 });
239 },
240
241 cancelTrackingForm: function(e) {
242 e.preventDefault();
243 var self = $(this);
244
245 self.closest('form#add-shipping-tracking-form').slideUp( 300, function() {
246 $(this).addClass('dokan-hide');
247 });
248 },
249
250 insertShippingTrackingInfo: function(e){
251 e.preventDefault();
252
253 var shipping_tracking_info = {
254 shipping_provider: $('#shipping_provider').val(),
255 shipping_number: $('#tracking_number').val(),
256 shipped_date: $('#shipped-date').val(),
257 action: $('#action').val(),
258 post_id: $('#post-id').val(),
259 security: $('#security').val()
260 };
261
262 $('#dokan-order-notes').block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
263
264 $.post( dokan.ajaxurl, shipping_tracking_info, function(response) {
265 $('ul.order_notes').prepend( response );
266 $('#dokan-order-notes').unblock();
267 $('form#add-shipping-tracking-form').find("input[type=text], textarea").val("");
268 });
269
270 return false;
271
272 },
273
274 block: function() {
275 $( '#woocommerce-order-items' ).block({
276 message: null,
277 overlayCSS: {
278 background: '#fff',
279 opacity: 0.6
280 }
281 });
282 },
283
284 unblock: function() {
285 $( '#woocommerce-order-items' ).unblock();
286 },
287
288 reload_items: function() {
289 var data = {
290 order_id: dokan_refund.post_id,
291 action: 'dokan_load_order_items',
292 security: dokan_refund.order_item_nonce
293 };
294
295 dokan_seller_meta_boxes_order_items.block();
296
297 $.ajax({
298 url: dokan_refund.ajax_url,
299 data: data,
300 type: 'POST',
301 success: function( response ) {
302 $( '.dokan-panel-default #woocommerce-order-items' ).empty();
303 $( '.dokan-panel-default #woocommerce-order-items' ).append( response );
304 // wc_meta_boxes_order.init_tiptip();
305 }
306 });
307 },
308
309 refund_items: function() {
310 $( 'div.wc-order-refund-items' ).slideDown();
311 $( 'div.wc-order-bulk-actions' ).slideUp();
312 $( 'div.wc-order-totals-items' ).slideUp();
313 $( '#woocommerce-order-items div.refund' ).show();
314 $( '.wc-order-edit-line-item .wc-order-edit-line-item-actions' ).hide();
315 return false;
316 },
317
318 cancel: function() {
319 $( this ).closest( 'div.wc-order-data-row' ).slideUp();
320 $( 'div.wc-order-bulk-actions' ).slideDown();
321 $( 'div.wc-order-totals-items' ).slideDown();
322 $( '#woocommerce-order-items div.refund' ).hide();
323 $( '.wc-order-edit-line-item .wc-order-edit-line-item-actions' ).show();
324
325 // Reload the items
326 if ( 'true' === $( this ).attr( 'data-reload' ) ) {
327 dokan_seller_meta_boxes_order_items.reload_items();
328 }
329
330 return false;
331 },
332
333 refunds: {
334
335 do_refund: function() {
336 dokan_seller_meta_boxes_order_items.block();
337
338 if ( window.confirm( dokan_refund.i18n_do_refund ) ) {
339 var refund_amount = $( 'input#refund_amount' ).val();
340 var refund_reason = $( 'input#refund_reason' ).val();
341
342 // Get line item refunds
343 var line_item_qtys = {};
344 var line_item_totals = {};
345 var line_item_tax_totals = {};
346
347 $( '.refund input.refund_order_item_qty' ).each(function( index, item ) {
348 if ( $( item ).closest( 'tr' ).data( 'order_item_id' ) ) {
349 if ( item.value ) {
350 line_item_qtys[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] = item.value;
351 }
352 }
353 });
354
355 $( '.refund input.refund_line_total' ).each(function( index, item ) {
356 if ( $( item ).closest( 'tr' ).data( 'order_item_id' ) ) {
357 line_item_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] = accounting.unformat( item.value, dokan_refund.mon_decimal_point );
358 }
359 });
360
361 $( '.refund input.refund_line_tax' ).each(function( index, item ) {
362 if ( $( item ).closest( 'tr' ).data( 'order_item_id' ) ) {
363 var tax_id = $( item ).data( 'tax_id' );
364
365 if ( ! line_item_tax_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] ) {
366 line_item_tax_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] = {};
367 }
368
369 line_item_tax_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ][ tax_id ] = accounting.unformat( item.value, dokan_refund.mon_decimal_point );
370 }
371 });
372
373 var data = {
374 action: 'dokan_refund_request',
375 order_id: dokan_refund.post_id,
376 refund_amount: refund_amount,
377 refund_reason: refund_reason,
378 line_item_qtys: JSON.stringify( line_item_qtys, null, '' ),
379 line_item_totals: JSON.stringify( line_item_totals, null, '' ),
380 line_item_tax_totals: JSON.stringify( line_item_tax_totals, null, '' ),
381 api_refund: $( this ).is( '.do-api-refund' ),
382 restock_refunded_items: $( '#restock_refunded_items:checked' ).size() ? 'true' : 'false',
383 security: dokan_refund.order_item_nonce
384 };
385
386 $.post( dokan_refund.ajax_url, data, function( response ) {
387 response.data.message ? window.alert( response.data.message ) : null;
388 dokan_seller_meta_boxes_order_items.reload_items();
389 }).fail( function ( jqXHR ) {
390 var message = [];
391
392 if ( jqXHR.responseJSON.data ) {
393 var data = jqXHR.responseJSON.data;
394
395 if ( $.isArray( data ) ) {
396 message = jqXHR.responseJSON.data.map( function ( item ) {
397 return item.message;
398 } );
399 } else {
400 message.push( data );
401 }
402 }
403
404 window.alert( message.join( ' ' ) );
405 dokan_seller_meta_boxes_order_items.unblock();
406 } );
407 } else {
408 dokan_seller_meta_boxes_order_items.unblock();
409 }
410 },
411
412 input_changed: function() {
413 var refund_amount = 0;
414 var $items = $( '.woocommerce_order_items' ).find( 'tr.item, tr.fee, tr.shipping' );
415
416 $items.each(function() {
417 var $row = $( this );
418 var refund_cost_fields = $row.find( '.refund input:not(.refund_order_item_qty)' );
419
420 refund_cost_fields.each(function( index, el ) {
421 refund_amount += parseFloat( accounting.unformat( $( el ).val() || 0, dokan_refund.mon_decimal_point ) );
422 });
423 });
424
425 $( '#refund_amount' )
426 .val( accounting.formatNumber(
427 refund_amount,
428 dokan_refund.currency_format_num_decimals,
429 '',
430 dokan_refund.mon_decimal_point
431 ) )
432 .change();
433 },
434
435 amount_changed: function() {
436 var total = accounting.unformat( $( this ).val(), dokan_refund.mon_decimal_point );
437
438 $( 'button .wc-order-refund-amount .amount' ).text( accounting.formatMoney( total, {
439 symbol: dokan_refund.currency_format_symbol,
440 decimal: dokan_refund.currency_format_decimal_sep,
441 thousand: dokan_refund.currency_format_thousand_sep,
442 precision: dokan_refund.currency_format_num_decimals,
443 format: dokan_refund.currency_format
444 } ) );
445 },
446
447 // When the refund qty is changed, increase or decrease costs
448 refund_quantity_changed: function() {
449 var $row = $( this ).closest( 'tr.item' );
450 var qty = $row.find( 'input.quantity' ).val();
451 var refund_qty = $( this ).val();
452 var line_total = $( 'input.line_total', $row );
453 var refund_line_total = $( 'input.refund_line_total', $row );
454
455 // Totals
456 var unit_total = accounting.unformat( line_total.attr( 'data-total' ), dokan_refund.mon_decimal_point ) / qty;
457
458 refund_line_total.val(
459 parseFloat( accounting.formatNumber( unit_total * refund_qty, dokan_refund.rounding_precision, '' ) )
460 .toString()
461 .replace( '.', dokan_refund.mon_decimal_point )
462 ).change();
463
464 // Taxes
465 $( 'td.line_tax', $row ).each( function() {
466 var line_total_tax = $( 'input.line_tax', $( this ) );
467 var refund_line_total_tax = $( 'input.refund_line_tax', $( this ) );
468 var unit_total_tax = accounting.unformat( line_total_tax.attr( 'data-total_tax' ), dokan_refund.mon_decimal_point ) / qty;
469
470 if ( 0 < unit_total_tax ) {
471 refund_line_total_tax.val(
472 parseFloat( accounting.formatNumber( unit_total_tax * refund_qty, dokan_refund.rounding_precision, '' ) )
473 .toString()
474 .replace( '.', dokan_refund.mon_decimal_point )
475 ).change();
476 } else {
477 refund_line_total_tax.val( 0 ).change();
478 }
479 });
480
481 // Restock checkbox
482 if ( refund_qty > 0 ) {
483 $( '#restock_refunded_items' ).closest( 'tr' ).show();
484 } else {
485 $( '#restock_refunded_items' ).closest( 'tr' ).hide();
486 $( '.woocommerce_order_items input.refund_order_item_qty' ).each( function() {
487 if ( $( this ).val() > 0 ) {
488 $( '#restock_refunded_items' ).closest( 'tr' ).show();
489 }
490 });
491 }
492
493 $( this ).trigger( 'refund_quantity_changed' );
494 }
495 },
496 };
497
498 dokan_seller_meta_boxes_order_items.init();
499
500 // Ajax search customers
501 $( '#dokan-filter-customer' ).filter( ':not(.enhanced)' ).each( function() {
502 var select2_args = {
503 allowClear: $( this ).data( 'allow_clear' ) ? true : false,
504 placeholder: $( this ).data( 'placeholder' ),
505 minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '1',
506 escapeMarkup: function( m ) {
507 return m;
508 },
509 ajax: {
510 url: dokan.ajaxurl,
511 dataType: 'json',
512 delay: 1000,
513 data: function( params ) {
514 return {
515 term: params.term,
516 action: 'dokan_json_search_vendor_customers',
517 security: dokan.search_customer_nonce,
518 exclude: $( this ).data( 'exclude' )
519 };
520 },
521 processResults: function( data ) {
522 var terms = [];
523 if ( data ) {
524 $.each( data, function( id, text ) {
525 terms.push({
526 id: id,
527 text: text
528 });
529 });
530 }
531 return {
532 results: terms
533 };
534 },
535 cache: true
536 }
537 };
538
539 $( this ).select2( select2_args ).addClass( 'enhanced' );
540
541 if ( $( this ).data( 'sortable' ) ) {
542 var $select = $(this);
543 var $list = $( this ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' );
544
545 $list.sortable({
546 placeholder : 'ui-state-highlight select2-selection__choice',
547 forcePlaceholderSize: true,
548 items : 'li:not(.select2-search__field)',
549 tolerance : 'pointer',
550 stop: function() {
551 $( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function() {
552 var id = $( this ).data( 'data' ).id;
553 var option = $select.find( 'option[value="' + id + '"]' )[0];
554 $select.prepend( option );
555 } );
556 }
557 });
558 }
559 });
560
561})(jQuery);
562
563
564;(function($){
565
566 var variantsHolder = $('#variants-holder');
567 var product_gallery_frame;
568 var product_featured_frame;
569 var $image_gallery_ids = $('#product_image_gallery');
570 var $product_images = $('#product_images_container ul.product_images');
571
572 var Dokan_Editor = {
573
574 /**
575 * Constructor function
576 */
577 init: function() {
578
579 product_type = 'simple';
580
581 $('.product-edit-container').on( 'click', '.dokan-section-heading', this.toggleProductSection );
582
583 $('.product-edit-container').on('click', 'input[type=checkbox]#_downloadable', this.downloadable );
584 $('.product-edit-container').on('click', 'a.sale-schedule', this.showDiscountSchedule );
585
586 // gallery
587 $('body, #dokan-product-images').on('click', 'a.add-product-images', this.gallery.addImages );
588 $('body, #dokan-product-images').on( 'click', 'a.action-delete', this.gallery.deleteImage );
589 this.gallery.sortable();
590
591 // featured image
592 $('body, .product-edit-container').on('click', 'a.dokan-feat-image-btn', this.featuredImage.addImage );
593 $('body, .product-edit-container').on('click', 'a.dokan-remove-feat-image', this.featuredImage.removeImage );
594
595 $('body, #variable_product_options').on( 'click', '.sale_schedule', this.saleSchedule );
596 $('body, #variable_product_options').on( 'click', '.cancel_sale_schedule', this.cancelSchedule );
597
598 // new product design variations
599 $('.product-edit-container').on( 'change', 'input[type=checkbox]#_manage_stock', this.showManageStock );
600 $( '.product-edit-container' ).on( 'click', 'a.upload_file_button', this.fileDownloadable );
601
602
603 // File inputs
604 $('body').on('click', 'a.insert-file-row', function(){
605 $(this).closest('table').find('tbody').append( $(this).data( 'row' ) );
606 return false;
607 });
608
609 $('body').on('click', 'a.dokan-product-delete', function() {
610 $(this).closest('tr').remove();
611 return false;
612 });
613
614 $( 'body' ).on( 'submit', 'form.dokan-product-edit-form', this.inputValidate );
615
616 // For new desing in product page
617 $( '.dokan-product-listing' ).on( 'click', 'a.dokan-add-new-product', this.addProductPopup );
618
619 this.loadSelect2();
620 this.bindProductTagDropdown();
621 this.attribute.sortable();
622 this.checkProductPostboxToggle();
623 $( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'click', 'a.dokan-product-toggle-attribute, .dokan-product-attribute-heading', this.attribute.toggleAttribute );
624 $( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'click', 'a.add_new_attribute', this.attribute.addNewAttribute );
625 $( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'keyup', 'input.dokan-product-attribute-name', this.attribute.dynamicAttrNameChange );
626 $( '.dokan-product-attribute-wrapper ul.dokan-attribute-option-list' ).on( 'click', 'button.dokan-select-all-attributes', this.attribute.selectAllAttr );
627 $( '.dokan-product-attribute-wrapper ul.dokan-attribute-option-list' ).on( 'click', 'button.dokan-select-no-attributes', this.attribute.selectNoneAttr );
628 $( '.dokan-product-attribute-wrapper ul.dokan-attribute-option-list' ).on( 'click', 'button.dokan-add-new-attribute', this.attribute.addNewExtraAttr );
629 $( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'click', 'a.dokan-product-remove-attribute', this.attribute.removeAttribute );
630 $( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'click', 'a.dokan-save-attribute', this.attribute.saveAttribute );
631 $( 'body' ).on( 'click', '.product-container-footer input[type="submit"]', this.createNewProduct );
632
633 this.attribute.disbalePredefinedAttribute();
634
635 $( 'body' ).trigger( 'dokan-product-editor-loaded', this );
636 },
637
638 saleSchedule: function() {
639 var $wrap = $(this).closest( '.dokan-product-field-content', 'div, table' );
640 $(this).hide();
641
642 $wrap.find('.cancel_sale_schedule').show();
643 $wrap.find('.sale_price_dates_fields').show();
644
645 return false;
646 },
647
648 cancelSchedule: function() {
649 var $wrap = $(this).closest( '.dokan-product-field-content', 'div, table' );
650
651 $(this).hide();
652 $wrap.find('.sale_schedule').show();
653 $wrap.find('.sale_price_dates_fields').hide();
654 $wrap.find('.sale_price_dates_fields').find('input').val('');
655
656 return false;
657 },
658
659
660 checkProductPostboxToggle: function() {
661 var toggle = JSON.parse( localStorage.getItem( 'toggleClasses' ) );
662
663 $.each( toggle, function(el, i) {
664 var wrapper = $( '.' + el.replace( /_/g, '-' ) ),
665 content = wrapper.find( '.dokan-section-content' ),
666 targetIcon = wrapper.find( 'i.fa-sort-desc' );
667
668 if ( i ) {
669 content.show();
670 targetIcon.removeClass( 'fa-flip-horizointal' ).addClass( 'fa-flip-vertical' );
671 targetIcon.css( 'marginTop', '9px' );
672 } else {
673 content.hide();
674 targetIcon.removeClass( 'fa-flip-vertical' ).addClass( 'fa-flip-horizointal' );
675 targetIcon.css( 'marginTop', '0px' );
676 }
677 });
678 },
679
680 toggleProductSection: function(e) {
681 e.preventDefault();
682
683 var self = $(this);
684 if ( JSON.parse( localStorage.getItem( 'toggleClasses' ) ) != null ) {
685 var toggleClasses = JSON.parse( localStorage.getItem( 'toggleClasses' ) );
686 } else {
687 var toggleClasses = {};
688 }
689
690 self.closest( '.dokan-edit-row' ).find('.dokan-section-content').slideToggle( 300, function() {
691 if( $(this).is( ':visible' ) ) {
692 var targetIcon = self.find( 'i.fa-sort-desc' );
693 targetIcon.removeClass( 'fa-flip-horizointal' ).addClass( 'fa-flip-vertical' );
694 targetIcon.css( 'marginTop', '9px' );
695 toggleClasses[self.data('togglehandler')] = true;
696 } else {
697 var targetIcon = self.find( 'i.fa-sort-desc' );
698 targetIcon.removeClass( 'fa-flip-vertical' ).addClass( 'fa-flip-horizointal' );
699 targetIcon.css( 'marginTop', '0px' );
700 toggleClasses[self.data('togglehandler')] = false;
701 }
702
703 localStorage.setItem( 'toggleClasses', JSON.stringify( toggleClasses ) );
704 });
705
706 },
707
708 loadSelect2: function() {
709 $('.dokan-select2').select2(
710 {
711 "language": {
712 "noResults": function () {
713 return dokan.i18n_no_result_found;
714 }
715 }
716 }
717 );
718 },
719
720 bindProductTagDropdown: function () {
721 if ( dokan.product_vendors_can_create_tags && 'on' === dokan.product_vendors_can_create_tags ) {
722 return;
723 }
724
725 $( '#product_tag' ).select2( {
726 language: {
727 noResults: function () {
728 return dokan.i18n_no_result_found;
729 }
730 }
731 } );
732 },
733
734 addProductPopup: function (e) {
735 e.preventDefault();
736 Dokan_Editor.openProductPopup();
737 },
738
739 openProductPopup: function() {
740 var productTemplate = wp.template( 'dokan-add-new-product' );
741 $.magnificPopup.open({
742 fixedContentPos: true,
743 items: {
744 src: productTemplate().trim(),
745 type: 'inline'
746 },
747 callbacks: {
748 open: function() {
749 $(this.content).closest('.mfp-wrap').removeAttr('tabindex');
750 Dokan_Editor.loadSelect2();
751 Dokan_Editor.bindProductTagDropdown();
752
753 $('.sale_price_dates_from, .sale_price_dates_to').on('focus', function() {
754 $(this).css('z-index', '99999');
755 });
756
757 $( ".sale_price_dates_fields input" ).datepicker({
758 defaultDate: "",
759 dateFormat: "yy-mm-dd",
760 numberOfMonths: 1
761 });
762
763 $('.tips').tooltip();
764
765 Dokan_Editor.gallery.sortable();
766
767 $( 'body' ).trigger( 'dokan-product-editor-popup-opened', Dokan_Editor );
768 },
769 close: function() {
770 product_gallery_frame = undefined;
771 product_featured_frame = undefined;
772 }
773 }
774 });
775 },
776
777 createNewProduct: function (e) {
778 e.preventDefault();
779
780 var self = $(this),
781 form = self.closest('form#dokan-add-new-product-form'),
782 btn_id = self.attr('data-btn_id');
783
784 form.find( 'span.dokan-show-add-product-error' ).html('');
785 form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'inline-block' );
786
787 self.attr( 'disabled', 'disabled' );
788
789 if ( form.find( 'input[name="post_title"]' ).val() == '' ) {
790 $( 'span.dokan-show-add-product-error' ).html( dokan.product_title_required );
791 self.removeAttr( 'disabled' );
792 form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'none' );
793 return;
794 }
795
796 if ( form.find( 'select[name="product_cat"]' ).val() == '-1' ) {
797 $( 'span.dokan-show-add-product-error' ).html( dokan.product_category_required );
798 self.removeAttr( 'disabled' );
799 form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'none' );
800 return;
801 }
802
803 var data = {
804 action: 'dokan_create_new_product',
805 postdata: form.serialize(),
806 _wpnonce : dokan.nonce
807 };
808
809 $.post( dokan.ajaxurl, data, function( resp ) {
810 if ( resp.success ) {
811 self.removeAttr( 'disabled' );
812 if ( btn_id == 'create_new' ) {
813 $.magnificPopup.close();
814 window.location.href = resp.data;
815 } else {
816 $('.dokan-dashboard-product-listing-wrapper').load( window.location.href + ' table.product-listing-table' );
817 $.magnificPopup.close();
818 Dokan_Editor.openProductPopup();
819 }
820 } else {
821 self.removeAttr( 'disabled' );
822 $( 'span.dokan-show-add-product-error' ).html( resp.data );
823 }
824 form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'none' );
825 });
826 },
827
828 attribute: {
829
830 toggleAttribute: function(e) {
831 e.preventDefault();
832
833 var self = $(this),
834 list = self.closest('li'),
835 item = list.find('.dokan-product-attribute-item');
836
837 if ( $(item).hasClass('dokan-hide') ) {
838 self.closest('.dokan-product-attribute-heading').css({ borderBottom: '1px solid #e3e3e3' });
839 $(item).slideDown( 200, function() {
840 self.find('i.fa').removeClass('fa-flip-horizointal').addClass('fa-flip-vertical');
841 $(this).removeClass('dokan-hide');
842 if ( ! $(e.target).hasClass( 'dokan-product-attribute-heading' ) ) {
843 $(e.target).closest('a').css('top', '12px');
844 } else if ( $(e.target).hasClass( 'dokan-product-attribute-heading' ) ) {
845 self.find( 'a.dokan-product-toggle-attribute' ).css('top', '12px');
846 }
847 });
848 } else {
849 $(item).slideUp( 200, function() {
850 $(this).addClass('dokan-hide');
851 self.find('i.fa').removeClass('fa-flip-vertical').addClass('fa-flip-horizointal');
852 if ( ! $(e.target).hasClass('dokan-product-attribute-heading') ) {
853 $(e.target).closest('a').css('top', '7px');
854 } else if ( $(e.target).hasClass( 'dokan-product-attribute-heading' ) ) {
855 self.find('a.dokan-product-toggle-attribute').css('top', '7px');
856 }
857 self.closest('.dokan-product-attribute-heading').css({ borderBottom: 'none' });
858
859 })
860 }
861 return false;
862 },
863
864 sortable: function() {
865 $('.dokan-product-attribute-wrapper ul').sortable({
866 items: 'li.product-attribute-list',
867 cursor: 'move',
868 scrollSensitivity:40,
869 forcePlaceholderSize: true,
870 forceHelperSize: false,
871 helper: 'clone',
872 opacity: 0.65,
873 placeholder: 'dokan-sortable-placeholder',
874 start:function(event,ui){
875 ui.item.css('background-color','#f6f6f6');
876 },
877 stop:function(event,ui){
878 ui.item.removeAttr('style');
879 },
880 update: function(event, ui) {
881 var attachment_ids = '';
882 Dokan_Editor.attribute.reArrangeAttribute();
883 }
884 });
885 },
886
887 dynamicAttrNameChange: function(e) {
888 e.preventDefault();
889 var self = $(this),
890 value = self.val();
891
892 if ( value == '' ) {
893 self.closest( 'li' ).find( 'strong' ).html( 'Attribute Name' );
894 } else {
895 self.closest( 'li' ).find( 'strong' ).html( value );
896 }
897 },
898
899 selectAllAttr: function(e) {
900 e.preventDefault();
901 $( this ).closest( 'li.product-attribute-list' ).find( 'select.dokan_attribute_values option' ).attr( 'selected', 'selected' );
902 $( this ).closest( 'li.product-attribute-list' ).find( 'select.dokan_attribute_values' ).change();
903 return false;
904 },
905
906 selectNoneAttr: function(e) {
907 e.preventDefault();
908 $( this ).closest( 'li.product-attribute-list' ).find( 'select.dokan_attribute_values option' ).removeAttr( 'selected' );
909 $( this ).closest( 'li.product-attribute-list' ).find( 'select.dokan_attribute_values' ).change();
910 return false;
911 },
912
913 reArrangeAttribute: function() {
914 var attributeWrapper = $('.dokan-product-attribute-wrapper').find('ul.dokan-attribute-option-list');
915 attributeWrapper.find( 'li.product-attribute-list' ).css( 'cursor', 'default' ).each(function( i ) {
916 $(this).find('.attribute_position').val(i);
917 });
918 },
919
920 addNewExtraAttr: function(e) {
921 e.preventDefault();
922
923 var $wrapper = $(this).closest( 'li.product-attribute-list' );
924 var attribute = $wrapper.data( 'taxonomy' );
925 var new_attribute_name = window.prompt( dokan.new_attribute_prompt );
926
927 if ( new_attribute_name ) {
928
929 var data = {
930 action: 'dokan_add_new_attribute',
931 taxonomy: attribute,
932 term: new_attribute_name,
933 _wpnonce : dokan.nonce
934 };
935
936 $.post( dokan.ajaxurl, data, function( response ) {
937 if ( response.error ) {
938 window.alert( response.error );
939 } else if ( response.slug ) {
940 $wrapper.find( 'select.dokan_attribute_values' ).append( '<option value="' + response.slug + '" selected="selected">' + response.name + '</option>' );
941 $wrapper.find( 'select.dokan_attribute_values' ).change();
942 }
943
944 });
945 }
946 },
947
948 addNewAttribute: function(e) {
949 e.preventDefault();
950
951 var self = $(this),
952 attrWrap = self.closest('.dokan-attribute-type').find('select#predefined_attribute'),
953 attribute = attrWrap.val(),
954 size = $( 'ul.dokan-attribute-option-list .product-attribute-list' ).length;
955
956
957 var data = {
958 action : 'dokan_get_pre_attribute',
959 taxonomy : attribute,
960 i : size,
961 _wpnonce : dokan.nonce
962 };
963
964 self.closest('.dokan-attribute-type').find('span.dokan-attribute-spinner').removeClass('dokan-hide');
965
966 $.post( dokan.ajaxurl, data, function( resp ) {
967 if ( resp.success ) {
968 var attributeWrapper = $('.dokan-product-attribute-wrapper').find('ul.dokan-attribute-option-list');
969 $html = $.parseHTML(resp.data);
970 $($html).find('.dokan-product-attribute-item').removeClass('dokan-hide');
971 $($html).find('i.fa.fa-sort-desc').removeClass('fa-flip-horizointal').addClass('fa-flip-vertical');
972 $($html).find('a.dokan-product-toggle-attribute').css('top','12px');
973 $($html).find('.dokan-product-attribute-heading').css({ borderBottom: '1px solid #e3e3e3' });
974
975 attributeWrapper.append( $html );
976 $( 'select#product_type' ).trigger('change');
977 Dokan_Editor.loadSelect2();
978 Dokan_Editor.attribute.reArrangeAttribute();
979 };
980
981 self.closest('.dokan-attribute-type').find('span.dokan-attribute-spinner').addClass('dokan-hide');
982
983 if ( attribute ) {
984 attrWrap.find( 'option[value="' + attribute + '"]' ).attr( 'disabled','disabled' );
985 attrWrap.val( '' );
986 }
987 });
988 },
989
990 removeAttribute: function(evt) {
991 evt.stopPropagation();
992
993 if ( window.confirm( dokan.remove_attribute ) ) {
994 var $parent = $( this ).closest('li.product-attribute-list');
995
996 $parent.fadeOut( 300, function() {
997 if ( $parent.is( '.taxonomy' ) ) {
998 $parent.find( 'select, input[type=text]' ).val( '' );
999 $( 'select.dokan_attribute_taxonomy' ).find( 'option[value="' + $parent.data( 'taxonomy' ) + '"]' ).removeAttr( 'disabled' );
1000 } else {
1001 $parent.find( 'select, input[type=text]' ).val( '' );
1002 $parent.hide();
1003 }
1004
1005 Dokan_Editor.attribute.reArrangeAttribute();
1006 });
1007 }
1008
1009 return false;
1010 },
1011
1012 saveAttribute: function(e) {
1013 e.preventDefault();
1014
1015 var self = $(this),
1016 data = {
1017 post_id: $('#dokan-edit-product-id').val(),
1018 data: $( 'ul.dokan-attribute-option-list' ).find( 'input, select, textarea' ).serialize(),
1019 action: 'dokan_save_attributes'
1020 };
1021
1022 $( '.dokan-product-attribute-wrapper' ).block({
1023 message: null,
1024 fadeIn: 50,
1025 fadeOut: 1000,
1026 overlayCSS: {
1027 background: '#fff',
1028 opacity: 0.6
1029 }
1030 });
1031
1032 $.post( dokan.ajaxurl, data, function( resp ) {
1033 // Load variations panel.
1034 $( '#dokan-variable-product-options' ).load( window.location.toString() + ' #dokan-variable-product-options-inner', function() {
1035 $( '#dokan-variable-product-options' ).trigger( 'reload' );
1036 $( 'select#product_type' ).trigger('change');
1037 $( '.dokan-product-attribute-wrapper' ).unblock();
1038 });
1039 });
1040
1041 },
1042
1043 disbalePredefinedAttribute: function() {
1044 $( 'ul.dokan-attribute-option-list li.product-attribute-list' ).each( function( index, el ) {
1045 if ( $( el ).css( 'display' ) !== 'none' && $( el ).is( '.taxonomy' ) ) {
1046 $( 'select#predefined_attribute' ).find( 'option[value="' + $( el ).data( 'taxonomy' ) + '"]' ).attr( 'disabled', 'disabled' );
1047 }
1048 });
1049 }
1050 },
1051
1052 inputValidate: function( e ) {
1053 e.preventDefault();
1054
1055 // EDIT
1056 if (!$("input[name='product_cat1']:checked").val()) {
1057 document.getElementById('cobasub').scrollIntoView();
1058 $( 'div.dokan-product-cat1-alert' ).removeClass('dokan-hide');
1059 $( 'div.dokan-product-cat2-alert' ).addClass('dokan-hide');
1060 return;
1061 }
1062 else {
1063 $( 'div.dokan-product-cat1-alert' ).addClass('dokan-hide');
1064
1065 }
1066
1067 if (!$("input[name='product_cat2']:checked").val()) {
1068 document.getElementById('cobasub2').scrollIntoView();
1069 $( 'div.dokan-product-cat2-alert' ).removeClass('dokan-hide');
1070 return;
1071 }
1072 else {
1073 $( 'div.dokan-product-cat2-alert' ).addClass('dokan-hide');
1074 }
1075 // END EDIT
1076 // EDIT 2
1077
1078 // END EDIT 2
1079
1080 if ( $( '#post_title' ).val().trim() == '' ) {
1081 $( '#post_title' ).focus();
1082 $( 'div.dokan-product-title-alert' ).removeClass('dokan-hide');
1083 return;
1084 }else{
1085 $( 'div.dokan-product-title-alert' ).hide();
1086 }
1087
1088 if ( $( '#post_content' ).val().trim() == '' ) {
1089 document.getElementById('deskripsi_produk').scrollIntoView();
1090 $( 'div.dokan-product-description-alert' ).removeClass('dokan-hide');
1091 return;
1092 }else{
1093 $( 'div.dokan-product-description-alert' ).addClass('dokan-hide');
1094 }
1095
1096 if ( $( 'select.product_cat' ).val() == -1 ) {
1097 $( 'select.product_cat' ).focus();
1098 $( 'div.dokan-product-cat-alert' ).removeClass('dokan-hide');
1099 return;
1100 }else{
1101 $( 'div.dokan-product-cat-alert' ).hide();
1102 }
1103
1104 $( 'input[type=submit]' ).attr( 'disabled', 'disabled' );
1105 this.submit();
1106 },
1107
1108 downloadable: function() {
1109 if ( $(this).prop('checked') ) {
1110 $(this).closest('aside').find('.dokan-side-body').removeClass('dokan-hide');
1111 } else {
1112 $(this).closest('aside').find('.dokan-side-body').addClass('dokan-hide');
1113 }
1114 },
1115
1116 showDiscountSchedule: function(e) {
1117 e.preventDefault();
1118 $('.sale-schedule-container').slideToggle('fast');
1119 },
1120
1121 showManageStock: function(e) {
1122 if ( $(this).is(':checked') ) {
1123 $('.show_if_stock').slideDown('fast');
1124 } else {
1125 $('.show_if_stock').slideUp('fast');
1126 }
1127 },
1128
1129 gallery: {
1130
1131 addImages: function(e) {
1132 e.preventDefault();
1133
1134 var self = $(this),
1135 p_images = self.closest('.dokan-product-gallery').find('#product_images_container ul.product_images'),
1136 images_gid = self.closest('.dokan-product-gallery').find('#product_image_gallery');
1137
1138 if ( product_gallery_frame ) {
1139 product_gallery_frame.open();
1140 return;
1141 } else {
1142 // Create the media frame.
1143 product_gallery_frame = wp.media({
1144 // Set the title of the modal.
1145 title: dokan.i18n_choose_gallery,
1146 button: {
1147 text: dokan.i18n_choose_gallery_btn_text,
1148 },
1149 multiple: true
1150 });
1151
1152 product_gallery_frame.on( 'select', function() {
1153
1154 var selection = product_gallery_frame.state().get('selection');
1155
1156 selection.map( function( attachment ) {
1157
1158 attachment = attachment.toJSON();
1159
1160 if ( attachment.id ) {
1161 attachment_ids = [];
1162
1163 $('<li class="image" data-attachment_id="' + attachment.id + '">\
1164 <img src="' + attachment.url + '" />\
1165 <a href="#" class="action-delete">×</a>\
1166 </li>').insertBefore( p_images.find('li.add-image') );
1167
1168 $('#product_images_container ul li.image').css('cursor','default').each(function() {
1169 var attachment_id = jQuery(this).attr( 'data-attachment_id' );
1170 attachment_ids.push( attachment_id );
1171 });
1172 }
1173
1174 } );
1175
1176 images_gid.val( attachment_ids.join(',') );
1177 });
1178
1179 product_gallery_frame.open();
1180 }
1181
1182 },
1183
1184 deleteImage: function(e) {
1185 e.preventDefault();
1186
1187 var self = $(this),
1188 p_images = self.closest('.dokan-product-gallery').find('#product_images_container ul.product_images'),
1189 images_gid = self.closest('.dokan-product-gallery').find('#product_image_gallery');
1190
1191 self.closest('li.image').remove();
1192
1193 var attachment_ids = [];
1194
1195 $('#product_images_container ul li.image').css('cursor','default').each(function() {
1196 var attachment_id = $(this).attr( 'data-attachment_id' );
1197 attachment_ids.push( attachment_id );
1198 });
1199
1200 images_gid.val( attachment_ids.join(',') );
1201
1202 return false;
1203 },
1204
1205 sortable: function() {
1206 // Image ordering
1207 $('body').find('#product_images_container ul.product_images').sortable({
1208 items: 'li.image',
1209 cursor: 'move',
1210 scrollSensitivity:40,
1211 forcePlaceholderSize: true,
1212 forceHelperSize: false,
1213 helper: 'clone',
1214 opacity: 0.65,
1215 placeholder: 'dokan-sortable-placeholder',
1216 start:function(event,ui){
1217 ui.item.css('background-color','#f6f6f6');
1218 },
1219 stop:function(event,ui){
1220 ui.item.removeAttr('style');
1221 },
1222 update: function(event, ui) {
1223 var attachment_ids = [];
1224
1225 $('body').find('#product_images_container ul li.image').css('cursor','default').each(function() {
1226 var attachment_id = jQuery(this).attr( 'data-attachment_id' );
1227 attachment_ids.push( attachment_id );
1228 });
1229
1230 $('body').find('#product_image_gallery').val( attachment_ids.join(',') );
1231 }
1232 });
1233 }
1234 },
1235
1236 featuredImage: {
1237
1238 addImage: function(e) {
1239 e.preventDefault();
1240
1241 var self = $(this);
1242
1243 if ( product_featured_frame ) {
1244 product_featured_frame.open();
1245 return;
1246 } else {
1247 product_featured_frame = wp.media({
1248 // Set the title of the modal.
1249 title: dokan.i18n_choose_featured_img,
1250 button: {
1251 text: dokan.i18n_choose_featured_img_btn_text,
1252 }
1253 });
1254
1255 product_featured_frame.on('select', function() {
1256 var selection = product_featured_frame.state().get('selection');
1257
1258 selection.map( function( attachment ) {
1259 attachment = attachment.toJSON();
1260
1261 // set the image hidden id
1262 self.siblings('input.dokan-feat-image-id').val(attachment.id);
1263
1264 // set the image
1265 var instruction = self.closest('.instruction-inside');
1266 var wrap = instruction.siblings('.image-wrap');
1267
1268 // wrap.find('img').attr('src', attachment.sizes.thumbnail.url);
1269 wrap.find('img').attr('src', attachment.url);
1270 wrap.find('img').removeAttr( 'srcset' );
1271
1272 instruction.addClass('dokan-hide');
1273 wrap.removeClass('dokan-hide');
1274 });
1275 });
1276
1277 product_featured_frame.open();
1278 }
1279 },
1280
1281 removeImage: function(e) {
1282 e.preventDefault();
1283
1284 var self = $(this);
1285 var wrap = self.closest('.image-wrap');
1286 var instruction = wrap.siblings('.instruction-inside');
1287
1288 instruction.find('input.dokan-feat-image-id').val('0');
1289 wrap.addClass('dokan-hide');
1290 instruction.removeClass('dokan-hide');
1291 }
1292 },
1293
1294 fileDownloadable: function(e) {
1295 e.preventDefault();
1296
1297 var self = $(this),
1298 downloadable_frame;
1299
1300 if ( downloadable_frame ) {
1301 downloadable_frame.open();
1302 return;
1303 }
1304
1305 downloadable_frame = wp.media({
1306 title: dokan.i18n_choose_file,
1307 button: {
1308 text: dokan.i18n_choose_file_btn_text,
1309 },
1310 multiple: true
1311 });
1312
1313 downloadable_frame.on('select', function() {
1314 var selection = downloadable_frame.state().get('selection');
1315
1316 selection.map( function( attachment ) {
1317 attachment = attachment.toJSON();
1318
1319 self.closest('tr').find( 'input.wc_file_url, input.wc_variation_file_url').val(attachment.url);
1320 });
1321 });
1322
1323 downloadable_frame.on( 'ready', function() {
1324 downloadable_frame.uploader.options.uploader.params = {
1325 type: 'downloadable_product'
1326 };
1327 });
1328
1329 downloadable_frame.open();
1330 }
1331 };
1332
1333 // On DOM ready
1334 $(function() {
1335 Dokan_Editor.init();
1336
1337 // PRODUCT TYPE SPECIFIC OPTIONS.
1338 $( 'select#product_type' ).change( function() {
1339 // Get value.
1340 var select_val = $( this ).val();
1341
1342 if ( 'variable' === select_val ) {
1343 $( 'input#_manage_stock' ).change();
1344 $( 'input#_downloadable' ).prop( 'checked', false );
1345 $( 'input#_virtual' ).removeAttr( 'checked' );
1346 }
1347
1348 show_and_hide_panels();
1349
1350 $( document.body ).trigger( 'dokan-product-type-change', select_val, $( this ) );
1351
1352 }).change();
1353
1354 $('.product-edit-container').on('change', 'input#_downloadable, input#_virtual', function() {
1355 show_and_hide_panels();
1356 }).change();
1357
1358 $( 'input#_downloadable' ).change();
1359 $( 'input#_virtual' ).change();
1360
1361 function show_and_hide_panels() {
1362 var product_type = $( '#product_type' ).val();
1363 var is_virtual = $( 'input#_virtual:checked' ).length;
1364 var is_downloadable = $( 'input#_downloadable:checked' ).length;
1365
1366 // Hide/Show all with rules.
1367 var hide_classes = '.hide_if_downloadable, .hide_if_virtual';
1368 var show_classes = '.show_if_downloadable, .show_if_virtual';
1369
1370 $.each( Object.keys( dokan.product_types ), function( index, value ) {
1371 hide_classes = hide_classes + ', .hide_if_' + value;
1372 show_classes = show_classes + ', .show_if_' + value;
1373 });
1374
1375 $( hide_classes ).show();
1376 $( show_classes ).hide();
1377
1378 // Shows rules.
1379 if ( is_downloadable ) {
1380 $( '.show_if_downloadable' ).show();
1381 }
1382 if ( is_virtual ) {
1383 $( '.show_if_virtual' ).show();
1384 }
1385
1386 $( '.show_if_' + product_type ).show();
1387
1388 // Hide rules.
1389 if ( is_downloadable ) {
1390 $( '.hide_if_downloadable' ).hide();
1391 }
1392 if ( is_virtual ) {
1393 $( '.hide_if_virtual' ).hide();
1394 }
1395
1396 $( '.hide_if_' + product_type ).hide();
1397
1398 $( 'input#_manage_stock' ).change();
1399 }
1400
1401 // Sale price schedule.
1402 $( '.sale_price_dates_fields' ).each( function() {
1403 var $these_sale_dates = $( this );
1404 var sale_schedule_set = false;
1405 var $wrap = $these_sale_dates.closest( 'div, table' );
1406
1407 $these_sale_dates.find( 'input' ).each( function() {
1408 if ( '' !== $( this ).val() ) {
1409 sale_schedule_set = true;
1410 }
1411 });
1412
1413 if ( sale_schedule_set ) {
1414 $wrap.find( '.sale_schedule' ).hide();
1415 $wrap.find( '.sale_price_dates_fields' ).show();
1416 } else {
1417 $wrap.find( '.sale_schedule' ).show();
1418 $wrap.find( '.sale_price_dates_fields' ).hide();
1419 }
1420 });
1421
1422 $( '.product-edit-container' ).on( 'click', '.sale_schedule', function() {
1423 var $wrap = $(this).closest( '.product-edit-container, div.dokan-product-variation-itmes, table' );
1424 $( this ).hide();
1425 $wrap.find( '.cancel_sale_schedule' ).show();
1426 $wrap.find( '.sale_price_dates_fields' ).show();
1427
1428 return false;
1429 });
1430
1431 $( '.product-edit-container' ).on( 'click', '.cancel_sale_schedule', function() {
1432 var $wrap = $( '.product-edit-container, div.dokan-product-variation-itmes, table' );
1433
1434 $( this ).hide();
1435 $wrap.find( '.sale_schedule' ).show();
1436 $wrap.find( '.sale_price_dates_fields' ).hide();
1437 $wrap.find( '.sale_price_dates_fields' ).find( 'input' ).val('');
1438
1439 return false;
1440 });
1441
1442 function dokan_show_earning_suggestion( callback ) {
1443 let commission = $('span.vendor-earning').attr( 'data-commission' );
1444 let product_id = $( 'span.vendor-earning' ).attr( 'data-product-id' );
1445 let product_price = $( 'input.dokan-product-regular-price' ).val();
1446 let sale_price = $( 'input.dokan-product-sales-price' ).val();
1447 let earning_suggestion = $('.simple-product span.vendor-price');
1448
1449 earning_suggestion.html( 'Calculating' );
1450
1451 $.get( dokan.ajaxurl, {
1452 action: 'get_vendor_earning',
1453 product_id: product_id,
1454 product_price: product_price,
1455 product_price: sale_price ? sale_price : product_price,
1456 _wpnonce: dokan.nonce
1457 } )
1458 .done( ( response ) => {
1459 earning_suggestion.html( response );
1460
1461 if ( typeof callback === 'function' ) {
1462 callback();
1463 }
1464 } );
1465 }
1466
1467 $( "input.dokan-product-regular-price, input.dokan-product-sales-price" ).on( 'keyup', _.debounce( () => {
1468 dokan_show_earning_suggestion( function() {
1469
1470 if ( $( '#product_type' ).val() == 'simple' || $( '#product_type' ).text() == '' ) {
1471 if ( Number( $('.simple-product span.vendor-price').text() ) < 0 ) {
1472 $( $('.dokan-product-less-price-alert').removeClass('dokan-hide') );
1473 $( 'input[type=submit]' ).attr( 'disabled', 'disabled' );
1474 $( 'button[type=submit]' ).attr( 'disabled', 'disabled' );
1475 } else {
1476 $( $('.dokan-product-less-price-alert').addClass('dokan-hide') );
1477 $( 'input[type=submit]' ).removeAttr( 'disabled');
1478 $( 'button[type=submit]' ).removeAttr( 'disabled');
1479 }
1480 }
1481 } );
1482
1483 }, 750 ) );
1484
1485 function debounce_delay( callback, ms ) {
1486 var timer = 0;
1487 return function() {
1488 var context = this, args = arguments;
1489 clearTimeout(timer);
1490 timer = setTimeout(function () {
1491 callback.apply(context, args);
1492 }, ms || 0);
1493 };
1494 }
1495
1496 $('body').on( 'keyup', '.dokan-product-sales-price, .dokan-product-regular-price', debounce_delay( function(evt) {
1497 evt.preventDefault();
1498 var product_price = $( 'input.dokan-product-regular-price' ).val();
1499 var sale_price_wrap = $( 'input.dokan-product-sales-price' );
1500 var sale_price = sale_price_wrap.val();
1501 var sale_price_input_div = sale_price_wrap.parent( 'div.dokan-input-group' );
1502 var sale_price_input_msg = "<span class='error'>" + dokan.i18n_sales_price_error + "</span>";
1503 var sale_price_parent_div = sale_price_input_div.parent( 'div.sale-price' ).find( 'span.error' );
1504
1505 if ( '' == product_price ) {
1506
1507 sale_price_parent_div.remove();
1508 sale_price_input_div.after( sale_price_input_msg );
1509
1510 sale_price_wrap.val('');
1511 setTimeout(function(){
1512 sale_price_parent_div.remove();
1513 }, 5000);
1514
1515 } else if( parseFloat( product_price ) <= parseFloat( sale_price ) ) {
1516
1517 sale_price_parent_div.remove();
1518 sale_price_input_div.after( sale_price_input_msg );
1519
1520 sale_price_wrap.val('');
1521 setTimeout(function(){
1522 sale_price_parent_div.remove();
1523 }, 5000);
1524
1525 } else {
1526
1527 sale_price_parent_div.remove();
1528
1529 }
1530
1531 } ,600 ) );
1532
1533 });
1534
1535})(jQuery);
1536
1537jQuery(function($) {
1538 var api = wp.customize;
1539
1540 $('.datepicker').datepicker({
1541 dateFormat: 'yy-mm-dd'
1542 });
1543
1544 $('.tips').tooltip();
1545
1546 function showTooltip(x, y, contents) {
1547 jQuery('<div class="chart-tooltip">' + contents + '</div>').css({
1548 top: y - 16,
1549 left: x + 20
1550 }).appendTo("body").fadeIn(200);
1551 }
1552
1553 var prev_data_index = null;
1554 var prev_series_index = null;
1555
1556 jQuery(".chart-placeholder").bind("plothover", function(event, pos, item) {
1557 if (item) {
1558 if (prev_data_index != item.dataIndex || prev_series_index != item.seriesIndex) {
1559 prev_data_index = item.dataIndex;
1560 prev_series_index = item.seriesIndex;
1561
1562 jQuery(".chart-tooltip").remove();
1563
1564 if (item.series.points.show || item.series.enable_tooltip) {
1565
1566 var y = item.series.data[item.dataIndex][1];
1567
1568 tooltip_content = '';
1569
1570 if (item.series.prepend_label)
1571 tooltip_content = tooltip_content + item.series.label + ": ";
1572
1573 if (item.series.prepend_tooltip)
1574 tooltip_content = tooltip_content + item.series.prepend_tooltip;
1575
1576 tooltip_content = tooltip_content + y;
1577
1578 if (item.series.append_tooltip)
1579 tooltip_content = tooltip_content + item.series.append_tooltip;
1580
1581 if (item.series.pie.show) {
1582
1583 showTooltip(pos.pageX, pos.pageY, tooltip_content);
1584
1585 } else {
1586
1587 showTooltip(item.pageX, item.pageY, tooltip_content);
1588
1589 }
1590
1591 }
1592 }
1593 } else {
1594 jQuery(".chart-tooltip").remove();
1595 prev_data_index = null;
1596 }
1597 });
1598
1599});
1600
1601//dokan settings
1602(function($) {
1603
1604 $.validator.setDefaults({ ignore: ":hidden" });
1605
1606 var validatorError = function(error, element) {
1607 var form_group = $(element).closest('.dokan-form-group');
1608 form_group.addClass('has-error').append(error);
1609 };
1610
1611 var validatorSuccess = function(label, element) {
1612 $(element).closest('.dokan-form-group').removeClass('has-error');
1613 };
1614
1615 var api = wp.customize;
1616
1617 var Dokan_Settings = {
1618 init: function() {
1619 var self = this;
1620
1621 //image upload
1622 $('a.dokan-banner-drag').on('click', this.imageUpload);
1623 $('a.dokan-remove-banner-image').on('click', this.removeBanner);
1624
1625 $('a.dokan-pro-gravatar-drag').on('click', this.gragatarImageUpload);
1626 $('a.dokan-gravatar-drag').on('click', this.simpleImageUpload);
1627 $('a.dokan-remove-gravatar-image').on('click', this.removeGravatar);
1628
1629 this.validateForm(self);
1630
1631 return false;
1632 },
1633
1634 calculateImageSelectOptions: function(attachment, controller) {
1635 var xInit = parseInt(dokan.store_banner_dimension.width, 10),
1636 yInit = parseInt(dokan.store_banner_dimension.height, 10),
1637 flexWidth = !! parseInt(dokan.store_banner_dimension['flex-width'], 10),
1638 flexHeight = !! parseInt(dokan.store_banner_dimension['flex-height'], 10),
1639 ratio, xImg, yImg, realHeight, realWidth,
1640 imgSelectOptions;
1641
1642 realWidth = attachment.get('width');
1643 realHeight = attachment.get('height');
1644
1645 this.headerImage = new api.HeaderTool.ImageModel();
1646 this.headerImage.set({
1647 themeWidth: xInit,
1648 themeHeight: yInit,
1649 themeFlexWidth: flexWidth,
1650 themeFlexHeight: flexHeight,
1651 imageWidth: realWidth,
1652 imageHeight: realHeight
1653 });
1654
1655 controller.set( 'canSkipCrop', ! this.headerImage.shouldBeCropped() );
1656
1657 ratio = xInit / yInit;
1658 xImg = realWidth;
1659 yImg = realHeight;
1660
1661 if ( xImg / yImg > ratio ) {
1662 yInit = yImg;
1663 xInit = yInit * ratio;
1664 } else {
1665 xInit = xImg;
1666 yInit = xInit / ratio;
1667 }
1668
1669 imgSelectOptions = {
1670 handles: true,
1671 keys: true,
1672 instance: true,
1673 persistent: true,
1674 imageWidth: realWidth,
1675 imageHeight: realHeight,
1676 x1: 0,
1677 y1: 0,
1678 x2: xInit,
1679 y2: yInit
1680 };
1681
1682 if (flexHeight === false && flexWidth === false) {
1683 imgSelectOptions.aspectRatio = xInit + ':' + yInit;
1684 }
1685 if (flexHeight === false ) {
1686 imgSelectOptions.maxHeight = yInit;
1687 }
1688 if (flexWidth === false ) {
1689 imgSelectOptions.maxWidth = xInit;
1690 }
1691
1692 return imgSelectOptions;
1693 },
1694
1695 onSelect: function() {
1696 this.frame.setState('cropper');
1697 },
1698
1699 onCropped: function(croppedImage) {
1700 var url = croppedImage.url,
1701 attachmentId = croppedImage.attachment_id,
1702 w = croppedImage.width,
1703 h = croppedImage.height;
1704 this.setImageFromURL(url, attachmentId, w, h);
1705 },
1706
1707 onSkippedCrop: function(selection) {
1708 var url = selection.get('url'),
1709 w = selection.get('width'),
1710 h = selection.get('height');
1711 this.setImageFromURL(url, selection.id, w, h);
1712 },
1713
1714 setImageFromURL: function(url, attachmentId, width, height) {
1715 if ( $(this.uploadBtn).hasClass('dokan-banner-drag') ) {
1716 var wrap = $(this.uploadBtn).closest('.dokan-banner');
1717 wrap.find('input.dokan-file-field').val(attachmentId);
1718 wrap.find('img.dokan-banner-img').attr('src', url);
1719 $(this.uploadBtn).parent().siblings('.image-wrap', wrap).removeClass('dokan-hide');
1720 $(this.uploadBtn).parent('.button-area').addClass('dokan-hide');
1721 } else if ( $(this.uploadBtn).hasClass('dokan-pro-gravatar-drag') ) {
1722 var wrap = $(this.uploadBtn).closest('.dokan-gravatar');
1723 wrap.find('input.dokan-file-field').val(attachmentId);
1724 wrap.find('img.dokan-gravatar-img').attr('src', url);
1725 $(this.uploadBtn).parent().siblings('.gravatar-wrap', wrap).removeClass('dokan-hide');
1726 $(this.uploadBtn).parent('.gravatar-button-area').addClass('dokan-hide');
1727 }
1728 },
1729
1730 removeImage: function() {
1731 api.HeaderTool.currentHeader.trigger('hide');
1732 api.HeaderTool.CombinedList.trigger('control:removeImage');
1733 },
1734
1735 imageUpload: function(e) {
1736 e.preventDefault();
1737
1738 var file_frame,
1739 settings = Dokan_Settings;
1740
1741 settings.uploadBtn = this;
1742
1743 settings.frame = wp.media({
1744 multiple: false,
1745 button: {
1746 text: dokan.selectAndCrop,
1747 close: false
1748 },
1749 states: [
1750 new wp.media.controller.Library({
1751 title: dokan.chooseImage,
1752 library: wp.media.query({ type: 'image' }),
1753 multiple: false,
1754 date: false,
1755 priority: 20,
1756 suggestedWidth: dokan.store_banner_dimension.width,
1757 suggestedHeight: dokan.store_banner_dimension.height
1758 }),
1759 new wp.media.controller.Cropper({
1760 suggestedWidth: 5000,
1761 imgSelectOptions: settings.calculateImageSelectOptions
1762 })
1763 ]
1764 });
1765
1766 settings.frame.on('select', settings.onSelect, settings);
1767 settings.frame.on('cropped', settings.onCropped, settings);
1768 settings.frame.on('skippedcrop', settings.onSkippedCrop, settings);
1769
1770 settings.frame.open();
1771
1772 },
1773
1774 calculateImageSelectOptionsProfile: function(attachment, controller) {
1775 var xInit = 150,
1776 yInit = 150,
1777 flexWidth = !! parseInt(dokan.store_banner_dimension['flex-width'], 10),
1778 flexHeight = !! parseInt(dokan.store_banner_dimension['flex-height'], 10),
1779 ratio, xImg, yImg, realHeight, realWidth,
1780 imgSelectOptions;
1781
1782 realWidth = attachment.get('width');
1783 realHeight = attachment.get('height');
1784
1785 this.headerImage = new api.HeaderTool.ImageModel();
1786 this.headerImage.set({
1787 themeWidth: xInit,
1788 themeHeight: yInit,
1789 themeFlexWidth: flexWidth,
1790 themeFlexHeight: flexHeight,
1791 imageWidth: realWidth,
1792 imageHeight: realHeight
1793 });
1794
1795 controller.set( 'canSkipCrop', ! this.headerImage.shouldBeCropped() );
1796
1797 ratio = xInit / yInit;
1798 xImg = realWidth;
1799 yImg = realHeight;
1800
1801 if ( xImg / yImg > ratio ) {
1802 yInit = yImg;
1803 xInit = yInit * ratio;
1804 } else {
1805 xInit = xImg;
1806 yInit = xInit / ratio;
1807 }
1808
1809 imgSelectOptions = {
1810 handles: true,
1811 keys: true,
1812 instance: true,
1813 persistent: true,
1814 imageWidth: realWidth,
1815 imageHeight: realHeight,
1816 x1: 0,
1817 y1: 0,
1818 x2: xInit,
1819 y2: yInit
1820 };
1821
1822 if (flexHeight === false && flexWidth === false) {
1823 imgSelectOptions.aspectRatio = xInit + ':' + yInit;
1824 }
1825 if (flexHeight === false ) {
1826 imgSelectOptions.maxHeight = yInit;
1827 }
1828 if (flexWidth === false ) {
1829 imgSelectOptions.maxWidth = xInit;
1830 }
1831
1832 return imgSelectOptions;
1833 },
1834
1835 simpleImageUpload : function(e) {
1836 e.preventDefault();
1837 var file_frame,
1838 self = $(this);
1839
1840 // If the media frame already exists, reopen it.
1841 if ( file_frame ) {
1842 file_frame.open();
1843 return;
1844 }
1845
1846 // Create the media frame.
1847 file_frame = wp.media.frames.file_frame = wp.media({
1848 title: jQuery( this ).data( 'uploader_title' ),
1849 button: {
1850 text: jQuery( this ).data( 'uploader_button_text' )
1851 },
1852 multiple: false
1853 });
1854
1855 // When an image is selected, run a callback.
1856 file_frame.on( 'select', function() {
1857 var attachment = file_frame.state().get('selection').first().toJSON();
1858
1859 var wrap = self.closest('.dokan-gravatar');
1860 wrap.find('input.dokan-file-field').val(attachment.id);
1861 wrap.find('img.dokan-gravatar-img').attr('src', attachment.url);
1862 self.parent().siblings('.gravatar-wrap', wrap).removeClass('dokan-hide');
1863 self.parent('.gravatar-button-area').addClass('dokan-hide');
1864
1865 });
1866
1867 // Finally, open the modal
1868 file_frame.open();
1869 },
1870
1871 gragatarImageUpload: function(e) {
1872 e.preventDefault();
1873
1874 var file_frame,
1875 settings = Dokan_Settings;
1876
1877 settings.uploadBtn = this;
1878
1879 settings.frame = wp.media({
1880 multiple: false,
1881 button: {
1882 text: dokan.selectAndCrop,
1883 close: false
1884 },
1885 states: [
1886 new wp.media.controller.Library({
1887 title: dokan.chooseImage,
1888 library: wp.media.query({ type: 'image' }),
1889 multiple: false,
1890 date: false,
1891 priority: 20,
1892 suggestedWidth: 150,
1893 suggestedHeight: 150
1894 }),
1895 new wp.media.controller.Cropper({
1896 imgSelectOptions: settings.calculateImageSelectOptionsProfile
1897 })
1898 ]
1899 });
1900
1901 settings.frame.on('select', settings.onSelect, settings);
1902 settings.frame.on('cropped', settings.onCropped, settings);
1903 settings.frame.on('skippedcrop', settings.onSkippedCrop, settings);
1904
1905 settings.frame.open();
1906
1907 },
1908
1909 submitSettings: function(form_id) {
1910
1911 if ( typeof tinyMCE != 'undefined' ) {
1912 tinyMCE.triggerSave();
1913 }
1914
1915 var self = $( "form#" + form_id ),
1916 form_data = self.serialize() + '&action=dokan_settings&form_id=' + form_id;
1917
1918 self.find('.ajax_prev').append('<span class="dokan-loading"> </span>');
1919 $.post(dokan.ajaxurl, form_data, function(resp) {
1920
1921 self.find('span.dokan-loading').remove();
1922 $('html,body').animate({scrollTop:100});
1923
1924 if ( resp.success ) {
1925 // Harcoded Customization for template-settings function
1926 $('.dokan-ajax-response').html( $('<div/>', {
1927 'class': 'dokan-alert dokan-alert-success',
1928 'html': '<p>' + resp.data.msg + '</p>',
1929 }) );
1930
1931 $('.dokan-ajax-response').append(resp.data.progress);
1932
1933 }else {
1934 $('.dokan-ajax-response').html( $('<div/>', {
1935 'class': 'dokan-alert dokan-alert-danger',
1936 'html': '<p>' + resp.data + '</p>'
1937 }) );
1938 }
1939 });
1940 },
1941
1942 validateForm: function(self) {
1943
1944 $("form#settings-form, form#profile-form, form#store-form, form#payment-form").validate({
1945 //errorLabelContainer: '#errors'
1946 submitHandler: function(form) {
1947 self.submitSettings( form.getAttribute('id') );
1948 },
1949 errorElement: 'span',
1950 errorClass: 'error',
1951 errorPlacement: validatorError,
1952 success: validatorSuccess,
1953 ignore: '.select2-search__field, :hidden, .mapboxgl-ctrl-geocoder--input'
1954 });
1955
1956 },
1957
1958 removeBanner: function(e) {
1959 e.preventDefault();
1960
1961 var self = $(this);
1962 var wrap = self.closest('.image-wrap');
1963 var instruction = wrap.siblings('.button-area');
1964
1965 wrap.find('input.dokan-file-field').val('0');
1966 wrap.addClass('dokan-hide');
1967 instruction.removeClass('dokan-hide');
1968 },
1969
1970 removeGravatar: function(e) {
1971 e.preventDefault();
1972
1973 var self = $(this);
1974 var wrap = self.closest('.gravatar-wrap');
1975 var instruction = wrap.siblings('.gravatar-button-area');
1976
1977 wrap.find('input.dokan-file-field').val('0');
1978 wrap.addClass('dokan-hide');
1979 instruction.removeClass('dokan-hide');
1980 },
1981 };
1982
1983 var Dokan_Withdraw = {
1984
1985 init: function() {
1986 var self = this;
1987
1988 this.withdrawValidate(self);
1989 },
1990
1991 withdrawValidate: function(self) {
1992 $('form.withdraw').validate({
1993 //errorLabelContainer: '#errors'
1994
1995 errorElement: 'span',
1996 errorClass: 'error',
1997 errorPlacement: validatorError,
1998 success: validatorSuccess
1999 })
2000 }
2001 };
2002
2003 var Dokan_Seller = {
2004 init: function() {
2005 this.validate(this);
2006 },
2007
2008 validate: function(self) {
2009 // e.preventDefault();
2010
2011 $('form#dokan-form-contact-seller').validate({
2012 errorPlacement: validatorError,
2013 success: validatorSuccess,
2014 submitHandler: function(form) {
2015
2016 $(form).block({ message: null, overlayCSS: { background: '#fff url(' + dokan.ajax_loader + ') no-repeat center', opacity: 0.6 } });
2017
2018 var form_data = $(form).serialize();
2019 $.post(dokan.ajaxurl, form_data, function(resp) {
2020 $(form).unblock();
2021
2022 if ( typeof resp.data !== 'undefined' ) {
2023 $(form).find('.ajax-response').html(resp.data);
2024 }
2025
2026 $(form).find('input[type=text], input[type=email], textarea').val('').removeClass('valid');
2027 });
2028 }
2029 });
2030 }
2031 };
2032
2033 $(function() {
2034 Dokan_Settings.init();
2035 Dokan_Withdraw.init();
2036 Dokan_Seller.init();
2037
2038 $('.dokan-form-horizontal').on('change', 'input[type=checkbox]#lbl_setting_minimum_quantity', function(){
2039 var showSWDiscount = $( '.show_if_needs_sw_discount' );
2040 if ( $( this ).is(':checked') ) {
2041 showSWDiscount.find('input[type="number"]').val('');
2042 showSWDiscount.slideDown('slow');
2043 } else {
2044 showSWDiscount.slideUp('slow');
2045 }
2046 } );
2047 });
2048
2049})(jQuery);
2050
2051//localize Validation messages
2052(function($){
2053 var dokan_messages = DokanValidateMsg;
2054
2055 dokan_messages.maxlength = $.validator.format( dokan_messages.maxlength_msg );
2056 dokan_messages.minlength = $.validator.format( dokan_messages.minlength_msg );
2057 dokan_messages.rangelength = $.validator.format( dokan_messages.rangelength_msg );
2058 dokan_messages.range = $.validator.format( dokan_messages.range_msg );
2059 dokan_messages.max = $.validator.format( dokan_messages.max_msg );
2060 dokan_messages.min = $.validator.format( dokan_messages.min_msg );
2061
2062 $.validator.messages = dokan_messages;
2063
2064 $(document).on('click','#dokan_store_tnc_enable',function(e) {
2065 if($(this).is(':checked')) {
2066 $('#dokan_tnc_text').show();
2067 }else {
2068 $('#dokan_tnc_text').hide();
2069 }
2070 }).ready(function(e){
2071 if($('#dokan_store_tnc_enable').is(':checked')) {
2072 $('#dokan_tnc_text').show();
2073 }else {
2074 $('#dokan_tnc_text').hide();
2075 }
2076 });
2077
2078})(jQuery);
2079
2080;(function($) {
2081 function resize_dummy_image() {
2082 var width = dokan.store_banner_dimension.width,
2083 height = (dokan.store_banner_dimension.height / dokan.store_banner_dimension.width) * $('#dokan-content').width();
2084
2085 $('.profile-info-img.dummy-image').css({
2086 height: height
2087 });
2088 }
2089
2090 resize_dummy_image();
2091
2092 $(window).on('resize', function (e) {
2093 resize_dummy_image();
2094 });
2095
2096 // Ajax product search box
2097 $( ':input.dokan-product-search' ).filter( ':not(.enhanced)' ).each( function() {
2098 var select2_args = {
2099 allowClear: $( this ).data( 'allow_clear' ) ? true : false,
2100 placeholder: $( this ).data( 'placeholder' ),
2101 minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3',
2102 escapeMarkup: function( m ) {
2103 return m;
2104 },
2105 language: {
2106 errorLoading: function() {
2107 // Workaround for https://github.com/select2/select2/issues/4355 instead of i18n_ajax_error.
2108 return dokan.i18n_searching;
2109 },
2110 inputTooLong: function( args ) {
2111 var overChars = args.input.length - args.maximum;
2112
2113 if ( 1 === overChars ) {
2114 return dokan.i18n_input_too_long_1;
2115 }
2116
2117 return dokan.i18n_input_too_long_n.replace( '%qty%', overChars );
2118 },
2119 inputTooShort: function( args ) {
2120 var remainingChars = args.minimum - args.input.length;
2121
2122 if ( 1 === remainingChars ) {
2123 return dokan.i18n_input_too_short_1;
2124 }
2125
2126 return dokan.i18n_input_too_short_n.replace( '%qty%', remainingChars );
2127 },
2128 loadingMore: function() {
2129 return dokan.i18n_load_more;
2130 },
2131 maximumSelected: function( args ) {
2132 if ( args.maximum === 1 ) {
2133 return dokan.i18n_selection_too_long_1;
2134 }
2135
2136 return dokan.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
2137 },
2138 noResults: function() {
2139 return dokan.i18n_no_matches;
2140 },
2141 searching: function() {
2142 return dokan.i18n_searching;
2143 }
2144 },
2145 ajax: {
2146 url: dokan.ajaxurl,
2147 dataType: 'json',
2148 delay: 250,
2149 data: function( params ) {
2150 return {
2151 term: params.term,
2152 action: $( this ).data( 'action' ) || 'dokan_json_search_products_and_variations',
2153 security: dokan.search_products_nonce,
2154 exclude: $( this ).data( 'exclude' ),
2155 user_ids: $( this ).data( 'user_ids' ),
2156 include: $( this ).data( 'include' ),
2157 limit: $( this ).data( 'limit' )
2158 };
2159 },
2160 processResults: function( data ) {
2161 var terms = [];
2162
2163 if ( data ) {
2164 $.each( data, function( id, text ) {
2165 terms.push( { id: id, text: text } );
2166 });
2167 }
2168 return {
2169 results: terms
2170 };
2171 },
2172 cache: true
2173 }
2174 };
2175
2176 // select2_args = $.extend( select2_args, {} );
2177
2178 $( this ).select2( select2_args ).addClass( 'enhanced' );
2179
2180 if ( $( this ).data( 'sortable' ) ) {
2181 var $select = $(this);
2182 var $list = $( this ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' );
2183
2184 $list.sortable({
2185 placeholder : 'ui-state-highlight select2-selection__choice',
2186 forcePlaceholderSize: true,
2187 items : 'li:not(.select2-search__field)',
2188 tolerance : 'pointer',
2189 stop: function() {
2190 $( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function() {
2191 var id = $( this ).data( 'data' ).id;
2192 var option = $select.find( 'option[value="' + id + '"]' )[0];
2193 $select.prepend( option );
2194 } );
2195 }
2196 });
2197 }
2198 });
2199
2200 /**
2201 * Trigger bulk item checkbox selections
2202 */
2203 var bulkItemsSelection = {
2204 init: function() {
2205 selected_items = [];
2206
2207 $( '#cb-select-all' ).on( 'change', function( e ) {
2208 var self = $(this);
2209
2210 var item_id = $( '.cb-select-items' );
2211
2212 if ( self.is( ':checked' ) ) {
2213 item_id.each( function ( key, value ) {
2214 var item = $( value );
2215 item.prop( 'checked', 'checked' );
2216 } );
2217 } else {
2218 item_id.each( function ( key, value ) {
2219 $( value ).prop( 'checked', '' );
2220 selected_items.pop();
2221 } );
2222 }
2223 } );
2224 }
2225 };
2226
2227 bulkItemsSelection.init();
2228
2229
2230
2231 $( '.product-cat-stack-dokan li.has-children' ).on( 'click', '> a span.caret-icon', function ( e ) {
2232 e.preventDefault();
2233 var self = $( this ),
2234 liHasChildren = self.closest( 'li.has-children' );
2235
2236 if ( !liHasChildren.find( '> ul.children' ).is( ':visible' ) ) {
2237 self.find( 'i.fa' ).addClass( 'fa-rotate-90' );
2238 if ( liHasChildren.find( '> ul.children' ).hasClass( 'level-0' ) ) {
2239 self.closest( 'a' ).css( { 'borderBottom': 'none' } );
2240 }
2241 }
2242
2243 liHasChildren.find( '> ul.children' ).slideToggle( 'fast', function () {
2244 if ( !$( this ).is( ':visible' ) ) {
2245 self.find( 'i.fa' ).removeClass( 'fa-rotate-90' );
2246
2247 if ( liHasChildren.find( '> ul.children' ).hasClass( 'level-0' ) ) {
2248 self.closest( 'a' ).css( { 'borderBottom': '1px solid #eee' } );
2249 }
2250 }
2251 } );
2252 } );
2253
2254 $( '.store-cat-stack-dokan li.has-children' ).on( 'click', '> a span.caret-icon', function ( e ) {
2255 e.preventDefault();
2256 var self = $( this ),
2257 liHasChildren = self.closest( 'li.has-children' );
2258
2259 if ( !liHasChildren.find( '> ul.children' ).is( ':visible' ) ) {
2260 self.find( 'i.fa' ).addClass( 'fa-rotate-90' );
2261 if ( liHasChildren.find( '> ul.children' ).hasClass( 'level-0' ) ) {
2262 self.closest( 'a' ).css( { 'borderBottom': 'none' } );
2263 }
2264 }
2265
2266 liHasChildren.find( '> ul.children' ).slideToggle( 'fast', function () {
2267 if ( !$( this ).is( ':visible' ) ) {
2268 self.find( 'i.fa' ).removeClass( 'fa-rotate-90' );
2269
2270 if ( liHasChildren.find( '> ul.children' ).hasClass( 'level-0' ) ) {
2271 self.closest( 'a' ).css( { 'borderBottom': '1px solid #eee' } );
2272 }
2273 }
2274 } );
2275 } );
2276
2277 $(document).ready(function(){
2278 var selectedLi = $('#cat-drop-stack ul').find( 'a.selected' );
2279 selectedLi.css({ fontWeight: 'bold' });
2280
2281 selectedLi.parents('ul.children').each( function( i, val ) {
2282 $( val ).css({ display: 'block' });
2283 });
2284 });
2285
2286
2287})(jQuery);
2288
2289;(function($) {
2290 var storeLists = {
2291 /**
2292 * Query holder
2293 *
2294 * @type object
2295 */
2296 query: {},
2297
2298 /**
2299 * Form holder
2300 *
2301 * @type object
2302 */
2303 form: null,
2304
2305 /**
2306 * Category item string holder
2307 *
2308 * @type array
2309 */
2310 cateItemStringArray: [],
2311
2312 /**
2313 * Init all the methods
2314 *
2315 * @return void
2316 */
2317 init: function() {
2318 $( '#dokan-store-listing-filter-wrap .sort-by #stores_orderby' ).on( 'change', this.buildSortByQuery );
2319 $( '#dokan-store-listing-filter-wrap .toggle-view span' ).on( 'click', this.toggleView );
2320 $( '#dokan-store-listing-filter-wrap .dokan-store-list-filter-button, #dokan-store-listing-filter-wrap .dokan-icons, #dokan-store-listing-filter-form-wrap .apply-filter #cancel-filter-btn ' ).on( 'click', this.toggleForm );
2321
2322 // Build query string
2323 $( '#dokan-store-listing-filter-form-wrap .store-search-input' ).on( 'change', this.buildSearchQuery );
2324
2325 // Submit the form
2326 $( '#dokan-store-listing-filter-form-wrap .apply-filter #apply-filter-btn' ).on( 'click', this.submitForm );
2327
2328 this.maybeHideListView();
2329
2330 const self = storeLists;
2331
2332 self.form = document.forms.dokan_store_lists_filter_form;
2333
2334 const view = self.getLocal( 'dokan-layout' );
2335
2336 if ( view ) {
2337 const toggleBtns = $( '.toggle-view span' );
2338 self.setView( view, toggleBtns );
2339 }
2340
2341 const params = self.getParams();
2342
2343 if ( params.length ) {
2344 let openTheForm = false;
2345
2346 params.forEach( function( param ) {
2347 const keys = Object.keys( param );
2348 const values = Object.values( param );
2349
2350 if ( ! keys.includes( 'stores_orderby' ) || params.length > 1 ) {
2351 openTheForm = true;
2352 }
2353
2354 self.setParams( keys, values );
2355 });
2356
2357 if ( openTheForm ) {
2358 $( '#dokan-store-listing-filter-form-wrap' ).slideToggle();
2359 }
2360 }
2361 },
2362
2363 buildSortByQuery: function( event ) {
2364 const self = storeLists;
2365
2366 self.query.stores_orderby = event.target.value;
2367 self.submitForm( event );
2368 },
2369
2370 /**
2371 * Toggle store layout view
2372 *
2373 * @param string event
2374 *
2375 * @return void
2376 */
2377 toggleView: function( event ) {
2378 const self = storeLists;
2379 const currentElement = $( event.target );
2380 const elements = currentElement.parent().find( 'span' );
2381 const view = currentElement.data( 'view' );
2382
2383 self.setView( view, elements );
2384 self.setLocal( 'dokan-layout', view );
2385 },
2386
2387 /**
2388 * Set grid or list view
2389 *
2390 * @param string view
2391 * @param array elements
2392 *
2393 * @return void
2394 */
2395 setView: function( view, elements ) {
2396 if ( typeof view === 'undefined'
2397 || view.length < 1
2398 || typeof elements === 'undefined'
2399 || elements.length < 1
2400 ) {
2401 return;
2402 }
2403
2404 const listingWrap = $( '#dokan-seller-listing-wrap' );
2405
2406 [...elements].forEach( function( value ) {
2407 const element = $( value );
2408
2409 if ( view === element.data( 'view' ) ) {
2410 element.addClass( 'active' );
2411 listingWrap.addClass( view );
2412 } else {
2413 element.removeClass( 'active' );
2414 listingWrap.removeClass( element.data( 'view' ) );
2415 }
2416 });
2417 },
2418
2419 /**
2420 * Toggle form
2421 *
2422 * @param string event
2423 *
2424 * @return void
2425 */
2426 toggleForm: function( event ) {
2427 event.preventDefault();
2428
2429 $( '#dokan-store-listing-filter-form-wrap' ).slideToggle();
2430 },
2431
2432 /**
2433 * Build Search Query
2434 *
2435 * @param string event
2436 *
2437 * @return void
2438 */
2439 buildSearchQuery: function( event ) {
2440 if ( event.target.value ) {
2441 storeLists.query.dokan_seller_search = event.target.value;
2442 } else {
2443 delete storeLists.query.dokan_seller_search;
2444 }
2445 },
2446
2447 /**
2448 * Submit the form
2449 *
2450 * @param string event
2451 *
2452 * @return void
2453 */
2454 submitForm: function( event ) {
2455 event.preventDefault();
2456
2457 const queryString = decodeURIComponent( $.param( storeLists.query ) );
2458
2459 window.history.pushState( null, null, `?${queryString}` );
2460 window.location.reload();
2461 },
2462
2463 /**
2464 * Add data into local storage
2465 *
2466 * @param string key
2467 * @param mix value
2468 *
2469 * @return void
2470 */
2471 setLocal: function( key, value ) {
2472 window.localStorage.setItem( key, value );
2473 },
2474
2475 /**
2476 * Get data from local storage
2477 *
2478 * @param string key
2479 *
2480 * @return mix
2481 */
2482 getLocal: function( key ) {
2483 return window.localStorage.getItem( key );
2484 },
2485
2486 setParams: function( key, value ) {
2487 const self = storeLists;
2488 const elements = self.form ? self.form.elements : '';
2489 const sortingForm = document.forms.stores_sorting;
2490 const sortingFormElements = sortingForm ? sortingForm.elements : '';
2491
2492 Object.values( sortingFormElements ).forEach( function( element ) {
2493 if ( element.name === key[0] ) {
2494 $( element ).val( value[0] );
2495 }
2496 });
2497
2498 // on reload, if query string exists, set the form input elment value
2499 Object.values( elements ).forEach( function( element ) {
2500 if ( key.includes( element.name ) ) {
2501 if ( element.type === 'checkbox' ) {
2502 element.checked = ['yes', 'true', '1'].includes( value[0] ) ? true : false;
2503 } else if ( [ 'text', 'search' ].includes( element.type ) ) {
2504 element.value = value[0];
2505 }
2506 }
2507
2508 // for backward compatibility we'll allow `store_category[]` query_var.
2509 if ( key[0].includes( 'store_categories[' ) || key[0].includes( 'store_category[' ) ) {
2510 const trimedValue = value[0].split( ' ' ).join( '-' );
2511 const cateItem = $( `[data-slug=${trimedValue}]` );
2512
2513 if ( ! self.cateItemStringArray.includes( cateItem.text().trim() ) ) {
2514 self.cateItemStringArray.push( cateItem.text().trim() );
2515 }
2516
2517 cateItem.addClass( 'dokan-btn-theme' );
2518
2519 } else if ( key[0] === 'rating' ) {
2520 const trimedValue = value[0].split( ' ' ).join( '-' );
2521
2522 $( `[data-${key[0]}=${trimedValue}]` ).addClass( 'active' );
2523 $( `[data-rating=${trimedValue}]` ).parent().addClass( 'selected' );
2524 }
2525 });
2526
2527 key.forEach( function( param, index ) {
2528 if ( ! param.includes( '[' ) ) {
2529 self.query[ param ] = value[ index ];
2530 }
2531 });
2532 },
2533
2534 /**
2535 * Get params from
2536 *
2537 * @return array
2538 */
2539 getParams: function() {
2540 const params = new URLSearchParams( location.search );
2541 const allParams = [];
2542
2543 params.forEach( function( value, key ) {
2544 allParams.push( {
2545 [key]: value
2546 } );
2547 });
2548
2549 return allParams;
2550 },
2551
2552 /**
2553 * On mobile screen hide the grid, list view button
2554 *
2555 * @return void
2556 */
2557 maybeHideListView: function() {
2558 const self = storeLists;
2559
2560 if ( window.matchMedia( '(max-width: 767px)' ).matches ) {
2561 if ( 'list-view' === self.getLocal( 'dokan-layout' ) ) {
2562 self.setLocal( 'dokan-layout', 'grid-view' );
2563 }
2564 }
2565
2566 $( window ).on( 'resize', function() {
2567 const container = $(this);
2568
2569 if ( container.width() < 767 ) {
2570 $( '#dokan-seller-listing-wrap' ).removeClass( 'list-view' );
2571 $( '#dokan-seller-listing-wrap' ).addClass( 'grid-view' );
2572 } else {
2573 $( '.toggle-view.item span' ).last().removeClass( 'active' );
2574 $( '.toggle-view.item span' ).first().addClass( 'active' );
2575 }
2576 });
2577 }
2578 };
2579
2580 if ( window.dokan ) {
2581 window.dokan.storeLists = storeLists;
2582 window.dokan.storeLists.init();
2583 }
2584
2585})(jQuery);