next and previous should be faster

unbind events on navigate, implimented for at least the single page view
bind changed to on for backbone navigating
This commit is contained in:
Dennis Collinson 2012-05-05 18:35:58 -07:00
parent ada91e8568
commit d47785d957
3 changed files with 30 additions and 21 deletions

View file

@ -42,7 +42,7 @@ var app = {
Backbone.history.start({pushState: true});
// there's probably a better way to do this...
$("a[rel=backbone]").bind("click", function(evt){
$("a[rel=backbone]").live("click", function(evt){
evt.preventDefault();
var link = $(this);

View file

@ -11,12 +11,7 @@ app.pages.PostViewer = app.views.Base.extend({
initialize : function(options) {
this.model = new app.models.Post({ id : options.id });
this.model.preloadOrFetch().done(_.bind(this.initViews, this));
this.prepIdleHooks();
$(document).bind("keypress", _.bind(this.commentAnywhere, this))
$(document).bind("keypress", _.bind(this.invokePane, this))
$(document).bind("keyup", _.bind(this.closePane, this))
this.bindEvents()
},
initViews : function() {
@ -29,6 +24,23 @@ app.pages.PostViewer = app.views.Base.extend({
this.render();
},
bindEvents : function(){
this.prepIdleHooks();
this.bindNavHooks();
$(document).bind("keypress", _.bind(this.commentAnywhere, this))
$(document).bind("keypress", _.bind(this.invokePane, this))
$(document).bind("keyup", _.bind(this.closePane, this))
},
unbind : function(){
$(document).unbind("idle.idleTimer")
$(document).unbind("active.idleTimer")
$(document).unbind('keydown')
$(document).unbind('keypress')
$(document).unbind('keyup')
},
prepIdleHooks : function () {
$.idleTimer(3000);
@ -41,14 +53,6 @@ app.pages.PostViewer = app.views.Base.extend({
});
},
postRenderTemplate : function() {
/* set the document title, if it has one */
if(this.model.get("title")){
document.title = this.model.get("title");
}
this.bindNavHooks();
},
bindNavHooks : function() {
var model = this.model;
$(document).keydown(function(evt){
@ -66,6 +70,10 @@ app.pages.PostViewer = app.views.Base.extend({
})
},
postRenderTemplate : function() {
if(this.model.get("title")){ document.title = this.model.get("title"); }
},
commentAnywhere : function(evt) {
/* ignore enter, space bar, arrow keys */
if(_.include([13, 32, 37, 38, 39, 40], evt.keyCode)) { return }

View file

@ -42,19 +42,19 @@ app.Router = Backbone.Router.extend({
},
newProfile : function(personId) {
this.renderPage(new app.pages.Profile({ personId : personId }));
this.renderPage(function(){ return new app.pages.Profile({ personId : personId })});
},
composer : function(){
this.renderPage(new app.pages.Composer());
this.renderPage(function(){ return new app.pages.Composer()});
},
framer : function(){
this.renderPage(new app.pages.Framer());
this.renderPage(function(){ return new app.pages.Framer()});
},
singlePost : function(id) {
this.renderPage(new app.pages.PostViewer({ id: id }));
this.renderPage(function(){ return new app.pages.PostViewer({ id: id })});
},
profile : function(page) {
@ -85,8 +85,9 @@ app.Router = Backbone.Router.extend({
return query.search("ex=true") != -1
},
renderPage : function(page){
app.page = page
renderPage : function(pageConstructor){
app.page && app.page.unbind && app.page.unbind() //old page might mutate global events $(document).keypress, so unbind before creating
app.page = pageConstructor() //create new page after the world is clean (like that will ever happen)
$("#container").html(app.page.render().el)
}
});