Merge pull request #1196 from UziTech/demo-link-outputtype
Demo link outputtype
This commit is contained in:
commit
373fbd4313
@ -18,10 +18,10 @@ var $panes = document.querySelectorAll('.pane');
|
|||||||
var inputDirty = true;
|
var inputDirty = true;
|
||||||
var $activeElem = null;
|
var $activeElem = null;
|
||||||
var changeTimeout = null;
|
var changeTimeout = null;
|
||||||
|
var search = searchToObject();
|
||||||
|
|
||||||
var match = location.search.match(/[?&]text=([^&]*)$/);
|
if ('text' in search) {
|
||||||
if (match) {
|
$inputElem.value = search.text;
|
||||||
$inputElem.value = decodeURIComponent(match[1]);
|
|
||||||
} else {
|
} else {
|
||||||
fetch('./initial.md')
|
fetch('./initial.md')
|
||||||
.then(function (res) { return res.text(); })
|
.then(function (res) { return res.text(); })
|
||||||
@ -36,6 +36,10 @@ if (match) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (search.outputType) {
|
||||||
|
$outputTypeElem.value = search.outputType;
|
||||||
|
}
|
||||||
|
|
||||||
fetch('./quickref.md')
|
fetch('./quickref.md')
|
||||||
.then(function (res) { return res.text(); })
|
.then(function (res) { return res.text(); })
|
||||||
.then(function (text) {
|
.then(function (text) {
|
||||||
@ -48,6 +52,8 @@ function handleChange() {
|
|||||||
}
|
}
|
||||||
$activeElem = document.querySelector('#' + $outputTypeElem.value);
|
$activeElem = document.querySelector('#' + $outputTypeElem.value);
|
||||||
$activeElem.style.display = 'block';
|
$activeElem.style.display = 'block';
|
||||||
|
|
||||||
|
updateLink();
|
||||||
};
|
};
|
||||||
|
|
||||||
$outputTypeElem.addEventListener('change', handleChange, false);
|
$outputTypeElem.addEventListener('change', handleChange, false);
|
||||||
@ -67,6 +73,24 @@ $clearElem.addEventListener('click', function () {
|
|||||||
handleInput();
|
handleInput();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
function searchToObject() {
|
||||||
|
// modified from https://stackoverflow.com/a/7090123/806777
|
||||||
|
var pairs = location.search.slice(1).split('&');
|
||||||
|
var obj = {};
|
||||||
|
|
||||||
|
for (var i = 0; i < pairs.length; i++) {
|
||||||
|
if (pairs[i] === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pair = pairs[i].split('=');
|
||||||
|
|
||||||
|
obj[decodeURIComponent(pair.shift())] = decodeURIComponent(pair.join('='));
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
function jsonString(input) {
|
function jsonString(input) {
|
||||||
var output = (input + '')
|
var output = (input + '')
|
||||||
.replace(/\n/g, '\\n')
|
.replace(/\n/g, '\\n')
|
||||||
@ -96,13 +120,22 @@ function setScrollPercent(percent) {
|
|||||||
$activeElem.scrollTop = percent * getScrollSize();
|
$activeElem.scrollTop = percent * getScrollSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function updateLink() {
|
||||||
|
var outputType = '';
|
||||||
|
if ($outputTypeElem.value !== 'preview') {
|
||||||
|
outputType = 'outputType=' + $outputTypeElem.value + '&';
|
||||||
|
}
|
||||||
|
|
||||||
|
$permalinkElem.href = '?' + outputType + 'text=' + encodeURIComponent($inputElem.value);
|
||||||
|
history.replaceState('', document.title, $permalinkElem.href);
|
||||||
|
}
|
||||||
|
|
||||||
var delayTime = 1;
|
var delayTime = 1;
|
||||||
function checkForChanges() {
|
function checkForChanges() {
|
||||||
if (inputDirty) {
|
if (inputDirty) {
|
||||||
inputDirty = false;
|
inputDirty = false;
|
||||||
|
|
||||||
$permalinkElem.href = '?text=' + encodeURIComponent($inputElem.value);
|
updateLink();
|
||||||
history.replaceState('', document.title, $permalinkElem.href);
|
|
||||||
|
|
||||||
var startTime = new Date();
|
var startTime = new Date();
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="label">
|
<div class="label">
|
||||||
<select id="outputType">
|
<select id="outputType">
|
||||||
<option value="preview">Preview</option>
|
<option value="preview">Preview</option>
|
||||||
<option value="html">HTML Source</option>
|
<option value="html">HTML Source</option>
|
||||||
<option value="lexer">Lexer Data</option>
|
<option value="lexer">Lexer Data</option>
|
||||||
<option value="quickref">Quick Reference</option>
|
<option value="quickref">Quick Reference</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="preview" class="pane">
|
<div id="preview" class="pane">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user