Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions app/assets/javascripts/routes/documents.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ LiveReader.DocumentsRoute = Ember.Route.extend
# Setup Pusher
pusher = new Pusher('8146487894a3cc81758c')
@set('pusher', pusher)

channel = pusher.subscribe('<%= Rails.env %>_main_channel')
channel.bind 'update', (payload) =>
# TODO: Clean up this big ugly chunk of procedural code
payload.updated_at = new Date(payload.updated_at)

channel.bind 'patch', (payload) =>
doc = @model().find((item) => item.get('id') == payload.id)
# debugger
if doc
doc.setProperties
title: payload.title
body: payload.body
updated_at: payload.updated_at
else
doc = LiveReader.Document.createRecord(payload)
20 changes: 17 additions & 3 deletions app/assets/javascripts/spotlight.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ channel.bind 'update', (payload) =>
y = el.position()['top'] - 100
$.scrollTo(y)




channel.bind 'patch', (payload) =>
$.ajax "/api/v1/documents/" + payload.id,
type: "GET"
dataType: "json"
success: (data) ->
document = data.document
oldText = split $(".text").html().trim()
$("h1").html(document.title)
$(".text").html(document.body)
newText = split $(".text").html().trim()
try
for snippet, i in newText
if newText[i] != oldText[i]
parsedSnippet = $("<p>#{snippet}</p>").text()
el = $(":contains(#{parsedSnippet})").last()
y = el.position()['top'] - 100
$.scrollTo(y)
3 changes: 2 additions & 1 deletion app/controllers/writeroom/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def update
@document = Document.find(params[:id])

if @document.update(document_params)
Pusher.trigger(pusher_channel, 'update', @document.to_pusher)
Pusher.trigger(pusher_channel, 'patch',
{ id: @document.id.to_s })
end
respond_with @document
end
Expand Down