@@ -287,13 +287,24 @@ export default async function ({ feature, console }) {
287287 input . type = "date" ;
288288 input . style . margin = "0 10px" ;
289289 if ( filterData . period [ id ] ) input . value = filterData . period [ id ] ;
290- const button = document . createElement ( "button" ) ;
291- button . textContent = feature . msg ( "reset" ) ;
292- button . addEventListener ( "click" , function ( ) {
290+ input . addEventListener ( "change" , function ( ) {
291+ if ( input . value ) {
292+ filterData [ "period" ] [ id ] = input . value ;
293+ button . classList . add ( 'active' ) ;
294+ }
295+ else if ( filterData . period [ id ] ) delete filterData . period [ id ] ;
296+ filter ( )
297+ } ) ;
298+ const resetButton = document . createElement ( "button" ) ;
299+ resetButton . textContent = feature . msg ( "reset" ) ;
300+ resetButton . addEventListener ( "click" , function ( ) {
293301 input . value = ''
302+ if ( filterData . period [ id ] ) delete filterData . period [ id ] ;
303+ filter ( )
304+ if ( Object . keys ( filterData [ "period" ] ) . length == 0 ) { if ( button . classList . contains ( 'active' ) ) button . classList . remove ( 'active' ) }
294305 } ) ;
295306 content . appendChild ( input ) ;
296- content . appendChild ( button ) ;
307+ content . appendChild ( resetButton ) ;
297308 return content ;
298309 }
299310
@@ -310,11 +321,7 @@ export default async function ({ feature, console }) {
310321 updateDetails . appendChild ( updateStart ) ;
311322 updateDetails . appendChild ( updateEnd ) ;
312323
313- const saveButton = document . createElement ( "button" ) ;
314- saveButton . textContent = feature . msg ( "save" ) ;
315- saveButton . style . marginRight = "100%" ;
316-
317- let modal = ScratchTools . modals . create ( {
324+ ScratchTools . modals . create ( {
318325 title : `${ feature . msg ( "period" ) } ` ,
319326 components : [
320327 {
@@ -324,29 +331,9 @@ export default async function ({ feature, console }) {
324331 {
325332 type : "html" ,
326333 content : updateDetails ,
327- } ,
328- {
329- type : "html" ,
330- content : saveButton ,
331334 }
332335 ]
333336 } ) ;
334- saveButton . addEventListener ( "click" , function ( ) {
335- function checkInput ( id , element ) {
336- const input = element . querySelector ( "input" ) ;
337- if ( input . value ) filterData [ "period" ] [ id ] = input . value ;
338- else if ( filterData . period [ id ] ) delete filterData . period [ id ] ;
339- }
340- checkInput ( "shareStart" , shareStart ) ;
341- checkInput ( "shareEnd" , shareEnd ) ;
342- checkInput ( "updateStart" , updateStart ) ;
343- checkInput ( "updateEnd" , updateEnd ) ;
344- modal . close ( ) ;
345-
346- filter ( )
347- if ( Object . keys ( filterData [ id ] ) . length == 0 ) { if ( button . classList . contains ( 'active' ) ) button . classList . remove ( 'active' ) }
348- else button . classList . add ( 'active' ) ;
349- } )
350337 break ;
351338 }
352339
@@ -361,7 +348,7 @@ export default async function ({ feature, console }) {
361348 else filterButton . classList . add ( 'active' ) ;
362349 const filterSettings = document . createElement ( "div" ) ;
363350 filterSettings . classList . add ( 'ste-filter-settings' ) ;
364- options . map ( ( option ) => {
351+ options . forEach ( option => {
365352 const icon = document . createElement ( "img" ) ;
366353 icon . src = feature . self . getResource ( option . icon ) ;
367354
0 commit comments