annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
349
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
1 #= require zp.formatter
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
2 window.zp.hash_magic =
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
3 load_hash: ->
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
4 format = window.location.hash.slice(1)
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
5 tab_link = (fmt) -> zp.formatter.links().filter("[href='##{fmt}']")
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
6
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
7 format = "pl" unless tab_link(format).length
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
8 tab_link(format).click()
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
9
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
10 set_hash: (e) ->
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
11 format = zp.formatter.current()
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
12 newpath = window.location.pathname
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
13 newpath += "##{format}" if (format != "pl")
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
14 history.replaceState null, "", newpath
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
15
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
16 init: ->
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
17 return unless $("#paste").length
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
18 @load_hash()
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
19 if (history.replaceState)
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
20 @set_hash()
f802099acd37 coffee: hash_magic.
edogawaconan <me@myconan.net>
parents: 340
diff changeset
21 zp.formatter.links().on("shown.bs.tab", this.set_hash)