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;
});
});
+ // copy first paragraph to story
+ let wptext = json.parse.text['*'];
+ let storyinput = document.getElementById('story');
+ if (storyinput && wptext) {
+ storyinput.innerHTML = wptext
+ .replace(/<h2.*/s, '') // prefix
+ .replace(/<table.*?<\/table>/sg, '') // ignore infobox
+ .match(/<p>(.*?)<\/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(/<img\s[^>]+>/g);
+ let wpimages = wptext.match(/<img\s[^>]+>/g);
let wpselect = wpinput.parentNode.appendChild(document.createElement('ul'));
wpselect.className = 'popup';
wpimages.forEach(img => {
};
}
+ 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 => {