Skip to content

Commit 793afe0

Browse files
feat: Clear advanced props button (DenverCoder1#438)
Co-authored-by: Jonah Lawrence <[email protected]> Fixes DenverCoder1#433
1 parent b2acf2c commit 793afe0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/demo/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ function gtag() {
149149
<button class="plus btn" type="button" onclick="return preview.addProperty()">+</button>
150150
</div>
151151
<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>
152153
<textarea id="exportedPhp" hidden></textarea>
153154
</details>
154155

src/demo/js/script.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const preview = {
3737
// disable copy button if username is invalid
3838
const copyButton = document.querySelector(".copy-button");
3939
copyButton.disabled = Boolean(document.querySelector("#user:invalid") || !document.querySelector("#user").value);
40+
// disable clear button if no added advanced options
41+
const clearButton = document.querySelector("#clear_button");
42+
clearButton.disabled = !document.querySelectorAll(".minus").length;
4043
},
4144

4245
/**
@@ -120,6 +123,20 @@ const preview = {
120123
return false;
121124
},
122125

126+
/**
127+
* Removes all properties from the advanced section
128+
*/
129+
removeAllProperties() {
130+
const parent = document.querySelector(".advanced .parameters");
131+
const activeProperties = parent.querySelectorAll("[data-property]");
132+
// select active and unique property names
133+
const propertyNames = Array.prototype.map
134+
.call(activeProperties, (prop) => prop.getAttribute("data-property"))
135+
.filter((value, index, self) => self.indexOf(value) === index);
136+
// remove each active property name
137+
propertyNames.forEach((prop) => this.removeProperty(prop));
138+
},
139+
123140
/**
124141
* Create a key-value mapping of ids to values from all elements in a Node list
125142
* @param {NodeList} elements - the elements to get the values from

0 commit comments

Comments
 (0)