Skip to content
This repository
Browse code

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.
  • Loading branch information...
commit ada91e8568e299ea7a6a6e456fd500a7c3b402f4 1 parent bd6a9cf
Dennis Collective authored May 05, 2012
17  app/assets/javascripts/app/pages/post-viewer.js
@@ -50,29 +50,20 @@ app.pages.PostViewer = app.views.Base.extend({
50 50
   },
51 51
 
52 52
   bindNavHooks : function() {
53  
-    /* navagation hooks */
54  
-    var nextPostLocation = this.model.get("next_post");
55  
-    var previousPostLocation = this.model.get("previous_post");
56  
-
57  
-
  53
+    var model = this.model;
58 54
     $(document).keydown(function(evt){
59  
-      /* prevent nav from happening if the user is using the arrow
60  
-       * keys to navigate through their comment text */
  55
+      // prevent nav from happening if the user is using the arrow keys to navigate through their comment text
61 56
       if($(evt.target).is("textarea")) { return }
62 57
 
63 58
       switch(evt.keyCode) {
64 59
         case 37:
65  
-          navigate(nextPostLocation); break;
  60
+          app.router.navigate(model.get("next_post"), true); break;
66 61
         case 39:
67  
-          navigate(previousPostLocation); break;
  62
+          app.router.navigate(model.get("previous_post"), true); break;
68 63
         default:
69 64
           break;
70 65
       }
71 66
     })
72  
-
73  
-    function navigate(loc) {
74  
-      loc ? window.location = loc : null
75  
-    }
76 67
   },
77 68
 
78 69
   commentAnywhere : function(evt) {
13  app/assets/javascripts/app/router.js
@@ -23,10 +23,23 @@ app.Router = Backbone.Router.extend({
23 23
 
24 24
     "posts/new" : "composer",
25 25
     "posts/:id": "singlePost",
  26
+    "posts/:id/next": "siblingPost",
  27
+    "posts/:id/previous": "siblingPost",
  28
+
26 29
     "p/:id": "singlePost",
27 30
     "framer": "framer"
28 31
   },
29 32
 
  33
+  siblingPost : function(){ //next or previous
  34
+    var post = new app.models.Post();
  35
+    post.bind("change", setPreloadAttributesAndNavigate)
  36
+    post.fetch({url : window.location})
  37
+
  38
+    function setPreloadAttributesAndNavigate(){
  39
+      window.preloads.post = post.attributes
  40
+      app.router.navigate(post.url(), true)
  41
+    }
  42
+  },
30 43
 
31 44
   newProfile : function(personId) {
32 45
     this.renderPage(new app.pages.Profile({ personId : personId }));
15  app/assets/javascripts/app/views/post-viewer/nav.js
... ...
@@ -1,16 +1,3 @@
1 1
 app.views.PostViewerNav = app.views.Base.extend({
2  
-  templateName: "post-viewer/nav",
3  
-
4  
-  postRenderTemplate : function() {
5  
-    var mappings = {"#forward" : "next_post",
6  
-                    "#back" : "previous_post"};
7  
-
8  
-    _.each(mappings, function(attribute, selector){
9  
-      this.setArrow(this.$(selector), this.model.get(attribute))
10  
-    }, this);
11  
-  },
12  
-
13  
-  setArrow : function(arrow, loc) {
14  
-    loc ? arrow.attr('href', loc) : arrow.remove()
15  
-  }
  2
+  templateName: "post-viewer/nav"
16 3
 });
4  app/assets/templates/post-viewer/nav.jst.hbs
... ...
@@ -1,10 +1,10 @@
1  
-<a href="#" class="nav-arrow left" id="forward">
  1
+<a href="{{next_post}}" class="nav-arrow left" id="forward" rel="backbone">
2 2
   <div class="nav-arrow-inner">
3 3
     <img src="{{imageUrl "arrow-left.png"}}" />
4 4
   </div>
5 5
 </a>
6 6
 
7  
-<a href="#" class="nav-arrow right" id="back">
  7
+<a href="{{previous_post}}" class="nav-arrow right" id="back" rel="backbone">
8 8
   <div class="nav-arrow-inner">
9 9
     <img src="{{imageUrl "arrow-right.png"}}" />
10 10
   </div>

0 notes on commit ada91e8

Please sign in to comment.
Something went wrong with that request. Please try again.