Skip to content

Commit af2aa49

Browse files
authored
refactor: Consistent ID naming, redundant return, styling (DenverCoder1#443)
1 parent 793afe0 commit af2aa49

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/demo/css/style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ input:focus:invalid {
200200

201201
.advanced summary {
202202
padding: 6px;
203+
cursor: pointer;
203204
}
204205

205206
.advanced .parameters {
@@ -304,7 +305,7 @@ input:focus:invalid {
304305
content: "You must first input a valid username.";
305306
}
306307

307-
textarea#exportedPhp {
308+
textarea#exported-php {
308309
margin-top: 10px;
309310
width: 100%;
310311
resize: vertical;

src/demo/index.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ function gtag() {
102102
</select>
103103

104104
<label for="hide_border">Hide Border</label>
105-
<select class="param" id="hide_border" name="hide_border">
105+
<select class="param" id="hide-border" name="hide_border">
106106
<option>false</option>
107107
<option>true</option>
108108
</select>
109109

110110
<label for="border_radius">Border Radius</label>
111-
<input class="param" type="number" id="border_radius" name="border_radius" placeholder="4.5" value="4.5" step="0.1">
111+
<input class="param" type="number" id="border-radius" name="border_radius" placeholder="4.5" value="4.5" step="0.1">
112112

113113
<label for="locale">Locale</label>
114114
<select class="param" id="locale" name="locale">
@@ -121,7 +121,7 @@ function gtag() {
121121
</select>
122122

123123
<label for="date_format">Date Format</label>
124-
<select class="param" id="date_format" name="date_format">
124+
<select class="param" id="date-format" name="date_format">
125125
<option value="">default</option>
126126
<option value="M j[, Y]">Aug 10, 2016</option>
127127
<option value="j M[ Y]">10 Aug 2016</option>
@@ -146,11 +146,11 @@ function gtag() {
146146
<option><?php echo $option; ?></option>
147147
<?php endforeach; ?>
148148
</select>
149-
<button class="plus btn" type="button" onclick="return preview.addProperty()">+</button>
149+
<button class="plus btn" type="button" onclick="preview.addProperty()">+</button>
150150
</div>
151-
<button class="btn" type="button" onclick="return preview.exportPhp()">Export to PHP</button>
152-
<button id="clear_button" class="btn" type="button" onclick="return preview.removeAllProperties()">Clear Options</button>
153-
<textarea id="exportedPhp" hidden></textarea>
151+
<button class="btn" type="button" onclick="preview.exportPhp()">Export to PHP</button>
152+
<button id="clear-button" class="btn" type="button" onclick="preview.removeAllProperties()" disabled>Clear Options</button>
153+
<textarea id="exported-php" hidden></textarea>
154154
</details>
155155

156156
<button class="btn" type="submit">Open Permalink</button>

src/demo/js/script.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ const preview = {
3838
const copyButton = document.querySelector(".copy-button");
3939
copyButton.disabled = Boolean(document.querySelector("#user:invalid") || !document.querySelector("#user").value);
4040
// disable clear button if no added advanced options
41-
const clearButton = document.querySelector("#clear_button");
41+
const clearButton = document.querySelector("#clear-button");
4242
clearButton.disabled = !document.querySelectorAll(".minus").length;
4343
},
4444

4545
/**
4646
* Add a property in the advanced section
4747
* @param {string} property - the name of the property, selected element is used if not provided
4848
* @param {string} value - the value to set the property to
49-
* @returns {false} false to prevent the default action
5049
*/
51-
addProperty(property, value = "#DD2727FF") {
50+
addProperty(property, value = "#EB5454FF") {
5251
const selectElement = document.querySelector("#properties");
5352
// if no property passed, get the currently selected property
5453
const propertyName = property || selectElement.value;
@@ -101,13 +100,11 @@ const preview = {
101100
// update and exit
102101
this.update();
103102
}
104-
return false;
105103
},
106104

107105
/**
108106
* Remove a property from the advanced section
109107
* @param {string} property - the name of the property to remove
110-
* @returns {false} false to prevent the default action
111108
*/
112109
removeProperty(property) {
113110
const parent = document.querySelector(".advanced .parameters");
@@ -120,7 +117,6 @@ const preview = {
120117
option.disabled = false;
121118
// update and exit
122119
this.update();
123-
return false;
124120
},
125121

126122
/**
@@ -138,7 +134,7 @@ const preview = {
138134
},
139135

140136
/**
141-
* Create a key-value mapping of ids to values from all elements in a Node list
137+
* Create a key-value mapping of names to values from all elements in a Node list
142138
* @param {NodeList} elements - the elements to get the values from
143139
* @returns {Object} the key-value mapping
144140
*/
@@ -154,7 +150,7 @@ const preview = {
154150
value = value.replace(/[Ff]{2}$/, "");
155151
}
156152
}
157-
obj[next.id] = value;
153+
obj[next.name] = value;
158154
return obj;
159155
}, {});
160156
},
@@ -177,7 +173,7 @@ const preview = {
177173
.join("\n");
178174
const output = `[\n${mappings}\n]`;
179175
// set the textarea value to the output
180-
const textarea = document.getElementById("exportedPhp");
176+
const textarea = document.getElementById("exported-php");
181177
textarea.value = output;
182178
textarea.hidden = false;
183179
},
@@ -190,7 +186,7 @@ const preview = {
190186
checkColor(color, input) {
191187
if (color.length === 9 && color.slice(-2) === "FF") {
192188
// if color has hex alpha value -> remove it
193-
document.getElementById(input).value = color.slice(0, -2);
189+
document.querySelector(`[name="${input}"]`).value = color.slice(0, -2);
194190
}
195191
},
196192

@@ -251,7 +247,7 @@ window.addEventListener(
251247
});
252248
// set input boxes to match URL parameters
253249
new URLSearchParams(window.___location.search).forEach((val, key) => {
254-
const paramInput = document.querySelector(`#${key}`);
250+
const paramInput = document.querySelector(`[name="${key}"]`);
255251
if (paramInput) {
256252
// set parameter value
257253
paramInput.value = val;

0 commit comments

Comments
 (0)