Mercurial > zeropaste
annotate app/assets/javascripts/zp.hash_magic.js @ 263:a9c45375a656
Nuke width adjuster from orbit.
author | edogawaconan <me@myconan.net> |
---|---|
date | Wed, 16 Oct 2013 01:55:23 +0900 |
parents | e3468efc9ec9 |
children | fa4a1ba990ae |
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() { |
263
a9c45375a656
Nuke width adjuster from orbit.
edogawaconan <me@myconan.net>
parents:
232
diff
changeset
|
5 var format = window.location.hash.slice(1) |
214
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
6 if (format !== undefined) { |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
7 zp.formatter.links().filter("[href=#" + format + "]").click() |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
8 } |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
9 }, |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
10 set_hash: function(e) { |
224
6e9718a1ee11
Combine event-related actions
Edho Arief <edho@myconan.net>
parents:
223
diff
changeset
|
11 if (typeof e !== "undefined") { |
263
a9c45375a656
Nuke width adjuster from orbit.
edogawaconan <me@myconan.net>
parents:
232
diff
changeset
|
12 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
|
13 else e.preventDefault() |
6e9718a1ee11
Combine event-related actions
Edho Arief <edho@myconan.net>
parents:
223
diff
changeset
|
14 } |
214
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
15 var |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
16 format = zp.formatter.current(), |
263
a9c45375a656
Nuke width adjuster from orbit.
edogawaconan <me@myconan.net>
parents:
232
diff
changeset
|
17 hash = "#" |
214
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
18 hash += format |
263
a9c45375a656
Nuke width adjuster from orbit.
edogawaconan <me@myconan.net>
parents:
232
diff
changeset
|
19 if (hash === "#pl") { hash = " " } |
214
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
20 history.replaceState(null, "", hash) |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
21 }, |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
22 init: function() { |
232
e3468efc9ec9
Do check if we're on the right place
Edho Arief <edho@myconan.net>
parents:
224
diff
changeset
|
23 if (!$("#paste").length) return |
214
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
24 this.load_hash() |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
25 if (history.replaceState) { |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
26 this.set_hash() |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
27 $(document).on('click', $.proxy(this.set_hash, this)) |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
28 } |
22c4b5f90e24
Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
29 } |
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 })(jQuery) |