add keybinding to the viewer

This commit is contained in:
danielgrippi 2012-02-22 19:19:24 -08:00
parent 8f3cc6769c
commit b4923a77f0
5 changed files with 72 additions and 45 deletions

View file

@ -21,7 +21,7 @@ class CommentsController < ApplicationController
if @comment if @comment
respond_to do |format| respond_to do |format|
format.json{ render :json => @comment.as_api_response(:backbone), :status => 201 } format.json{ render :json => @comment.as_api_response(:backbone), :status => 201 }
format.html{ redirect_to :back} format.html{ render :nothing => true, :status => 201 }
format.mobile{ render :partial => 'comment', :locals => {:post => @comment.post, :comment => @comment} } format.mobile{ render :partial => 'comment', :locals => {:post => @comment.post, :comment => @comment} }
end end
else else

View file

@ -9,25 +9,25 @@ app.pages.PostViewer = app.views.Base.extend({
"#header-container" : "authorView" "#header-container" : "authorView"
}, },
postView : function(){ initialize : function() {
return new app.views.Post({ this.initViews();
$(document).bind("keypress", _.bind(this.commentAnywhere, this))
$(document).bind("keypress", _.bind(this.invokePane, this))
$(document).bind("keyup", _.bind(this.closePane, this))
},
initViews : function() {
this.authorView = new app.views.PostViewerAuthor({ model : this.model });
this.interactionsView = new app.views.PostViewerInteractions({ model : this.model });
this.navView = new app.views.PostViewerNav({ model : this.model });
this.postView = new app.views.Post({
model : this.model, model : this.model,
className : "post loaded", className : "post loaded",
templateName : "post-viewer/content/" + this.options.postTemplateName, templateName : "post-viewer/content/" + this.options.postTemplateName,
attributes : {"data-template" : this.options.postTemplateName} attributes : {"data-template" : this.options.postTemplateName}
}) });
},
navView : function() {
return new app.views.PostViewerNav({ model : this.model })
},
interactionsView : function() {
return new app.views.PostViewerInteractions({ model : this.model })
},
authorView : function() {
return new app.views.PostViewerAuthor({ model : this.model })
}, },
postRenderTemplate : function() { postRenderTemplate : function() {
@ -42,24 +42,36 @@ app.pages.PostViewer = app.views.Base.extend({
$(document).keydown(function(e){ $(document).keydown(function(e){
switch(e.keyCode) { switch(e.keyCode) {
case 37: case 37:
navigate(nextPostLocation, "left"); break; navigate(nextPostLocation); break;
case 39: case 39:
navigate(previousPostLocation, "right"); break; navigate(previousPostLocation); break;
default: default:
break; break;
} }
}) })
function navigate(loc, direction) { function navigate(loc) {
loc ? window.location = loc : bump(direction) loc ? window.location = loc : null
} }
},
function bump(direction) { commentAnywhere : function(evt) {
$(".backdrop").addClass("bump-" + direction) /* ignore enter and space bar */
setTimeout( function(){ if(evt.keyCode == 13 || evt.keyCode == 32) { return }
$(".backdrop").removeClass("bump-" + direction)
}, 200) this.interactionsView.invokePane();
} $('#new-post-comment textarea').focus();
},
invokePane : function(evt) {
if(evt.keyCode != 32) { return }
this.interactionsView.invokePane();
},
closePane : function(evt) {
if(evt.keyCode != 27) { return }
this.interactionsView.hidePane();
} }
}) })

View file

@ -10,17 +10,13 @@ app.views.PostViewerFeedback = app.views.Feedback.extend({
"click .follow" : "toggleFollow", "click .follow" : "toggleFollow",
"click .reshare" : "resharePost", "click .reshare" : "resharePost",
"click .comment" : "comment" "click .comment" : "invokePane"
}, },
tooltipSelector : ".label", tooltipSelector : ".label",
comment : function(evt){ invokePane : function(evt){
if(evt) { evt.preventDefault() } this.trigger("invokePane")
$("#post-info").slideToggle()
this.removeTooltips()
console.log(this.model)
} }
}) })

View file

@ -10,17 +10,36 @@ app.views.PostViewerInteractions = app.views.Base.extend({
templateName: "post-viewer/interactions", templateName: "post-viewer/interactions",
feedbackView : function() { initialize : function() {
if(!window.app.user()) { return null } this.initViews();
return new app.views.PostViewerFeedback({ model : this.model })
this.feedbackView.bind("invokePane", this.invokePane, this)
}, },
reactionsView : function() { initViews : function() {
return new app.views.PostViewerReactions({ model : this.model }) this.reactionsView = new app.views.PostViewerReactions({ model : this.model })
},
newCommentView : function() { /* subviews that require user */
if(!window.app.user()) { return null } if(window.app.user()) {
return new app.views.PostViewerNewComment({ model : this.model }) this.feedbackView = new app.views.PostViewerFeedback({ model : this.model })
this.newCommentView = new app.views.PostViewerNewComment({ model : this.model })
} }
},
togglePane : function(evt) {
if(evt) { evt.preventDefault() }
this.$("#post-info").slideToggle()
this.removeTooltips()
},
invokePane : function(evt) {
if(evt) { evt.preventDefault() }
if(!this.$("#post-info").is(":visible")) { this.togglePane() }
},
hidePane : function(evt) {
if(evt) { evt.preventDefault() }
if(this.$("#post-info").is(":visible")) { this.togglePane() }
}
}) })

View file

@ -339,7 +339,7 @@ $light-grey: #999;
background-color: #444; background-color: #444;
background-image: url("../images/hatched-bg-dark.png"); background-image: url("../images/hatched-bg-dark.png");
color: #ccc; color: #ddd;
} }
.well { .well {
@ -417,10 +417,10 @@ $light-grey: #999;
@include border-radius(); @include border-radius();
} }
text-shadow: 0 1px 3px #222; text-shadow: 0 1px 3px rgba(0,0,0,0.3);
a { a:hover {
color: inherit; color: #99CCFF
} }
time { time {