X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/c4ded4553b22504dde319c4e222b98b4c9a13208..5e4c37b26db8009a1104b7784fe4520d228aa7ff:/writer.js diff --git a/writer.js b/writer.js index ebace02..5d3ad5e 100644 --- a/writer.js +++ b/writer.js @@ -2,6 +2,7 @@ document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('.multiinput > input[id]').forEach(el => { el.oninput = e => { if (e.target.value == '') return; + // insert another empty input element option let add = e.target.cloneNode(true); add.value = ''; add.oninput = e.target.oninput; @@ -36,10 +37,21 @@ document.addEventListener('DOMContentLoaded', () => { }); }); + // copy first paragraph to story + let wptext = json.parse.text['*']; + let storyinput = document.getElementById('story'); + if (storyinput && wptext) { + storyinput.innerHTML = wptext + .replace(//sg, '') // ignore infobox + .match(/

(.*?)<\/p>/s)[0] // first paragraph + .replace(/<[^>]*>/g, '') // strip html tags + } + // list images in article html let imginput = document.getElementById('source'); if (!imginput || imginput.value) return; - let wpimages = json.parse.text['*'].match(/]+>/g); + let wpimages = wptext.match(/]+>/g); let wpselect = wpinput.parentNode.appendChild(document.createElement('ul')); wpselect.className = 'popup'; wpimages.forEach(img => { @@ -84,6 +96,29 @@ document.addEventListener('DOMContentLoaded', () => { }; } + let thumbpreview = document.getElementById('thumbpreview'); + if (thumbpreview && imgpreview) { + thumbpreview.onclick = e => { + let imgselect = imgpreview; /* TODO clone */ + imgselect.hidden = false; + imgselect.classList.add('popup'); + imgselect.onmousemove = e => { + let border = imgselect.getBoundingClientRect(); + let pos = [ + Math.round(1000 * (e.clientX - border.x) / border.width), + Math.round(1000 * (e.clientY - border.y) / border.height) + ]; + return pos; + }; + imgselect.onclick = e => { + let imgoption = document.getElementById('thumb'); + imgoption.value += (imgoption.value && '-') + imgselect.onmousemove(e); + imgselect.hidden = true; + imgselect.classList.remove('popup'); + }; + }; + } + let translist = document.getElementById('trans'); if (translist) { let langoptions = Array.prototype.filter.call(document.getElementById('lang').options, opt => {