whisper.cat/weboasis/todo/scripts/TodoItemInput.min.js
2023-10-05 23:28:32 +11:00

1 line
775 B
JavaScript

window.VT=window.VT||{},VT.TodoItemInput=function(a){function b(){var b=e.value.trim();""===b||(e.value="",a.dispatchEvent(new CustomEvent("addItem",{detail:{label:b},bubbles:!0})))}function c(){e.value="",e.blur()}var d=!0;a.innerHTML="<input type=\"text\" class=\"input use-focus-other\">\n<button class=\"app-button save\"><i class=\"app-icon\" data-id=\"plus-24\"></i></button>";var e=a.querySelector(".input"),f=a.querySelector(".save");a.querySelectorAll(".app-icon").forEach(VT.AppIcon),e.addEventListener("keyup",function(a){switch(a.keyCode){case 13:b();break;case 27:c();}}),e.addEventListener("blur",function(){d&&b(),d=!0}),e.addEventListener("focusOther",b),f.addEventListener("mousedown",function(){d=!1}),f.addEventListener("click",function(){b(),e.focus()})};