State in the DOM

Pages are rendered into the dom in the wiki-client's lib/refresh.coffee. Logic there annotates elements with data attributes offen fetched with jquery.

# Item

Refresh creates a dom element for each story item. These are passed to plugin functions emit and bind.

emit = ($item, item) -> ... bind = ($item, item) -> ...

Cooperating items can share things by announcing their availability by attaching a class to $item and then retrieving available items by agreed function calls.

$item.addClass 'thing-source' $item.get(0).getThings = -> ...

By convention we retrieve items above and to our left.

items = $(".item:lt(#{$('.item').index($item)})") for each in items if $(each).hasClass 'thing-source' things = each.getThings() ...

An item can revise its own contents by constructing a new or revised item object, rendering it, and then posting an edit action to the server which will revise the journal on completion. See Tips for Binding Events

$item.empty() emit($item, item) bind($item, item) wiki.pageHandler.put $page, type: 'edit', id: item.id, item: item

# Page

Refresh expects an empty dom element which it fills after fetching json content from the web.

Find a page from an item by looking up the dom element parent tree. From this one can retrieve the parsed json for the page as refreshed. See JSON Schema

$page = $item.parents '.page'

page = $page.data 'data'

A page retrieved from a remote site will be annotated as such. Null or absent means page came from the origin.

remote = $page.data 'site'

Find the slug of the page from the page id. [sic]

slug_rev = $page.attr('id') slug = $page.attr('id').split('_')[0]

Find the title from the h1 or from the page data.

title = $page.find('h1').text().trim() title = page.title