Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Last active December 11, 2015 21:09
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/4660123 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/4660123 to your computer and use it in GitHub Desktop.
obj={}#this will store the data we get from pouch
converter = new Showdown.converter()
update = ->
window.views = {sideList : []}
if location.hash == ""
hash="home"
location.hash="home"
else if location.hash.slice(0,5) == '#edit'
hash = location.hash.slice(5)
views.edit = true
else
hash = location.hash.slice(1)
if hash not of obj
hash = "home"
for key of obj#itterate through all the items every update, I'd not do this in real life if i were you
if hash == key
views.title=obj[key].title
views.body=obj[key].body
views[key]=true
if "type" of obj[key] and obj[key].type == "note"
item = {key:key,title:obj[key].title}
if hash == key
views.editable=true
item.active=true
else
item.active=false
views.sideList.push item
views.up = pouch.up
views.hash = hash
views.md =()->
(text, render)->
converter.makeHtml(render(text))
if views.title is "New Note"
views.newNote = true
$("#body").empty().append(template(views))
if views.edit or views.title is "New Note"
ta = $("#noteBody")
t2 = $("#tab2")
tt = $("#noteTitle")
ch=()->
t2.empty().append("<h3>#{tt.val()}</h3>"+converter.makeHtml(ta.val()))
ch()
ta.on "change", ch
tt.on "change", ch
document.title = views.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment