jquery.flowchart icon indicating copy to clipboard operation
jquery.flowchart copied to clipboard

Keypress events

Open jonesr91 opened this issue 8 years ago • 1 comments

Hi there, Is there any way for me to bind to a keypress event on a link? I want to be able to delete a link by selecting it, then hitting the delete key. As of yet, I've not seen a way I can achieve this.

Any help is appreciated, Ryan

jonesr91 avatar Aug 30 '17 09:08 jonesr91

Ryan, I solved this by binding an event to a "keyListener" when a link is selected and when the delete key is pressed deleting the link and turning off the "keyListener". You will need to bind the flowchart "onLinkSelect" and "onLinkUnselect" to these methods. Code:

function linkSelected(linkID) { keyListener(true, linkKeyListener);

return true;

}

function linkUnSelected() { keyListener(false, linkKeyListener);

return true;

}

function linkKeyListener(event) { if (event.key.toLowerCase() == 'delete') { deleteSelectedLink(); } }

function keyListener(activate, callFunction) { if (activate == true) { document.addEventListener('keyup', callFunction); } else { document.removeEventListener('keyup', callFunction); } }

Rob-ModernAnalytics avatar Jan 11 '18 21:01 Rob-ModernAnalytics