Commit 548454a9 by Tom Giannattasio

drop down arrow key nav works with nested and filtered lists; scrolls menu to…

drop down arrow key nav works with nested and filtered lists; scrolls menu to show focused at all times
parent 00328189
...@@ -194,22 +194,23 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -194,22 +194,23 @@ class @DiscussionThreadListView extends Backbone.View
return return
event.preventDefault() event.preventDefault()
totalItems = $(".browse-topic-drop-menu-wrapper a").length itemHeight = $(".browse-topic-drop-menu a").outerHeight()
index = $(".browse-topic-drop-menu-wrapper .focused").parent().index() items = $.makeArray($(".browse-topic-drop-menu-wrapper a").not(".hidden"))
firstShownIndex = $($(".browse-topic-drop-menu-wrapper a").not('.hidden')[0]).parent().index() index = items.indexOf($('.browse-topic-drop-menu-wrapper .focused')[0])
if event.which == 40 if event.which == 40
index = index + 1 index = Math.min(index + 1, items.length - 1)
else if event.which == 38 if event.which == 38
index = index - 1 index = Math.max(index - 1, 0)
while $(".browse-topic-drop-menu-wrapper li").eq(index).find('a').hasClass('hidden')
index--;
if index == totalItems
index = 0
while $(".browse-topic-drop-menu-wrapper li").eq(index).find('a').hasClass('hidden')
index++;
$(".browse-topic-drop-menu-wrapper .focused").removeClass("focused") $(".browse-topic-drop-menu-wrapper .focused").removeClass("focused")
$(".browse-topic-drop-menu-wrapper li").eq(index).find('a').addClass("focused") $(items[index]).addClass("focused")
$(".browse-topic-drop-menu-wrapper").attr("data-focused", index)
scrollTarget = Math.min(index * itemHeight, $(".browse-topic-drop-menu").scrollTop())
scrollTarget = Math.max(index * itemHeight - $(".browse-topic-drop-menu").height() + itemHeight, scrollTarget)
$(".browse-topic-drop-menu").scrollTop(scrollTarget)
...@@ -30,15 +30,16 @@ class @NewPostView extends Backbone.View ...@@ -30,15 +30,16 @@ class @NewPostView extends Backbone.View
toggleTopicDropdown: (event) -> toggleTopicDropdown: (event) ->
event.stopPropagation() event.stopPropagation()
if @menuOpen if @menuOpen
@hideTopicDropdown() @hideTopicDropdown()
else else
@showTopicDropdown() @showTopicDropdown()
showTopicDropdown: () -> showTopicDropdown: () ->
@menuOpen = true @menuOpen = true
@dropdownButton.addClass('dropped') @dropdownButton.addClass('dropped')
@topicMenu.show() @topicMenu.show()
$('body').bind 'keydown', @setActiveItem
$('body').bind 'click', @hideTopicDropdown $('body').bind 'click', @hideTopicDropdown
# Set here because 1) the window might get resized and things could # Set here because 1) the window might get resized and things could
...@@ -51,6 +52,7 @@ class @NewPostView extends Backbone.View ...@@ -51,6 +52,7 @@ class @NewPostView extends Backbone.View
@dropdownButton.removeClass('dropped') @dropdownButton.removeClass('dropped')
@topicMenu.hide() @topicMenu.hide()
$('body').unbind 'keydown', @setActiveItem
$('body').unbind 'click', @hideTopicDropdown $('body').unbind 'click', @hideTopicDropdown
setTopic: (event) -> setTopic: (event) ->
...@@ -157,3 +159,30 @@ class @NewPostView extends Backbone.View ...@@ -157,3 +159,30 @@ class @NewPostView extends Backbone.View
#threadView = new ThreadView el: $thread[0], model: thread #threadView = new ThreadView el: $thread[0], model: thread
#thread.updateInfo response.annotated_content_info #thread.updateInfo response.annotated_content_info
#@cancelNewPost() #@cancelNewPost()
setActiveItem: (event) ->
if event.which == 13
$(".topic_menu_wrapper .focused").click()
return
if event.which != 40 && event.which != 38
return
event.preventDefault()
itemHeight = $(".topic_menu_wrapper a").outerHeight()
items = $.makeArray($(".topic_menu_wrapper a").not(".hidden"))
index = items.indexOf($('.topic_menu_wrapper .focused')[0])
if event.which == 40
index = Math.min(index + 1, items.length - 1)
if event.which == 38
index = Math.max(index - 1, 0)
$(".topic_menu_wrapper .focused").removeClass("focused")
$(items[index]).addClass("focused")
scrollTarget = Math.min(index * itemHeight, $(".topic_menu").scrollTop())
scrollTarget = Math.max(index * itemHeight - $(".topic_menu").height() + itemHeight, scrollTarget)
$(".topic_menu").scrollTop(scrollTarget)
...@@ -123,7 +123,7 @@ function filterDrop(e) { ...@@ -123,7 +123,7 @@ function filterDrop(e) {
* single query * single query
*/ */
var $drop = $(e.target).parents('.form-topic-drop-menu-wrapper, .browse-topic-drop-menu-wrapper'); var $drop = $(e.target).parents('.topic_menu_wrapper, .browse-topic-drop-menu-wrapper');
var query = $(this).val(); var query = $(this).val();
var $items = $drop.find('a'); var $items = $drop.find('a');
...@@ -134,7 +134,7 @@ function filterDrop(e) { ...@@ -134,7 +134,7 @@ function filterDrop(e) {
$items.addClass('hidden'); $items.addClass('hidden');
$items.each(function(i) { $items.each(function(i) {
var thisText = $(this).children().not('.unread').text(); var thisText = $(this).not('.unread').text();
$(this).parents('ul').siblings('a').not('.unread').each(function(i) { $(this).parents('ul').siblings('a').not('.unread').each(function(i) {
thisText = thisText + ' ' + $(this).text(); thisText = thisText + ' ' + $(this).text();
}); });
...@@ -150,10 +150,10 @@ function filterDrop(e) { ...@@ -150,10 +150,10 @@ function filterDrop(e) {
$(this).removeClass('hidden'); $(this).removeClass('hidden');
// show children // show children
$(this).parent().find('a').show(); $(this).parent().find('a').removeClass('hidden');
// show parents // show parents
$(this).parents('ul').siblings('a').show(); $(this).parents('ul').siblings('a').removeClass('hidden');
} }
}); });
} }
......
...@@ -303,8 +303,10 @@ body.discussion { ...@@ -303,8 +303,10 @@ body.discussion {
font-weight: 700; font-weight: 700;
line-height: 18px; line-height: 18px;
color: #eee; color: #eee;
@include transition(none);
&:hover { &:hover,
&.focused {
background-color: #666; background-color: #666;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment