Skip to content
This repository has been archived by the owner on Feb 14, 2018. It is now read-only.

Commit

Permalink
History branch cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nrn committed Feb 25, 2012
1 parent 1170d27 commit c5b67dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
18 changes: 11 additions & 7 deletions client/client.coffee
Expand Up @@ -347,7 +347,7 @@ $ ->
.append("<a class=\"show-page-source\" href=\"/#{slug}.json?random=#{randomBytes(4)}\" title=\"source\">JSON</a> . ")
.append("<a href=\"#\" class=\"add-factory\" title=\"add paragraph\">[+]</a>")

setState()
setUrl()

fetch = (slug, callback, localContext) ->
wiki.fetchContext = ['origin'] unless wiki.fetchContext.length > 0
Expand Down Expand Up @@ -410,12 +410,12 @@ $ ->

# FUNCTIONS and HANDLERS to manage location bar and back button

setState = ->
setUrl = ->
if history and history.pushState
locs = locsInDom()
pages = pagesInDom()
url = ("/#{locs?[idx] or 'view'}/#{page}" for page, idx in pages).join('')
unless url is document.location.pathname
unless url is $(location).attr('pathname')
wiki.log 'set state', locs, pages
history.pushState(null, null, url)

Expand Down Expand Up @@ -447,9 +447,6 @@ $ ->

setActive($('.page').last().attr('id'))

$(window).on 'popstate', (event) ->
wiki.log 'popstate', event
showState()

LEFTARROW = 37
RIGHTARROW = 39
Expand All @@ -464,6 +461,9 @@ $ ->
if 0 <= newIndex < pages.length
setActive(pages[newIndex])

# FUNCTIONS for finding the current state of pages and locations in the
# URL or DOM

pagesInDom = ->
$.makeArray $(".page").map (_, el) -> el.id

Expand All @@ -485,6 +485,10 @@ $ ->

# HANDLERS for jQuery events

$(window).on 'popstate', (event) ->
wiki.log 'popstate', event
showState()

$(document)
.ajaxError (event, request, settings) ->
wiki.log 'ajax error', event, request, settings
Expand Down Expand Up @@ -532,7 +536,7 @@ $ ->
$("footer input:first").val $(this).attr('data-provider')
$("footer form").submit()

setState()
setUrl()

firstUrlPages = urlPages()
firstUrlLocs = urlLocs()
Expand Down
18 changes: 9 additions & 9 deletions client/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5b67dd

Please sign in to comment.