Commit d8e3108a by Matthew Mongeau

Sidebar positioning and height.

parent 9da7a337
...@@ -14,6 +14,7 @@ class @DiscussionRouter extends Backbone.Router ...@@ -14,6 +14,7 @@ class @DiscussionRouter extends Backbone.Router
@newPostView.on "thread:created", @navigateToThread @newPostView.on "thread:created", @navigateToThread
allThreads: -> allThreads: ->
@nav.updateSidebar()
# TODO: Do something reasonable here # TODO: Do something reasonable here
# $(".discussion-column").html($('#blank-slate-template').html()) # $(".discussion-column").html($('#blank-slate-template').html())
...@@ -29,6 +30,8 @@ class @DiscussionRouter extends Backbone.Router ...@@ -29,6 +30,8 @@ class @DiscussionRouter extends Backbone.Router
@main = new DiscussionThreadView(el: $(".discussion-column"), model: @thread) @main = new DiscussionThreadView(el: $(".discussion-column"), model: @thread)
@main.render() @main.render()
@main.on "thread:responses:rendered", =>
@nav.updateSidebar()
navigateToThread: (thread_id) => navigateToThread: (thread_id) =>
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
......
...@@ -11,9 +11,44 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -11,9 +11,44 @@ class @DiscussionThreadListView extends Backbone.View
initialize: -> initialize: ->
@displayedCollection = new Discussion(@collection.models) @displayedCollection = new Discussion(@collection.models)
@collection.on "change", @reloadDisplayedCollection @collection.on "change", @reloadDisplayedCollection
@sidebar_padding = 10
@sidebar_header_height = 87
reloadDisplayedCollection: => reloadDisplayedCollection: =>
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models)
@updateSidebar()
updateSidebar: =>
scrollTop = $(window).scrollTop();
windowHeight = $(window).height();
$discussionBody = $(".discussion-body")
discussionsBodyTop = $discussionBody.offset().top;
discussionsBodyBottom = discussionsBodyTop + $discussionBody.height();
$sidebar = $(".sidebar")
if scrollTop > discussionsBodyTop - @sidebar_padding
$sidebar.addClass('fixed');
$sidebar.css('top', @sidebar_padding);
else
$sidebar.removeClass('fixed');
$sidebar.css('top', '0');
sidebarWidth = .32 * $discussionBody.width() - 10;
$sidebar.css('width', sidebarWidth + 'px');
sidebarHeight = windowHeight - Math.max(discussionsBodyTop - scrollTop, @sidebar_padding)
topAmount = scrollTop + windowHeight
bottomAmount = discussionsBodyBottom + @sidebar_padding
amount = Math.max(topAmount - bottomAmount, 0)
sidebarHeight = sidebarHeight - @sidebar_padding - amount
$sidebar.css 'height', Math.max(sidebarHeight, 400)
$postListWrapper = @$('.post-list-wrapper')
$postListWrapper.css('height', (sidebarHeight - @sidebar_header_height - 4) + 'px');
# Because we want the behavior that when the body is clicked the menu is # Because we want the behavior that when the body is clicked the menu is
...@@ -25,6 +60,10 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -25,6 +60,10 @@ class @DiscussionThreadListView extends Backbone.View
render: -> render: ->
@timer = 0 @timer = 0
@$el.html(@template()) @$el.html(@template())
$(window).bind "scroll", @updateSidebar
$(window).bind "resize", @updateSidebar
@displayedCollection.on "reset", @renderThreads @displayedCollection.on "reset", @renderThreads
@renderThreads() @renderThreads()
@ @
......
...@@ -54,6 +54,7 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -54,6 +54,7 @@ class @DiscussionThreadView extends DiscussionContentView
Content.loadContentInfos(data['annotated_content_info']) Content.loadContentInfos(data['annotated_content_info'])
comments = new Comments(data['content']['children']) comments = new Comments(data['content']['children'])
comments.each @renderResponse comments.each @renderResponse
@trigger "thread:responses:rendered"
renderResponse: (response) => renderResponse: (response) =>
view = new ThreadResponseView(model: response) view = new ThreadResponseView(model: response)
......
...@@ -67,13 +67,13 @@ $(document).ready(function() { ...@@ -67,13 +67,13 @@ $(document).ready(function() {
$body.delegate('.browse-topic-drop-search-input, .form-topic-drop-search-input', 'keyup', filterDrop); $body.delegate('.browse-topic-drop-search-input, .form-topic-drop-search-input', 'keyup', filterDrop);
$(window).bind('resize', updateSidebar); // $(window).bind('resize', updateSidebar);
$(window).bind('scroll', updateSidebar); // $(window).bind('scroll', updateSidebar);
$('.discussion-column').bind("input", function (e) { // $('.discussion-column').bind("input", function (e) {
console.log("resized"); // console.log("resized");
updateSidebar(); // updateSidebar();
}) // })
updateSidebar(); // updateSidebar();
}); });
function filterDrop(e) { function filterDrop(e) {
......
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