Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created October 28, 2011 10:33
Show Gist options
  • Save mizchi/1322043 to your computer and use it in GitHub Desktop.
Save mizchi/1322043 to your computer and use it in GitHub Desktop.
私家版pushState
init_content = (href)->
$.ajax href,
data:
v : 0.1
json:true
from:location.href
success:(data)->
$("div#content").html CoffeeKup.render content[data.template],data.params
$("a.push").each ->
$(@).unbind "click"
$(@).click (event)=>
load_url $(@).text(),$(@).attr "href"
event.preventDefault()
load_url = (title,href)->
next_url = window.location.protocol + "//" + window.location.host + href
if !!(window.history and window.history.pushState)
history.pushState
ts: new Date
, title
, next_url
init_content href
else
window.location.href = next_url
$(window).bind "popstate",(e)->
init_content location.pathname
$(document).ready ->
init_content location.pathname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment