Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Created January 28, 2013 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/4660159 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/4660159 to your computer and use it in GitHub Desktop.
$ ()->
linkaction = (e)->
if e.target.id != ""# and "login" "logout"
location.hash = e.target.id
e.preventDefault()
update()
true
$("#body").on "click","a",linkaction
$("#body").on "click","#editable",(e)->
e.preventDefault()
location.hash = location.hash.slice 1
update()
$("#body").on "click","#dontNote", ()->
e.preventDefault()
location.hash = "home"
update()
$("#body").on "submit","#noteForm", (e)->
e.preventDefault()
results =
body : $("#noteBody").val()
title : $("#noteTitle").val()
type : "note"
pouch.add results, (err, resp)->
location.hash = resp.id
update()
false
$("#body").on "click","#updateNote",(e)->
e.preventDefault()
if location.hash.slice(0,5) == '#edit'
docid =location.hash.slice(5)
pouch.get docid, (err,doc)->
return if err or doc.type isnt "note"
doc.body =$("#noteBody").val()
doc.title=$("#noteTitle").val()
pouch.add doc
location.hash = docid
update()
true
$("#body").on "click","#deleteNote",(e)->
e.preventDefault()
if location.hash.slice(0,5) == '#edit'
docid =location.hash.slice(5)
pouch.remove docid, ()->
location.hash ="home"
update()
true
$("#body").on "click","#cancelUpdate",(e)->
e.preventDefault()
location.hash="home"
update()
$("#body").on "click","#toggleStart",(e)->
e.preventDefault()
pouch.stop().start()
update()
true
window.onpopstate=()->
update()
window.pouch = new PouchCore location.protocol + "//"+ location.host + "/pd", (change)=>
if change.id[0] isnt "_" and (change.doc.type is 'note' or change.doc.type is 'page')
unless change.doc._deleted
obj[change.id] = change.doc
update()
else if change.doc._deleted and change.id of obj
delete obj[change.id]
update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment