Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More persistent test page #1529

Merged
merged 4 commits into from
Mar 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ <h2>Test drive</h2>
languages = components.languages,
highlightCode = function() { Prism.highlightElement(code); };


function updateHashLanguage(lang) {
location.hash = lang ? 'language=' + lang : '';
}
function getHashLanguage() {
var match = /[#&]language=([^&]+)/.exec(location.hash);
return match ? match[1] : null;
}
function getRadio(lang) {
return $('input[name=language][value="' + lang + '"]');
}

window.onhashchange = function () {
var input = getRadio(getHashLanguage());

if (input && !input.checked) {
input.checked = true;
input.onclick();
}
}


for (var id in languages) {
if (id == 'meta') {
continue;
Expand All @@ -160,6 +182,7 @@ <h2>Test drive</h2>
var lang = this.value;
code.className = 'language-' + lang;
code.textContent = code.textContent;
updateHashLanguage(lang);

// loadLanguage() returns a promise, so we use highlightCode()
// as resolve callback. The promise will be immediately
Expand Down Expand Up @@ -228,15 +251,39 @@ <h2>Test drive</h2>


var radios = $$('input[name=language]');
radios[0].checked = true;
radios[0].onclick();
var selectedRadio = radios[0];

var lastLanguageRadio = getRadio(getHashLanguage());
if (lastLanguageRadio) {
selectedRadio = lastLanguageRadio;
}

selectedRadio.checked = true;
selectedRadio.onclick();

var textarea = $('textarea', form);

(textarea.oninput = function() {
code.textContent = this.value || '';
try {
var lastCode = sessionStorage.getItem('test-code');
if (lastCode) {
textarea.value = lastCode;
}
} catch (e) {
// ignore sessionStorage errors
}

textarea.oninput = function() {
var codeText = this.value || '';
code.textContent = codeText;
highlightCode();
}).call(textarea);

try {
sessionStorage.setItem('test-code', codeText);
} catch (error) {
// ignore sessionStorage errors
}
}
textarea.oninput();

$('#option-show-tokens').onchange = function () {
var cls = 'show-tokens';
Expand Down