Created
October 28, 2011 10:33
-
-
Save mizchi/1322043 to your computer and use it in GitHub Desktop.
私家版pushState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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