comparison app/assets/javascripts/zp.hash_magic.js.coffee @ 349:f802099acd37

coffee: hash_magic.
author edogawaconan <me@myconan.net>
date Thu, 03 Jul 2014 15:03:34 +0900
parents app/assets/javascripts/zp.hash_magic.js@4b91c0c1938c
children
comparison
equal deleted inserted replaced
348:55287d8a5a04 349:f802099acd37
1 #= require zp.formatter
2 window.zp.hash_magic =
3 load_hash: ->
4 format = window.location.hash.slice(1)
5 tab_link = (fmt) -> zp.formatter.links().filter("[href='##{fmt}']")
6
7 format = "pl" unless tab_link(format).length
8 tab_link(format).click()
9
10 set_hash: (e) ->
11 format = zp.formatter.current()
12 newpath = window.location.pathname
13 newpath += "##{format}" if (format != "pl")
14 history.replaceState null, "", newpath
15
16 init: ->
17 return unless $("#paste").length
18 @load_hash()
19 if (history.replaceState)
20 @set_hash()
21 zp.formatter.links().on("shown.bs.tab", this.set_hash)