Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/static/js/backend/woo-variation.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + import { createElement, createRoot } from '@wordpress/element'
2 + import OptionsRoot from '../options/OptionsRoot'
3 + import { getValueFromInput } from '../options/helpers/get-value-from-input'
4 + import $ from 'jquery'
5 + import { __ } from 'ct-i18n'
6 +
7 + export const initWooVariation = (variationWrapper) => {
8 + let uploadImage = variationWrapper.querySelector('.upload_image')
9 +
10 + if (!uploadImage) {
11 + return
12 + }
13 +
14 + if (uploadImage.closest('.form-flex-box')) {
15 + uploadImage = uploadImage.closest('.form-flex-box')
16 + } else {
17 + uploadImage = uploadImage.nextElementSibling
18 + }
19 +
20 + const div = document.createElement('div')
21 +
22 + div.classList.add('form-row')
23 + div.classList.add('form-row-full')
24 + div.classList.add('ct-variation-image-gallery')
25 +
26 + uploadImage.insertAdjacentElement('afterend', div)
27 +
28 + const maybeWpmlLocked = document.querySelector('.wcml_lock_img')
29 +
30 + const input = variationWrapper.querySelector(
31 + '[name*="blocksy_post_meta_options"]'
32 + )
33 +
34 + if (!input) {
35 + return
36 + }
37 +
38 + const options = {
39 + gallery_source: {
40 + label: __('Variation Gallery', 'blocksy'),
41 + type: maybeWpmlLocked ? 'hidden' : 'ct-radio',
42 + value: 'default',
43 + design: 'inline',
44 + divider: 'bottom',
45 + choices: {
46 + default: __('Default', 'blocksy'),
47 + custom: __('Custom', 'blocksy'),
48 + },
49 + },
50 +
51 + ...(maybeWpmlLocked
52 + ? {
53 + inheritance: {
54 + label: __('Variation Gallery', 'blocksy'),
55 + type: 'ct-notification',
56 + design: 'inline',
57 + text: maybeWpmlLocked.outerHTML
58 + .replace('wcml_lock_img', '')
59 + .replace('display: none;', ''),
60 + },
61 + }
62 + : {}),
63 +
64 + condition: maybeWpmlLocked
65 + ? {
66 + type: 'hidden',
67 + }
68 + : {
69 + type: 'ct-condition',
70 + condition: {
71 + gallery_source: 'custom',
72 + },
73 + options: {
74 + images: {
75 + label: __('Custom Image Gallery', 'blocksy'),
76 + type: 'ct-multi-image-uploader',
77 + design: ({ value }) =>
78 + value.length === 0 ? 'inline' : 'block',
79 + value: [],
80 + },
81 + },
82 + },
83 + }
84 +
85 + const root = createRoot(div)
86 + root.render(
87 + <OptionsRoot
88 + options={options}
89 + value={getValueFromInput(
90 + options,
91 + JSON.parse(input.value),
92 + null,
93 + false
94 + )}
95 + input_id={input.id}
96 + input_name={input.name}
97 + hasRevertButton={false}
98 + />
99 + )
100 + }
101 +
102 + export const initAllWooVariations = () => {
103 + ;[
104 + ...document.querySelectorAll(
105 + '.woocommerce_variations .woocommerce_variation'
106 + ),
107 + ].map((variationWrapper) => {
108 + if (variationWrapper.hasBlocksyOptions) {
109 + return
110 + }
111 +
112 + variationWrapper.hasBlocksyOptions = true
113 +
114 + initWooVariation(variationWrapper)
115 + })
116 + }
117 +