annotate app/assets/javascripts/zp.hash_magic.js @ 214:22c4b5f90e24

Massive javascript and html refactor. Also, ie9
author Edho Arief <edho@myconan.net>
date Sun, 12 May 2013 02:43:38 +0900
parents
children 45ccec189bd7
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 //= require zp.viewer_width
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
3 (function($) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
4 window.zp.hash_magic = {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
5 load_hash: function() {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
6 var hash_array = window.location.hash.slice(2).split(".")
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
7 format = hash_array[0]
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
8 width = hash_array[1]
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
9 if (format !== undefined) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
10 zp.formatter.links().filter("[href=#" + format + "]").click()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
11 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
12 if (width !== undefined) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
13 zp.viewer_width.resize(width)
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
14 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
15 },
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
16 set_hash: function(e) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
17 var
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
18 format = zp.formatter.current(),
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
19 width = zp.viewer_width.current,
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
20 hash = "#!"
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 hash += format
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
22 if (width !== "auto") { hash += "." + width }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 if (hash === "#!pl") { hash = " " }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
24 history.replaceState(null, "", hash)
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 if (e !== undefined) { e.preventDefault() }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
26 },
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
27 init: function() {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 this.load_hash()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
29 if (history.replaceState) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 this.set_hash()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
31 $(document).on('click', $.proxy(this.set_hash, this))
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 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
34 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 })(jQuery)