File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,7 @@ function gtag() {
149
149
<button class="plus btn" type="button" onclick="return preview.addProperty()">+</button>
150
150
</div>
151
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>
152
153
<textarea id="exportedPhp" hidden></textarea>
153
154
</details>
154
155
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ const preview = {
37
37
// disable copy button if username is invalid
38
38
const copyButton = document . querySelector ( ".copy-button" ) ;
39
39
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 ;
40
43
} ,
41
44
42
45
/**
@@ -120,6 +123,20 @@ const preview = {
120
123
return false ;
121
124
} ,
122
125
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
+
123
140
/**
124
141
* Create a key-value mapping of ids to values from all elements in a Node list
125
142
* @param {NodeList } elements - the elements to get the values from
You can’t perform that action at this time.
0 commit comments