next and last post don't have obnoxious blink 1/2 the time.
why not the rest, I don't know, time to start getting into event cleanup territory.
This commit is contained in:
parent
bd6a9cfe00
commit
ada91e8568
4 changed files with 20 additions and 29 deletions
|
|
@ -50,29 +50,20 @@ app.pages.PostViewer = app.views.Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
bindNavHooks : function() {
|
bindNavHooks : function() {
|
||||||
/* navagation hooks */
|
var model = this.model;
|
||||||
var nextPostLocation = this.model.get("next_post");
|
|
||||||
var previousPostLocation = this.model.get("previous_post");
|
|
||||||
|
|
||||||
|
|
||||||
$(document).keydown(function(evt){
|
$(document).keydown(function(evt){
|
||||||
/* prevent nav from happening if the user is using the arrow
|
// prevent nav from happening if the user is using the arrow keys to navigate through their comment text
|
||||||
* keys to navigate through their comment text */
|
|
||||||
if($(evt.target).is("textarea")) { return }
|
if($(evt.target).is("textarea")) { return }
|
||||||
|
|
||||||
switch(evt.keyCode) {
|
switch(evt.keyCode) {
|
||||||
case 37:
|
case 37:
|
||||||
navigate(nextPostLocation); break;
|
app.router.navigate(model.get("next_post"), true); break;
|
||||||
case 39:
|
case 39:
|
||||||
navigate(previousPostLocation); break;
|
app.router.navigate(model.get("previous_post"), true); break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function navigate(loc) {
|
|
||||||
loc ? window.location = loc : null
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
commentAnywhere : function(evt) {
|
commentAnywhere : function(evt) {
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,23 @@ app.Router = Backbone.Router.extend({
|
||||||
|
|
||||||
"posts/new" : "composer",
|
"posts/new" : "composer",
|
||||||
"posts/:id": "singlePost",
|
"posts/:id": "singlePost",
|
||||||
|
"posts/:id/next": "siblingPost",
|
||||||
|
"posts/:id/previous": "siblingPost",
|
||||||
|
|
||||||
"p/:id": "singlePost",
|
"p/:id": "singlePost",
|
||||||
"framer": "framer"
|
"framer": "framer"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
siblingPost : function(){ //next or previous
|
||||||
|
var post = new app.models.Post();
|
||||||
|
post.bind("change", setPreloadAttributesAndNavigate)
|
||||||
|
post.fetch({url : window.location})
|
||||||
|
|
||||||
|
function setPreloadAttributesAndNavigate(){
|
||||||
|
window.preloads.post = post.attributes
|
||||||
|
app.router.navigate(post.url(), true)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
newProfile : function(personId) {
|
newProfile : function(personId) {
|
||||||
this.renderPage(new app.pages.Profile({ personId : personId }));
|
this.renderPage(new app.pages.Profile({ personId : personId }));
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,3 @@
|
||||||
app.views.PostViewerNav = app.views.Base.extend({
|
app.views.PostViewerNav = app.views.Base.extend({
|
||||||
templateName: "post-viewer/nav",
|
templateName: "post-viewer/nav"
|
||||||
|
|
||||||
postRenderTemplate : function() {
|
|
||||||
var mappings = {"#forward" : "next_post",
|
|
||||||
"#back" : "previous_post"};
|
|
||||||
|
|
||||||
_.each(mappings, function(attribute, selector){
|
|
||||||
this.setArrow(this.$(selector), this.model.get(attribute))
|
|
||||||
}, this);
|
|
||||||
},
|
|
||||||
|
|
||||||
setArrow : function(arrow, loc) {
|
|
||||||
loc ? arrow.attr('href', loc) : arrow.remove()
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<a href="#" class="nav-arrow left" id="forward">
|
<a href="{{next_post}}" class="nav-arrow left" id="forward" rel="backbone">
|
||||||
<div class="nav-arrow-inner">
|
<div class="nav-arrow-inner">
|
||||||
<img src="{{imageUrl "arrow-left.png"}}" />
|
<img src="{{imageUrl "arrow-left.png"}}" />
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="#" class="nav-arrow right" id="back">
|
<a href="{{previous_post}}" class="nav-arrow right" id="back" rel="backbone">
|
||||||
<div class="nav-arrow-inner">
|
<div class="nav-arrow-inner">
|
||||||
<img src="{{imageUrl "arrow-right.png"}}" />
|
<img src="{{imageUrl "arrow-right.png"}}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue