Skip to content

Commit

Permalink
wip - 1st draft
Browse files Browse the repository at this point in the history
# TODO

- add specs for new feature
- what about a situation, where there are more items than screenspace, scrallable list is not really working when using arrow down/up, AND the input leaves the viewport
  • Loading branch information
janraasch committed Mar 17, 2019
1 parent 12a4c67 commit 3916a8a
Show file tree
Hide file tree
Showing 7 changed files with 1,577 additions and 1,630 deletions.
25 changes: 16 additions & 9 deletions app/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
<body>
<div class="container">
<div class="hero-unit">
<h2>Search for Tabs in</h2>
<ul class="nav nav-pills">
<li id="current">
<a href="#" title="current">Current Window</a>
</li>
<li id="all">
<a href="#" title="all">All Windows</a>
</li>
</ul>
<form>
<fieldset>
<legend>Tab Ahead Options</legend>
<label>Max Results</label>
<input type="number" value="10" min="1" id="max_results">

<label class="radio">
<input type="radio" name="query" id="current" value="current"/>
Search Tabs in Current Window
</label>
<label class="radio">
<input type="radio" name="query" id="all" value="all"/>
Search Tabs in All Windows
</label>
</fieldset>
</form>
<blockquote>
<p>A child of five could understand this. Send someone to fetch a child of five.</p>
<small>Groucho Marx</small>
Expand Down
39 changes: 29 additions & 10 deletions app/scripts/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ window.tabaheadOptions = (storage) ->
CURRENT: 'current'

PREF_QUERY = 'pref/query'

MAX_RESULTS_DEFAULT = 10

PREF_MAX_RESULTS = 'pref/max_results'
# Constants shared with popup.coffee <--

CLASSES =
Expand All @@ -14,37 +18,52 @@ window.tabaheadOptions = (storage) ->
ui =
all: document.getElementById 'all'
current: document.getElementById 'current'
max_results: document.getElementById 'max_results'
activateAll: ->
ui.current.classList.remove CLASSES.ACTIVE
ui.all.classList.add CLASSES.ACTIVE
ui.current.checked = false
ui.all.checked = true
activateCurrent: ->
ui.all.classList.remove CLASSES.ACTIVE
ui.current.classList.add CLASSES.ACTIVE
update: ->
ui.all.checked = false
ui.current.checked = true
setMaxResults: (value) ->
ui.max_results.value = value
updateQuery: ->
query = storage[PREF_QUERY]
switch query
when QUERY.ALL then ui.activateAll()
when QUERY.CURRENT then ui.activateCurrent()
else
# Something went wrong. Let's reset.
storage[PREF_QUERY] = QUERY.CURRENT
ui.update()
ui.updateQuery()
updateMaxResults: ->
max_results = storage[PREF_MAX_RESULTS]
ui.setMaxResults(max_results)

# Events
ui.all.addEventListener 'click', ->
storage[PREF_QUERY] = QUERY.ALL
ui.update()
ui.updateQuery()
false
ui.current.addEventListener 'click', ->
storage[PREF_QUERY] = QUERY.CURRENT
ui.update()
ui.updateQuery()
false
ui.max_results.addEventListener 'keyup', ->
if ui.max_results.value > 0
storage[PREF_MAX_RESULTS] = ui.max_results.value
else
storage[PREF_MAX_RESULTS] = MAX_RESULTS_DEFAULT
ui.updateMaxResults()
false

# Init default pref
# Init defaults
storage[PREF_QUERY] = QUERY.CURRENT unless storage[PREF_QUERY]
storage[PREF_MAX_RESULTS] = MAX_RESULTS_DEFAULT unless storage[PREF_MAX_RESULTS]

# Init UI state
ui.update()
ui.updateQuery()
ui.updateMaxResults()

# Go go go, unless we're unit testing this thing.
window.tabaheadOptions window.localStorage unless window.__karma__?
11 changes: 8 additions & 3 deletions app/scripts/popup.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
window.tabahead = ($, Fuse, chrome, setTimeout, storage) ->
# --> Constants shared with options.coffee
# --> Constants shared with `options.coffee`
QUERY =
ALL: 'all'
CURRENT: 'current'

PREF_QUERY = 'pref/query'
# Constants shared with options.coffee <--

MAX_RESULTS_DEFAULT = 10

PREF_MAX_RESULTS = 'pref/max_results'
# Constants shared with `options.coffee` <--

string_separator = ':::::'

Expand Down Expand Up @@ -99,12 +103,13 @@ window.tabahead = ($, Fuse, chrome, setTimeout, storage) ->
return

# Init typeahead.
items = if storage[PREF_MAX_RESULTS] > 0 then storage[PREF_MAX_RESULTS] else MAX_RESULTS_DEFAULT
($ '#typeahead').typeahead(
source: source
matcher: matcher
sorter: sorter
highlighter: highlighter
items: 10
items: items
).focus()

# Do not submit form,
Expand Down
Loading

0 comments on commit 3916a8a

Please sign in to comment.