Skip to content

Instantly share code, notes, and snippets.

@jhchabran
Created November 3, 2012 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhchabran/4006422 to your computer and use it in GitHub Desktop.
Save jhchabran/4006422 to your computer and use it in GitHub Desktop.
class Application
constructor: ->
# Inject our html into the view
@injectView()
# Install a listener for our input
@element().find('input').keyup (event)=>
@onInput(event)
# Spawn a view that handle results display
@tabListView = new TabListView @element().find('ul')
element: ->
# Return our base div
@element_ ||= $('#tabswitcher-overlay')
onInput: (event)->
# When something is entered is the input, filter tabs !
candidates = fuzzy(@tabs(), event.target.value)
# Update tabs that match
@tabListView.update candidates
# If enter
if event.keyCode == 13
# Go to that tab
@switchTab candidates[0].tab if candidates?
hide: ->
# ...
show: ->
# ...
switchTab: (tab)->
# We're switching tab, hide the UI before leaving
@hide()
# Send message to the background script
chrome.extension.sendRequest(message:"switchTab", target:tab)
hotKeyListener: (event)->
# Listen for ctrl-\
if event.keyCode
if event.ctrlKey && event.keyCode == 220 # Ctrl + \
# Send message to background script, ask for list of tabs
chrome.extension.sendRequest {message: "getTabs"},
(response)=>
@tabs_ = response.tabs
@show()
else if event.keyCode == 27 # ESC
@hide()
injectView: ->
# Inject our UI in the DOM
$('body').append ...
app = new Application()
# Attach our handler
window.addEventListener("keyup", (e)->
app.hotKeyListener(e), false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment