2017-09-14 1 views
1

Apparemment, aucun événement keydown n'est associé au papier jointjs. Comment pouvons-nous capturer un tel événement?Comment capturer un événement keydown sur un papier joint?

Solutions que j'essayées:

Solution 1: Capture keydown sur l'élément div (qui contient du papier). Ça n'a pas marché.

$('#myholder).on('keydown', (e) => { 
    console.log(e.which); 
}); 

Solution 2: Cela semble un peu difficile.

$(document).on('keydown', (e) => { 
if(the previous event fired in 'blank:pointerdown' on paper and no other event is fired after that [which is equivalent to keydown on paper]) { 
    console.log(e.which); 
} 

});

Répondre

2

réponse à cette question fait l'affaire How to grab keyboard events on an element which doesn't accept focus?

$('#paper') 
    .attr('tabindex', 0) 
    .on('mouseover', function() { 
     this.focus(); 
    }) 
    .on('keydown', function(e) { 
     console.log(e.which); 
    }); 

également dans les RappidJS (bases cadres sur le JointJS) il y a le plugin ui.Keyboard qui rend le clavier une manipulation plus aisée http://resources.jointjs.com/docs/rappid/v2.1/ui.html#ui.Keyboard

+0

Merci beaucoup, @Vermont. Il a fait l'affaire. – Sid