From 68900ba8097a3ad797e883262b431cb7ab3fb188 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 3 Apr 2018 11:07:56 -0500 Subject: [PATCH 1/3] fix spaces --- docs/demo/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/demo/index.html b/docs/demo/index.html index 0f20731b..39166248 100644 --- a/docs/demo/index.html +++ b/docs/demo/index.html @@ -31,11 +31,11 @@
+ + + + +
From f9cef1f0d76cd37602f18e1792e6e32ecda81848 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 3 Apr 2018 11:21:25 -0500 Subject: [PATCH 2/3] add outputType param --- docs/demo/demo.js | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/demo/demo.js b/docs/demo/demo.js index 6042f7b3..ada958e8 100644 --- a/docs/demo/demo.js +++ b/docs/demo/demo.js @@ -18,10 +18,10 @@ var $panes = document.querySelectorAll('.pane'); var inputDirty = true; var $activeElem = null; var changeTimeout = null; +var search = searchToObject(); -var match = location.search.match(/[?&]text=([^&]*)$/); -if (match) { - $inputElem.value = decodeURIComponent(match[1]); +if (search.text) { + $inputElem.value = search.text; } else { fetch('./initial.md') .then(function (res) { return res.text(); }) @@ -36,6 +36,10 @@ if (match) { }); } +if (search.outputType) { + $outputTypeElem.value = search.outputType; +} + fetch('./quickref.md') .then(function (res) { return res.text(); }) .then(function (text) { @@ -48,6 +52,8 @@ function handleChange() { } $activeElem = document.querySelector('#' + $outputTypeElem.value); $activeElem.style.display = 'block'; + + updateLink(); }; $outputTypeElem.addEventListener('change', handleChange, false); @@ -67,6 +73,24 @@ $clearElem.addEventListener('click', function () { handleInput(); }, 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) { var output = (input + '') .replace(/\n/g, '\\n') @@ -96,13 +120,22 @@ function setScrollPercent(percent) { $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; function checkForChanges() { if (inputDirty) { inputDirty = false; - $permalinkElem.href = '?text=' + encodeURIComponent($inputElem.value); - history.replaceState('', document.title, $permalinkElem.href); + updateLink(); var startTime = new Date(); From f66196ae5f3b60a45ed82f89a8d3368d251b328e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 3 Apr 2018 11:39:08 -0500 Subject: [PATCH 3/3] fix when text is blank --- docs/demo/demo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/demo/demo.js b/docs/demo/demo.js index ada958e8..8db8e714 100644 --- a/docs/demo/demo.js +++ b/docs/demo/demo.js @@ -20,7 +20,7 @@ var $activeElem = null; var changeTimeout = null; var search = searchToObject(); -if (search.text) { +if ('text' in search) { $inputElem.value = search.text; } else { fetch('./initial.md')