From 5320d6506e6781a70682d9ba48ff77fc0087ddc3 Mon Sep 17 00:00:00 2001 From: Paul Rumkin Date: Fri, 24 Jul 2020 01:29:05 +0300 Subject: [PATCH 1/5] [util] Update .npmignore style --- .npmignore | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.npmignore b/.npmignore index cac9291..2914d6b 100644 --- a/.npmignore +++ b/.npmignore @@ -2,8 +2,8 @@ .eslintignore .editorconfig -bin/ -example/ -local/ -src/ -tmp/ +/bin/ +/example/ +/local/ +/src/ +/tmp/ From 5abd3fba9c4b6ea8fe15160599d6f61592dd83f8 Mon Sep 17 00:00:00 2001 From: Paul Rumkin Date: Fri, 24 Jul 2020 01:29:48 +0300 Subject: [PATCH 2/5] [util,doc] Update example code linting. Update eslintignore --- .eslintignore | 4 +++- example/site.js | 25 +++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.eslintignore b/.eslintignore index 66ec1e2..8858ba6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,5 @@ /dist/ /node_modules/ -/example/ + +/example/pill.js +/example/pill.min.js diff --git a/example/site.js b/example/site.js index 47a1e64..661981f 100644 --- a/example/site.js +++ b/example/site.js @@ -1,3 +1,5 @@ +/* globals pill */ +/* eslint-disable no-console */ const indicator = document.getElementById('indicator') let timeout = 0 @@ -12,22 +14,23 @@ pill('#page', { indicator.style.display = 'block' }, onUnmounting(page, url, element) { - PreserveFormPlugin(element) + preserveFormPlugin(element) }, - onReady(page, element) { + onReady(page, url, element) { // Delay to simulate long content loading timeout = setTimeout(() => { indicator.style.display = 'none' }, 1000) - PopulateFormPlugin(element) + populateFormPlugin(element) }, onMounting() { console.log('updating content') - } + }, + listenClickEventOn: '#page', }) -const PopulateFormPlugin = element =>{ - const key = location.pathname; +function 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) || '[]') @@ -35,23 +38,25 @@ const PopulateFormPlugin = element =>{ 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 { + } + else { input.value = field.value } }) } } -const PreserveFormPlugin = (element) =>{ +function preserveFormPlugin(element) { 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)) From 521ef4e74edc1b38ca7d1f2c381b5d682eacbfca Mon Sep 17 00:00:00 2001 From: Paul Rumkin Date: Sat, 8 Aug 2020 18:30:55 +0300 Subject: [PATCH 3/5] [src] Add x/y scrolling capturing --- src/pill.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pill.js b/src/pill.js index 7ebf5b1..a85a5c2 100644 --- a/src/pill.js +++ b/src/pill.js @@ -109,8 +109,9 @@ export default function pill(selector, options) { scrollToAnchor(url.hash.slice(1)) } } + // Initial scroll - updateState({scroll: window.scrollY}, currentUrl, currentPage.title, false) + updateState({scrollX: window.scrollX, scrollY: window.scrollY}, currentUrl, currentPage.title, false) function goto(url, push) { var cacheKey = keyFromUrl(url) @@ -191,7 +192,9 @@ export default function pill(selector, options) { function onPopState(e) { goto(new URL(document.location), false) requestAnimationFrame(function() { - window.scrollTo(0, e.state.scroll || 0) + var scrollY = e.state && e.state.scrollY || 0 + var scrollX = e.state && e.state.scrollX || 0 + window.scrollTo(scrollX, scrollY) }) } @@ -202,7 +205,7 @@ export default function pill(selector, options) { } scrollDebounceTimeout = setTimeout(function () { - updateState({scroll: window.scrollY}, document.location, document.title, false) + updateState({scrollX: window.scrollX, scrollY: window.scrollY}, document.location, document.title, false) scrollDebounceTimeout = null }, 100) } @@ -210,4 +213,4 @@ export default function pill(selector, options) { document.body.addEventListener('click', onClick) window.addEventListener('popstate', onPopState) window.addEventListener('scroll', onScroll) -} \ No newline at end of file +} From 60ed25a05c9f4ab4b1699d4dbc79d025d3191340 Mon Sep 17 00:00:00 2001 From: Paul Rumkin Date: Sat, 8 Aug 2020 18:33:22 +0300 Subject: [PATCH 4/5] [doc] Fix example code --- example/site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/site.js b/example/site.js index 661981f..97df93b 100644 --- a/example/site.js +++ b/example/site.js @@ -16,7 +16,7 @@ pill('#page', { onUnmounting(page, url, element) { preserveFormPlugin(element) }, - onReady(page, url, element) { + onReady(page, element) { // Delay to simulate long content loading timeout = setTimeout(() => { indicator.style.display = 'none' From 3b2a759a4dc12b7106731ba0692d2d0620dc136f Mon Sep 17 00:00:00 2001 From: Paul Rumkin Date: Sat, 8 Aug 2020 18:34:55 +0300 Subject: [PATCH 5/5] [v] 1.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ec058da..654dca8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pill", "description": "Pill dynamic content loading for static sites.", - "version": "1.4.0", + "version": "1.4.1", "main": "dist/node/pill.js", "devDependencies": { "@codegoods/eslint-config-base": "^1.0.2",