Skip to content

Commit

Permalink
[doc] Fix error in site.js and make it satisfy lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
rumkin committed Jul 22, 2020
1 parent 5886bc5 commit 9548006
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions example/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,49 @@ pill('#page', {

indicator.style.display = 'block'
},
onUnmounting(page, url, element){
PreserveFormPlugin(element);
onUnmounting(page, url, element) {
PreserveFormPlugin(element)
},
onReady(page, element) {
// Delay to simulate long content loading
timeout = setTimeout(() => {
indicator.style.display = 'none'
}, 1000)
PopulateFormPlugin(element);
PopulateFormPlugin(element)
},
onMounting(){
onMounting() {
console.log('updating content')
}
})

const PopulateFormPlugin = element =>{
const key = location.pathname;
const fields = Array.from(element.querySelectorAll('input, textarea, select'));
if(fields.length > 0){
const obj = JSON.parse(localStorage.getItem(key));
obj.forEach(field=>{
const input = document.querySelector('[name='+field.fieldName+']');
if(input.type == 'checkbox' || input.type=='radio'){
const fields = Array.from(element.querySelectorAll('input, textarea, select'))
if (fields.length > 0) {
const obj = JSON.parse(localStorage.getItem(key) || '[]')
obj.forEach((field) => {
const input = document.querySelector('[name=' + field.fieldName + ']')
if (input.type === 'checkbox' || input.type === 'radio') {
input.checked = field.value
} else if (input.nodeName == 'TEXTAREA'){
} else if (input.nodeName === 'TEXTAREA') {
input.textContent = field.value
} else {
input.value = field.value
}
});
})
}
}

const PreserveFormPlugin = (element) =>{
const key = location.pathname;
const fields = Array.from(element.querySelectorAll('input, textarea, select'));
if(fields.length > 0){
const values = fields.map(val=>{
const key = location.pathname
const fields = Array.from(element.querySelectorAll('input, textarea, select'))
if (fields.length > 0) {
const values = fields.map((val) => {
return {
fieldName: val.name,
value: val.type == 'checkbox' || val.type == 'radio'? val.checked : val.value
value: val.type == 'checkbox' || val.type == 'radio' ? val.checked : val.value
}
});
localStorage.setItem(key, JSON.stringify(values));
})
localStorage.setItem(key, JSON.stringify(values))
}
}
}

0 comments on commit 9548006

Please sign in to comment.