From 4877c43451d30a0ae0e2d3eaae6b684304683581 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 11 Jun 2020 18:12:45 +0200 Subject: Add intermistic title edit functionality using double-click. --- src/ws/view.js | 58 ++++++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) (limited to 'src/ws/view.js') diff --git a/src/ws/view.js b/src/ws/view.js index 4a10386..b960170 100644 --- a/src/ws/view.js +++ b/src/ws/view.js @@ -200,52 +200,42 @@ function node_submit_KeyUpHandler(target, e) // Butt ugly.. but hey! it works... // var updateid; -var divtxt; -var oldtxt; -var oldtitle; -function onKeyUpHandler(target, e) +var lineedit; +var lineeditparent; +function onKeyUpHandler(e) { if(e.which == 13) { // enter - divtxt.removeChild(target); - oldtxt.nodeValue = 'updating...'; - update(updateid, "title", target.value); + lineeditparent.removeChild(lineedit); + lineeditparent.nodeValue = 'updating...'; + update(updateid, "title", lineedit.value); } if(e.which == 27) { // escape - divtxt.removeChild(target); - oldtxt.nodeValue = oldtitle; + lineeditparent.removeChild(lineedit); } } -function onLostFocusHandler(target, e) +function onLostFocusHandler(e) { - if(target.value == oldtitle) - { - divtxt.removeChild(target); - oldtxt.nodeValue = oldtitle; - } + lineeditparent.removeChild(lineedit); } -function editTitle(target, e) +function editTitle(e) { e.stopPropagation(); - updateid = idFromStr(target.id); - if(updateid < 10) - { - return; - } - var inp = document.createElement("input"); - var txtdiv = document.getElementById(target.id + "_txt"); - divtxt = txtdiv; - oldtxt = txtdiv.firstChild; - oldtitle = oldtxt.nodeValue; - oldtxt.nodeValue = ""; - inp.setAttribute("onkeyup", "onKeyUpHandler(this, event)"); - inp.setAttribute("onblur", "onLostFocusHandler(this, event)"); - inp.setAttribute("style", "border: inherit; padding: inherit; margin: inherit; background: inherit;"); - inp.value = oldtitle; - lineedit = inp; - txtdiv.appendChild(inp); - inp.focus(); + updateid = idFromStr(e.target.id); + subscriptionId = subscriptionIdFromStr(e.target.id); + + var node = findNode(updateid, subscriptionId); + + lineedit = document.createElement("input"); + lineedit.setAttribute("class", "edit"); + lineedit.setAttribute("onkeyup", "onKeyUpHandler(event)"); + lineedit.setAttribute("onblur", "onLostFocusHandler(event)"); + lineedit.value = node.getTitle(); + e.target.appendChild(lineedit); + //e.target.insertBefore(e.target.childNodes[2], lineedit); + lineeditparent = e.target; + lineedit.focus(); } -- cgit v1.2.3