diff --git a/src/web/Manager.mjs b/src/web/Manager.mjs index 9d5ab6be..562a13fb 100755 --- a/src/web/Manager.mjs +++ b/src/web/Manager.mjs @@ -148,6 +148,7 @@ class Manager { document.getElementById("edit-favourites").addEventListener("click", this.ops.editFavouritesClick.bind(this.ops)); document.getElementById("save-favourites").addEventListener("click", this.ops.saveFavouritesClick.bind(this.ops)); document.getElementById("categories").addEventListener("keydown", this.ops.onKeyPress.bind(this.ops)); + this.addDynamicListener(".op-list li.operation","keydown", this.ops.ddlEnter.bind(this.ops)); document.getElementById("reset-favourites").addEventListener("click", this.ops.resetFavouritesClick.bind(this.ops)); this.addDynamicListener(".op-list", "oplistcreate", this.ops.opListCreate, this.ops); this.addDynamicListener("li.operation", "operationadd", this.recipe.opAdd, this.recipe); diff --git a/src/web/waiters/OperationsWaiter.mjs b/src/web/waiters/OperationsWaiter.mjs index 7e56dbfb..2d119045 100755 --- a/src/web/waiters/OperationsWaiter.mjs +++ b/src/web/waiters/OperationsWaiter.mjs @@ -302,53 +302,37 @@ class OperationsWaiter { EventHandler(ev){ if(ev.key === "Enter" || ev.key === "Space" || ev.key === " " ){ ev.preventDefault(); - console.log("Enter Pressed"); - const el = ev.target.childNodes[3].classList; - console.log(el); - if(!el.contains("show")){ - const add = ev.target.childNodes[3].classList.add("show"); - console.log("add" , add); - return add; + ev.target.childNodes[3].classList.add("show"); }else if(el.contains("show")){ - const remove = ev.target.childNodes[3].classList.remove("show"); - console.log("remove" , remove); - return remove; + ev.target.childNodes[3].classList.remove("show"); } } }; - // /** - // * Handler for to hide panels with Enter/Space events. - // * When "Enter" or "Space" if pressed it will mimick the click function and close the operations panels . - // * @param {Event} ev - // * @param {Element} ele - // */ - // closeEventHandler(ev, ele){ - // if(ev.key === "Enter" || ev.key === "Space" || ev.key === " " ){ - // ev.preventDefault(); - // console.log("Enter Pressed"); - // if(ele.contains(ev.target) && ev.timeStamp !== instantiatingEvent.timeStamp){ - // hidePanelOperation(ele); - // } - // const cl = ev.target.childNodes[3].classList.remove("show"); - // console.log(cl); - // } - // } - - // /** - // * Hides the panels and remove the keydown listener from it. - // * @param {Element} ele - // */ - // hidePanelOperation(ele){ - // ele.classList.remove("show"); - // document.removeEventListener("keydown", this.closeEventHandler, false) - // } + operationDblEnter(){ + let cat = document.querySelectorAll(".op-list li.operation"); + console.log("cat=" , cat); + for(let i = 0; i < cat.children.length; i++){ + cat.children[i].addEventListener("keydown", this.ddlEnter, false); + }; + } + /** + * Handler to add operators to recipe with keyboard. + * @param {Event} ev + */ + ddlEnter(ev){ + if(ev.ctrlKey && ev.key ==="Enter"){ + const li = ev.target + this.manager.recipe.addOperation(li.textContent); + } + } + /** * Handler for reset favourites click events. * Resets favourites to their defaults.