Created
November 3, 2012 07:33
-
-
Save jhchabran/4006422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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