File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 4
4
$ TRANSLATIONS = include "../translations.php " ;
5
5
// Get the keys of the first value in the translations array
6
6
$ LOCALES = array_keys ($ TRANSLATIONS );
7
+
8
+ /**
9
+ * Convert a camelCase string to a skewer-case string
10
+ * @param string $str The camelCase string
11
+ * @return string The skewer-case string
12
+ */
13
+ function camel_to_skewer (string $ str ): string
14
+ {
15
+ return preg_replace_callback (
16
+ "/([A-Z])/ " ,
17
+ function ($ matches ) {
18
+ return "- " . strtolower ($ matches [0 ]);
19
+ },
20
+ $ str
21
+ );
22
+ }
7
23
?>
8
24
9
25
<!DOCTYPE html>
@@ -65,7 +81,18 @@ function gtag() {
65
81
<label for="theme">Theme</label>
66
82
<select class="param" id="theme" name="theme" placeholder="default">
67
83
<?php foreach ($ THEMES as $ theme => $ options ): ?>
68
- <option><?php echo $ theme ; ?> </option>
84
+ <?php
85
+ $ dataAttrs = "" ;
86
+ foreach ($ options as $ key => $ value ) {
87
+ // convert key from camelCase to skewer-case
88
+ $ key = camel_to_skewer ($ key );
89
+ // remove '#' from hex color value
90
+ $ value = preg_replace ("/^\#/ " , "" , $ value );
91
+ // add data attribute
92
+ $ dataAttrs .= "data- " . $ key . "= \"" . $ value . "\" " ;
93
+ }
94
+ ?>
95
+ <option value="<?php echo $ theme ; ?> " <?php echo $ dataAttrs ; ?> ><?php echo $ theme ; ?> </option>
69
96
<?php endforeach ; ?>
70
97
</select>
71
98
Original file line number Diff line number Diff line change @@ -144,12 +144,20 @@ const preview = {
144
144
* Export the advanced parameters to PHP code for creating a new theme
145
145
*/
146
146
exportPhp ( ) {
147
- const params = this . objectFromElements ( document . querySelectorAll ( ".advanced .param.jscolor" ) ) ;
147
+ // get default values from the currently selected theme
148
+ const themeSelect = document . querySelector ( "#theme" ) ;
149
+ const selectedOption = themeSelect . options [ themeSelect . selectedIndex ] ;
150
+ const defaultParams = selectedOption . dataset ;
151
+ // get parameters with the advanced options
152
+ const advancedParams = this . objectFromElements ( document . querySelectorAll ( ".advanced .param.jscolor" ) ) ;
153
+ // update default values with the advanced options
154
+ const params = { ...defaultParams , ...advancedParams } ;
155
+ // convert parameters to PHP code
148
156
const mappings = Object . keys ( params )
149
157
. map ( ( key ) => ` "${ key } " => "#${ params [ key ] } ",` )
150
158
. join ( "\n" ) ;
151
159
const output = `[\n${ mappings } \n]` ;
152
-
160
+ // set the textarea value to the output
153
161
const textarea = document . getElementById ( "exportedPhp" ) ;
154
162
textarea . value = output ;
155
163
textarea . hidden = false ;
You can’t perform that action at this time.
0 commit comments