Skip to content

Commit

Permalink
Console keyboard shortcuts
Browse files Browse the repository at this point in the history
Cmd/Ctrl-Enter to run code
Escape to dismiss console
  • Loading branch information
willmoffat committed Feb 10, 2011
1 parent 6f21f8a commit 80adaa7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
18 changes: 13 additions & 5 deletions documentation/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<textarea id="repl_source" rows="100">alert "Hello CoffeeScript!"</textarea>
</div>
<div id="repl_results_wrap"><pre id="repl_results"></pre></div>
<div class="minibutton dark run">Run</div>
<div class="minibutton dark run" title="Ctrl-Enter">Run</div>
<br class="clear" />
</div>
</div>
Expand Down Expand Up @@ -1580,7 +1580,7 @@ Expressions
$('#repl_source').keyup -> compileSource()

# Eval the compiled js.
$('.minibutton.run').click ->
evalJS = ->
try
eval window.compiledJS
catch error then alert error
Expand All @@ -1596,6 +1596,8 @@ Expressions
closeMenus = ->
$('.navigation.active').removeClass 'active'

$('.minibutton.run').click -> evalJS()

# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
Expand All @@ -1607,9 +1609,15 @@ Expressions
$(this).addClass 'active'
false

$(document.body).click (e) ->
return false if $(e.target).hasClass('minibutton')
closeMenus()
# Dismiss console if Escape pressed or click falls outside console
# Trigger Run button on Ctrl-Enter
$(document.body)
.keydown (e) ->
closeMenus() if e.which == 27
evalJS() if e.which == 13 and (e.metaKey or e.ctrlKey) and $('.minibutton.run:visible').length
.click (e) ->
return false if $(e.target).hasClass('minibutton')
closeMenus()

$('#open_webchat').click ->
$(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
Expand Down
18 changes: 13 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<textarea id="repl_source" rows="100">alert "Hello CoffeeScript!"</textarea>
</div>
<div id="repl_results_wrap"><pre id="repl_results"></pre></div>
<div class="minibutton dark run">Run</div>
<div class="minibutton dark run" title="Ctrl-Enter">Run</div>
<br class="clear" />
</div>
</div>
Expand Down Expand Up @@ -2484,7 +2484,7 @@ <h2>
$('#repl_source').keyup -> compileSource()

# Eval the compiled js.
$('.minibutton.run').click ->
evalJS = ->
try
eval window.compiledJS
catch error then alert error
Expand All @@ -2500,6 +2500,8 @@ <h2>
closeMenus = ->
$('.navigation.active').removeClass 'active'

$('.minibutton.run').click -> evalJS()

# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
Expand All @@ -2511,9 +2513,15 @@ <h2>
$(this).addClass 'active'
false

$(document.body).click (e) ->
return false if $(e.target).hasClass('minibutton')
closeMenus()
# Dismiss console if Escape pressed or click falls outside console
# Trigger Run button on Ctrl-Enter
$(document.body)
.keydown (e) ->
closeMenus() if e.which == 27
evalJS() if e.which == 13 and (e.metaKey or e.ctrlKey) and $('.minibutton.run:visible').length
.click (e) ->
return false if $(e.target).hasClass('minibutton')
closeMenus()

$('#open_webchat').click ->
$(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
Expand Down

0 comments on commit 80adaa7

Please sign in to comment.