Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/css/fundamentals.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + // Function to get proper default value for a responsive value.
4 + // [
5 + // 'desktop' => 'value',
6 + // 'tablet' => 'value',
7 + // 'mobile' => 'value',
8 + // ] => 'value'
9 + //
10 + // 'value' => 'value'
11 + //
12 + // [
13 + // 'desktop' => 'value',
14 + // 'tablet' => 'value',
15 + // 'mobile' => 'value1',
16 + // ] => [
17 + // 'desktop' => 'value',
18 + // 'tablet' => 'value',
19 + // 'mobile' => 'value1',
20 + // ]
21 + function blocksy_default_responsive_value($value) {
22 + if (
23 + // If is just plain array
24 + is_array($value) && ! isset($value['desktop'])
25 + &&
26 + // If it's scalar value
27 + ! is_array($value)
28 + ) {
29 + return $value;
30 + }
31 +
32 + if (
33 + isset($value['desktop'])
34 + &&
35 + isset($value['tablet'])
36 + &&
37 + isset($value['mobile'])
38 + ) {
39 + if (
40 + $value['desktop'] == $value['tablet']
41 + &&
42 + $value['desktop'] == $value['mobile']
43 + ) {
44 + return $value['desktop'];
45 + }
46 + }
47 +
48 + return $value;
49 + }
50 +
51 + if (! function_exists('blocksy_expand_responsive_value')) {
52 + function blocksy_expand_responsive_value($value, $is_responsive = true) {
53 + if (is_array($value) && isset($value['desktop'])) {
54 + if (! $is_responsive) {
55 + return $value['desktop'];
56 + }
57 +
58 + return $value;
59 + }
60 +
61 + if (! $is_responsive) {
62 + return $value;
63 + }
64 +
65 + return [
66 + 'desktop' => $value,
67 + 'tablet' => $value,
68 + 'mobile' => $value,
69 + ];
70 + }
71 + }
72 +
73 + if (! function_exists('blocksy_map_values')) {
74 + function blocksy_map_values($args = []) {
75 + $args = wp_parse_args(
76 + $args,
77 + [
78 + 'value' => null,
79 + 'map' => []
80 + ]
81 + );
82 +
83 + if (
84 + ! is_array($args['value'])
85 + &&
86 + isset($args['map'][$args['value']])
87 + ) {
88 + return $args['map'][$args['value']];
89 + }
90 +
91 + if (! is_array($args['value'])) {
92 + return $args['value'];
93 + }
94 +
95 + foreach ($args['value'] as $key => $value) {
96 + if (! is_array($value) && isset($args['map'][$value])) {
97 + $args['value'][$key] = $args['map'][$value];
98 + }
99 + }
100 +
101 + return $args['value'];
102 + }
103 + }
104 +
105 + function blocksy_output_css_vars($args = []) {
106 + $args = wp_parse_args(
107 + $args,
108 + [
109 + 'css' => null,
110 + 'tablet_css' => null,
111 + 'mobile_css' => null,
112 +
113 + // string or array
114 + // array is used for responsive selector
115 + 'selector' => null,
116 +
117 + 'desktop_selector_prefix' => '',
118 + 'tablet_selector_prefix' => '',
119 + 'mobile_selector_prefix' => '',
120 +
121 + 'variableName' => null,
122 +
123 + // custom-property | property
124 + 'variableType' => 'custom-property',
125 +
126 + 'value' => null,
127 +
128 + 'value_suffix' => '',
129 +
130 + 'responsive' => false
131 + ]
132 + );
133 +
134 + if (! $args['variableName']) {
135 + throw new Error('variableName missing in args!');
136 + }
137 +
138 + if ($args['responsive']) {
139 + blocksy_assert_args($args, ['tablet_css', 'mobile_css']);
140 + }
141 +
142 + $value = blocksy_expand_responsive_value($args['value']);
143 +
144 + if ($args['variableType'] === 'custom-property') {
145 + $args['variableName'] = '--' . $args['variableName'];
146 + }
147 +
148 + if (
149 + substr_count(
150 + $value['desktop'], '('
151 + ) !== substr_count(
152 + $value['desktop'], ')'
153 + )
154 + ) {
155 + $value['desktop'] = '"' . $value['desktop'] . '"';
156 + }
157 +
158 + if (
159 + substr_count(
160 + $value['tablet'], '('
161 + ) !== substr_count(
162 + $value['tablet'], ')'
163 + )
164 + ) {
165 + $value['tablet'] = '"' . $value['tablet'] . '"';
166 + }
167 +
168 + if (
169 + substr_count(
170 + $value['mobile'], '('
171 + ) !== substr_count(
172 + $value['mobile'], ')'
173 + )
174 + ) {
175 + $value['mobile'] = '"' . $value['mobile'] . '"';
176 + }
177 +
178 + $responsive_selector = blocksy_expand_responsive_value($args['selector']);
179 +
180 + if (! empty($args['desktop_selector_prefix'])) {
181 + $responsive_selector['desktop'] = implode(' ', [
182 + $args['desktop_selector_prefix'],
183 + $responsive_selector['desktop']
184 + ]);
185 + }
186 +
187 + if (! empty($args['tablet_selector_prefix'])) {
188 + $responsive_selector['tablet'] = implode(' ', [
189 + $args['tablet_selector_prefix'],
190 + $responsive_selector['tablet']
191 + ]);
192 + }
193 +
194 + if (! empty($args['mobile_selector_prefix'])) {
195 + $responsive_selector['mobile'] = implode(' ', [
196 + $args['mobile_selector_prefix'],
197 + $responsive_selector['mobile']
198 + ]);
199 + }
200 +
201 + $args['css']->put(
202 + $responsive_selector['desktop'],
203 + $args['variableName'] . ': ' . $value['desktop'] . $args['value_suffix']
204 + );
205 +
206 + if (
207 + $args['responsive']
208 + &&
209 + (
210 + $value['tablet'] !== $value['desktop']
211 + ||
212 + $responsive_selector['desktop'] !== $responsive_selector['tablet']
213 + )
214 + ) {
215 + $args['tablet_css']->put(
216 + $responsive_selector['tablet'],
217 + $args['variableName'] . ': ' . $value['tablet'] . $args['value_suffix']
218 + );
219 + }
220 +
221 + if (
222 + $args['responsive']
223 + &&
224 + (
225 + $value['tablet'] !== $value['mobile']
226 + ||
227 + $responsive_selector['tablet'] !== $responsive_selector['mobile']
228 + )
229 + ) {
230 + $args['mobile_css']->put(
231 + $responsive_selector['mobile'],
232 + $args['variableName'] . ': ' . $value['mobile'] . $args['value_suffix']
233 + );
234 + }
235 + }
236 +