preload post on post show
This commit is contained in:
parent
6fcba2dd4b
commit
4253796f55
5 changed files with 16 additions and 7 deletions
|
|
@ -61,7 +61,7 @@ var app = {
|
|||
var preload = window.preloads[prop]
|
||||
delete window.preloads[prop] //prevent dirty state across navigates
|
||||
|
||||
return JSON.parse(preload)
|
||||
return(preload)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,12 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
|
|||
var body = this.get("text").trim()
|
||||
, newlineIdx = body.indexOf("\n")
|
||||
return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : ""
|
||||
},
|
||||
|
||||
//returns a promise
|
||||
preloadOrFetch : function(){
|
||||
var action = app.hasPreload("post") ? this.set(app.parsePreload("post")) : this.fetch()
|
||||
return $.when(action)
|
||||
}
|
||||
}), {
|
||||
headlineLimit : 118,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ app.pages.PostViewer = app.views.Base.extend({
|
|||
|
||||
initialize : function(options) {
|
||||
this.model = new app.models.Post({ id : options.id });
|
||||
this.model.fetch().success(_.bind(this.initViews, this));
|
||||
this.model.preloadOrFetch().done(_.bind(this.initViews, this));
|
||||
|
||||
this.prepIdleHooks();
|
||||
|
||||
|
|
|
|||
|
|
@ -119,8 +119,7 @@ class PeopleController < ApplicationController
|
|||
format.all do
|
||||
if params[:ex]
|
||||
@page = :experimental
|
||||
json = @stream.stream_posts.as_api_response(:backbone).to_json
|
||||
gon.stream = json
|
||||
gon.stream = @stream.stream_posts.as_api_response(:backbone).as_json
|
||||
render :nothing => true, :layout => 'post'
|
||||
else
|
||||
respond_with @person, :locals => {:post_type => :all}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ class PostsController < ApplicationController
|
|||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html{render 'posts/show.html.haml'}
|
||||
format.html{ gon.post = postJson; render 'posts/show.html.haml' }
|
||||
format.xml{ render :xml => @post.to_diaspora_xml }
|
||||
format.mobile{render 'posts/show.mobile.haml', :layout => "application"}
|
||||
format.json{ render :json => PostPresenter.new(@post, current_user).to_json }
|
||||
format.json{ render :json => postJson }
|
||||
end
|
||||
|
||||
else
|
||||
|
|
@ -88,7 +88,11 @@ class PostsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
protected
|
||||
|
||||
def postJson
|
||||
PostPresenter.new(@post, current_user).to_json
|
||||
end
|
||||
|
||||
def find_by_guid_or_id_with_current_user(id)
|
||||
key = id.to_s.length <= 8 ? :id : :guid
|
||||
|
|
|
|||
Loading…
Reference in a new issue