comparison 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
comparison
equal deleted inserted replaced
262:45bd94c70896 263:a9c45375a656
1 //= require zp.formatter 1 //= require zp.formatter
2 //= require zp.viewer_width
3 (function($) { 2 (function($) {
4 window.zp.hash_magic = { 3 window.zp.hash_magic = {
5 load_hash: function() { 4 load_hash: function() {
6 var hash_array = window.location.hash.slice(2).split(".") 5 var format = window.location.hash.slice(1)
7 format = hash_array[0]
8 width = hash_array[1]
9 if (format !== undefined) { 6 if (format !== undefined) {
10 zp.formatter.links().filter("[href=#" + format + "]").click() 7 zp.formatter.links().filter("[href=#" + format + "]").click()
11 }
12 if (width !== undefined) {
13 zp.viewer_width.resize(width)
14 } 8 }
15 }, 9 },
16 set_hash: function(e) { 10 set_hash: function(e) {
17 if (typeof e !== "undefined") { 11 if (typeof e !== "undefined") {
18 if (zp.formatter.links().filter(e.target).length === 0 && 12 if (zp.formatter.links().filter(e.target).length === 0) return
19 zp.viewer_width.links().filter(e.target).length === 0) { return }
20 else e.preventDefault() 13 else e.preventDefault()
21 } 14 }
22 var 15 var
23 format = zp.formatter.current(), 16 format = zp.formatter.current(),
24 width = zp.viewer_width.current, 17 hash = "#"
25 hash = "#!"
26 hash += format 18 hash += format
27 if (width !== "auto") { hash += "." + width } 19 if (hash === "#pl") { hash = " " }
28 if (hash === "#!pl") { hash = " " }
29 history.replaceState(null, "", hash) 20 history.replaceState(null, "", hash)
30 }, 21 },
31 init: function() { 22 init: function() {
32 if (!$("#paste").length) return 23 if (!$("#paste").length) return
33 this.load_hash() 24 this.load_hash()