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:
parent
ada91e8568
commit
d47785d957
3 changed files with 30 additions and 21 deletions
|
|
@ -42,7 +42,7 @@ var app = {
|
||||||
Backbone.history.start({pushState: true});
|
Backbone.history.start({pushState: true});
|
||||||
|
|
||||||
// there's probably a better way to do this...
|
// 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();
|
evt.preventDefault();
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,7 @@ app.pages.PostViewer = app.views.Base.extend({
|
||||||
initialize : function(options) {
|
initialize : function(options) {
|
||||||
this.model = new app.models.Post({ id : options.id });
|
this.model = new app.models.Post({ id : options.id });
|
||||||
this.model.preloadOrFetch().done(_.bind(this.initViews, this));
|
this.model.preloadOrFetch().done(_.bind(this.initViews, this));
|
||||||
|
this.bindEvents()
|
||||||
this.prepIdleHooks();
|
|
||||||
|
|
||||||
$(document).bind("keypress", _.bind(this.commentAnywhere, this))
|
|
||||||
$(document).bind("keypress", _.bind(this.invokePane, this))
|
|
||||||
$(document).bind("keyup", _.bind(this.closePane, this))
|
|
||||||
},
|
},
|
||||||
|
|
||||||
initViews : function() {
|
initViews : function() {
|
||||||
|
|
@ -29,6 +24,23 @@ app.pages.PostViewer = app.views.Base.extend({
|
||||||
this.render();
|
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 () {
|
prepIdleHooks : function () {
|
||||||
$.idleTimer(3000);
|
$.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() {
|
bindNavHooks : function() {
|
||||||
var model = this.model;
|
var model = this.model;
|
||||||
$(document).keydown(function(evt){
|
$(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) {
|
commentAnywhere : function(evt) {
|
||||||
/* ignore enter, space bar, arrow keys */
|
/* ignore enter, space bar, arrow keys */
|
||||||
if(_.include([13, 32, 37, 38, 39, 40], evt.keyCode)) { return }
|
if(_.include([13, 32, 37, 38, 39, 40], evt.keyCode)) { return }
|
||||||
|
|
|
||||||
|
|
@ -42,19 +42,19 @@ app.Router = Backbone.Router.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
newProfile : function(personId) {
|
newProfile : function(personId) {
|
||||||
this.renderPage(new app.pages.Profile({ personId : personId }));
|
this.renderPage(function(){ return new app.pages.Profile({ personId : personId })});
|
||||||
},
|
},
|
||||||
|
|
||||||
composer : function(){
|
composer : function(){
|
||||||
this.renderPage(new app.pages.Composer());
|
this.renderPage(function(){ return new app.pages.Composer()});
|
||||||
},
|
},
|
||||||
|
|
||||||
framer : function(){
|
framer : function(){
|
||||||
this.renderPage(new app.pages.Framer());
|
this.renderPage(function(){ return new app.pages.Framer()});
|
||||||
},
|
},
|
||||||
|
|
||||||
singlePost : function(id) {
|
singlePost : function(id) {
|
||||||
this.renderPage(new app.pages.PostViewer({ id: id }));
|
this.renderPage(function(){ return new app.pages.PostViewer({ id: id })});
|
||||||
},
|
},
|
||||||
|
|
||||||
profile : function(page) {
|
profile : function(page) {
|
||||||
|
|
@ -85,8 +85,9 @@ app.Router = Backbone.Router.extend({
|
||||||
return query.search("ex=true") != -1
|
return query.search("ex=true") != -1
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPage : function(page){
|
renderPage : function(pageConstructor){
|
||||||
app.page = page
|
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)
|
$("#container").html(app.page.render().el)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue