1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
window.VT=window.VT||{},VT.TodoCustomList=function(a){function b(){a.dispatchEvent(new CustomEvent("saveList",{detail:{list:f.list,title:j.value.trim()},bubbles:!0})),d({editing:!1})}function c(){h=!1,d({editing:!1})}function d(b){Object.assign(f,b),i.innerText=f.list.title||"...",a.querySelector(".todo-list").todoList.update({items:f.list.items}),a.querySelector(".todo-list > .todo-item-input").dataset.key="todo-item-input"+f.list.id,a.classList.toggle("-editing",f.editing),f.editing&&g&&(j.value=f.list.title,j.focus(),j.select(),g=!1)}var f={list:null,editing:!1},g=!1,h=!0;a.innerHTML="<div class=\"header\">\n <h3 class=\"title\"></h3>\n <p class=\"form\">\n <input type=\"text\" class=\"input use-focus-other\">\n <button class=\"app-button delete\"><i class=\"app-icon\" data-id=\"trashcan-16\"></i></button>\n </p>\n</div>\n<div class=\"todo-list\"></div>";var i=a.querySelector(".title"),j=a.querySelector(".input"),k=a.querySelector(".delete");VT.AppDraggable(i,{dropSelector:".todo-frame.-custom .container"}),VT.TodoList(a.querySelector(".todo-list")),a.querySelectorAll(".app-icon").forEach(VT.AppIcon),i.addEventListener("click",function(){g=!0,d({editing:!0})}),k.addEventListener("touchstart",function(){h=!1}),k.addEventListener("mousedown",function(){h=!1}),j.addEventListener("blur",function(){h&&b(),h=!0}),j.addEventListener("focusOther",function(){f.editing&&b()}),j.addEventListener("keyup",function(a){switch(a.keyCode){case 13:b();break;case 27:c();}}),k.addEventListener("click",function(){0<f.list.items.length&&!confirm("Deleting this list will delete its items as well. Are you sure?")||a.dispatchEvent(new CustomEvent("deleteList",{detail:f.list,bubbles:!0}))}),a.addEventListener("draggableStart",function(b){b.target!==i||(b.detail.data.list=f.list,b.detail.data.key=f.list.id,b.detail.setImage(a),b.detail.image.addEventListener("draggableDrag",function(a){var b=a.detail.clientX-a.detail.imageX,c=a.detail.originY-a.detail.imageY;a.detail.image.style.transform="translate("+b+"px, "+c+"px)"}))}),a.addEventListener("addItem",function(a){a.detail.listId=f.list.id}),a.addEventListener("moveItem",function(a){a.detail.listId=f.list.id,a.detail.index=a.detail.index||0}),a.todoCustomList={update:d}}; |