diaspora/app/assets/javascripts/app/pages/post-viewer.js
Steven Hancock 1aa0b15c8c Move Javascript to the asset pipeline
* Move all Diaspora-specific javascripts to app/assets/javascripts
* Move all vendored javascripts to vendor/assets/javascripts
* Add the appropriate Sprockets require directives to make sure
  everything gets included in the right order
* Remove Jammit dependencies
* Fix all templates that were using Jammit's include_javascripts helper
* Add handlebars_assets gem for compiling Handlebars templates
* Move all Handlebars templates to app/assets/templates and rename
  from .handlebars to .jst.hbs (this is to keep them in the same
  global JST namespace that they were in under Jammit)
* Add public/assets to .gitignore since these files can and should
  be re-generated by Heroku or Capistrano during each deploy
* Fix a few Handlebars templates that were looking for images in the
  wrong location (I'm sure there are others, but it's late)
* Configure application.rb to precompile all javascript and css assets
  that were compiled by Jammit in the Rails 3.0 code
2012-03-27 18:07:44 -07:00

97 lines
2.5 KiB
JavaScript

app.pages.PostViewer = app.views.Base.extend({
templateName: "post-viewer",
subviews : {
"#post-content" : "postView",
"#post-nav" : "navView",
"#post-interactions" : "interactionsView",
"#header-container" : "authorView"
},
initialize : function(options) {
this.model = new app.models.Post({ id : options.id });
this.model.fetch().success(_.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))
},
initViews : function() {
/* init view */
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 = app.views.Post.showFactory(this.model)
this.render();
},
prepIdleHooks : function () {
$.idleTimer(3000);
$(document).bind("idle.idleTimer", function(){
$("body").addClass('idle');
});
$(document).bind("active.idleTimer", function(){
$("body").removeClass('idle');
});
},
postRenderTemplate : function() {
/* set the document title */
console.log(this.model)
document.title = this.model.get("title");
this.bindNavHooks();
},
bindNavHooks : function() {
/* navagation hooks */
var nextPostLocation = this.model.get("next_post");
var previousPostLocation = this.model.get("previous_post");
$(document).keydown(function(evt){
/* prevent nav from happening if the user is using the arrow
* keys to navigate through their comment text */
if($(evt.target).is("textarea")) { return }
switch(evt.keyCode) {
case 37:
navigate(nextPostLocation); break;
case 39:
navigate(previousPostLocation); break;
default:
break;
}
})
function navigate(loc) {
loc ? window.location = loc : null
}
},
commentAnywhere : function(evt) {
/* ignore enter, space bar, arrow keys */
if(_.include([13, 32, 37, 38, 39, 40], evt.keyCode)) { return }
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();
}
});