@@ -145,12 +145,17 @@ function setStateProps(index, state) {
145145 console . log ( index ) ;
146146
147147 state . props . attribution = [ ] ;
148+ setStatePropsAttribution ( state ) ;
149+ }
150+
151+ // isolated function to just set the attribution
152+ // subset of state.props (for use other places)
153+ function setStatePropsAttribution ( state ) {
148154 state . props . attribution . title = document . querySelector ( '#attribution-details #title' ) . value ;
149155 state . props . attribution . creator = document . querySelector ( '#attribution-details #creator' ) . value ;
150156 state . props . attribution . workLink = document . querySelector ( '#attribution-details #work-link' ) . value ;
151157 state . props . attribution . creatorLink = document . querySelector ( '#attribution-details #creator-link' ) . value ;
152158 state . props . attribution . workCreationYear = document . querySelector ( '#attribution-details #work-creation-year' ) . value ;
153-
154159}
155160
156161// function to reset values beyond current fieldset
@@ -206,6 +211,24 @@ function renderLicenseRec(state) {
206211 }
207212}
208213
214+ // render specifically the mark formats subsections
215+ function renderMarkingFormats ( state ) {
216+
217+
218+ if ( state . props . license != 'unknown' ) { }
219+
220+ setStatePropsAttribution ( state ) ;
221+
222+ let title = state . props . attribution . title ;
223+ let workCreationYear = state . props . attribution . workCreationYear ;
224+
225+ let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ' ;
226+
227+ document . querySelector ( '#mark-your-work .plain-text.mark' ) . textContent = phrase + state . props . license ;
228+ }
229+
230+
231+
209232// function to render "mark your work",
210233// if valid license from state.parts and/or state.current
211234// if attribution details input(s) filled out
@@ -216,17 +239,18 @@ function renderMarkYourWork(state) {
216239 document . querySelector ( '#mark-your-work' ) . classList . remove ( 'disable' ) ;
217240
218241 //state.props.attribution.title
219- let title = state . props . attribution . title ;
220- let workCreationYear = state . props . attribution . workCreationYear ;
242+ // let title = state.props.attribution.title;
243+ // let workCreationYear = state.props.attribution.workCreationYear;
221244
222- let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ' ;
245+ // let phrase = '(c) ' + workCreationYear + ' ' + title + ' is licensed under ';
223246
224- document . querySelector ( '#mark-your-work .mark-holder' ) . textContent = phrase + state . props . license ;
247+ // document.querySelector('#mark-your-work .mark-holder').textContent = phrase + state.props.license;
248+ renderMarkingFormats ( state ) ;
225249
226250 }
227251
228252 else if ( state . props . license == 'unknown' ) {
229- // set to empty
253+ document . querySelector ( '#mark-your-work' ) . classList . add ( 'disable' ) ;
230254 }
231255
232256}
@@ -351,6 +375,22 @@ function watchFieldsets(fieldsets, state) {
351375 renderLicenseRec ( state ) ;
352376
353377 renderMarkYourWork ( state ) ;
378+
379+ } ) ;
380+
381+ } ) ;
382+ }
383+
384+ function watchAttributionDetails ( fieldsets , state ) {
385+
386+ let textFields = fieldsets [ 8 ] . querySelectorAll ( 'input' ) ;
387+
388+ textFields . forEach ( ( element , index ) => {
389+
390+ element . addEventListener ( "keyup" , ( event ) => {
391+ console . log ( 'typing is happening' ) ;
392+
393+ renderMarkingFormats ( state ) ;
354394 } ) ;
355395
356396 } ) ;
@@ -368,4 +408,8 @@ console.log(state.possibilities);
368408setDefaults ( applyDefaults ) ;
369409console . log ( "initial defaults applied" ) ;
370410
411+ setStateProps ( 0 , state ) ;
412+ console . log ( "initial defaults applied" ) ;
413+
371414watchFieldsets ( fieldsets , state ) ;
415+ watchAttributionDetails ( fieldsets , state ) ;
0 commit comments