annotate app/assets/javascripts/zp.hash_magic.js @ 332:a999250e57c4

Update deprecated method.
author edogawaconan <me@myconan.net>
date Mon, 14 Apr 2014 17:28:31 +0900
parents e855e58d137e
children 4b91c0c1938c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
1 //= require zp.formatter
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
2 (function($) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
3 window.zp.hash_magic = {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
4 load_hash: function() {
287
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
5 var
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
6 format = window.location.hash.slice(1),
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
7 tab_link = function(fmt) {
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
8 return zp.formatter.links().filter("[href='#" + fmt + "']")
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
9 }
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
10 if(!tab_link(format).length) format = "pl"
77c157a9e645 Fix hash magic links.
edogawaconan <me@myconan.net>
parents: 264
diff changeset
11 tab_link(format).click()
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
12 },
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
13 set_hash: function(e) {
224
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
14 if (typeof e !== "undefined") {
263
a9c45375a656 Nuke width adjuster from orbit.
edogawaconan <me@myconan.net>
parents: 232
diff changeset
15 if (zp.formatter.links().filter(e.target).length === 0) return
224
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
16 else e.preventDefault()
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
17 }
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
18 var
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
19 format = zp.formatter.current(),
308
e855e58d137e Always include current path when replacing state.
edogawaconan <me@myconan.net>
parents: 287
diff changeset
20 newpath = window.location.pathname
e855e58d137e Always include current path when replacing state.
edogawaconan <me@myconan.net>
parents: 287
diff changeset
21 if (format !== "pl") { newpath += "#" + format }
e855e58d137e Always include current path when replacing state.
edogawaconan <me@myconan.net>
parents: 287
diff changeset
22 history.replaceState(null, "", newpath)
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 },
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
24 init: function() {
232
e3468efc9ec9 Do check if we're on the right place
Edho Arief <edho@myconan.net>
parents: 224
diff changeset
25 if (!$("#paste").length) return
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
26 this.load_hash()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
27 if (history.replaceState) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 this.set_hash()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
29 $(document).on('click', $.proxy(this.set_hash, this))
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
31 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
32 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
33 })(jQuery)