annotate app/assets/javascripts/zp.hash_magic.js @ 260:c4aba8990c5e

Fix new paste form.
author edogawaconan <me@myconan.net>
date Tue, 15 Oct 2013 21:52:08 +0900
parents e3468efc9ec9
children a9c45375a656
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) {
224
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
17 if (typeof e !== "undefined") {
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
18 if (zp.formatter.links().filter(e.target).length === 0 &&
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
19 zp.viewer_width.links().filter(e.target).length === 0) { return }
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
20 else e.preventDefault()
6e9718a1ee11 Combine event-related actions
Edho Arief <edho@myconan.net>
parents: 223
diff changeset
21 }
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
22 var
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 format = zp.formatter.current(),
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
24 width = zp.viewer_width.current,
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 hash = "#!"
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
26 hash += format
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
27 if (width !== "auto") { hash += "." + width }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 if (hash === "#!pl") { hash = " " }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
29 history.replaceState(null, "", hash)
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 init: function() {
232
e3468efc9ec9 Do check if we're on the right place
Edho Arief <edho@myconan.net>
parents: 224
diff changeset
32 if (!$("#paste").length) return
214
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
33 this.load_hash()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
34 if (history.replaceState) {
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 this.set_hash()
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
36 $(document).on('click', $.proxy(this.set_hash, this))
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
37 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
38 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
39 }
22c4b5f90e24 Massive javascript and html refactor. Also, ie9
Edho Arief <edho@myconan.net>
parents:
diff changeset
40 })(jQuery)