Skip to content

Commit

Permalink
demo.js: inlined keyup and keydown event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ngn committed Oct 22, 2015
1 parent aeb5356 commit c61d032
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ function keyInfo(e){ // returns a pair of the key name and an "is complete" flag
var c=!!e.which&&k!=='Shift'&&k!=='Ctrl'&&k!=='Alt' // c: is the key combination complete?
c&&(s+=k);return[s,c]
}
function keyDownHandler(e){var s=keyInfo(e)[0];$p.text(s).toggle(!!s)}
function keyUpHandler(e){
var h=keyInfo(e),s=h[0],c=h[1]
if(c){$p.hide();var $k=$('<span>').text(s).insertBefore($p);setTimeout(function(){$k.fadeOut(1000)},2000)}
else{$p.text(s).toggle(!!s)}
}
$.extend(CodeMirror.commands,{
DMN:function(){move( 1)}, // next line
DMP:function(){move(-1)}, // prev line
Expand All @@ -37,7 +31,13 @@ $.extend(CodeMirror.commands,{
DMK:function(){ // toggle key display mode
if(!$p){
$('body').append($('<div id=demo-keys>').append($p=$('<span>').hide()))
$(document).on('keyup.demo',keyUpHandler).on('keydown.demo',keyDownHandler)
$(document)
.on('keydown.demo',function(e){var s=keyInfo(e)[0];$p.text(s).toggle(!!s)})
.on('keyup.demo',function(e){
var h=keyInfo(e),s=h[0],c=h[1]
if(c){$p.hide();var $k=$('<span>').text(s).insertBefore($p);setTimeout(function(){$k.fadeOut(1000)},2000)}
else{$p.text(s).toggle(!!s)}
})
}else{
$(document).off('.demo');$('#demo-keys').remove();$p=null
}
Expand Down

0 comments on commit c61d032

Please sign in to comment.