Skip to content

Commit

Permalink
Ugh, *now* correctly handle hash changes and such on the generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Nov 6, 2018
1 parent c1b9e1a commit a4751ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 11 additions & 4 deletions generator-no-module.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@

find('.input').addEventListener('input', e=>process(e.target.value), false);
document.addEventListener('DOMContentLoaded', initialProcess, false);
window.addEventListener('hashchange', initialProcess, false);
window.addEventListener('hashchange', hashProcess, false);

function initialProcess() {
if(location.hash && location.hash.length > 1) {
const code = decodeURIComponent(location.hash.substr(1));
const input = find('.input');
if(code != input.value) {
input.textContent = code;
}
process();
}

function hashProcess() {
if(location.hash && location.hash.length > 1) {
const code = decodeURIComponent(location.hash.substr(1));
const input = find('.input');
if(input.value != code) {
input.textContent = code;
process(code);
}
} else {
process();
}
}

Expand Down
15 changes: 11 additions & 4 deletions generator.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@

find('.input').addEventListener('input', e=>process(e.target.value), false);
document.addEventListener('DOMContentLoaded', initialProcess, false);
window.addEventListener('hashchange', initialProcess, false);
window.addEventListener('hashchange', hashProcess, false);

function initialProcess() {
if(location.hash && location.hash.length > 1) {
const code = decodeURIComponent(location.hash.substr(1));
const input = find('.input');
if(code != input.value) {
input.textContent = code;
}
process();
}

function hashProcess() {
if(location.hash && location.hash.length > 1) {
const code = decodeURIComponent(location.hash.substr(1));
const input = find('.input');
if(input.value != code) {
input.textContent = code;
process(code);
}
} else {
process();
}
}

Expand Down

0 comments on commit a4751ef

Please sign in to comment.