Mercurial > zeropaste
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 213:0993715b455d | 214:22c4b5f90e24 |
|---|---|
| 1 //= require zp.formatter | |
| 2 //= require zp.viewer_width | |
| 3 (function($) { | |
| 4 window.zp.hash_magic = { | |
| 5 load_hash: function() { | |
| 6 var hash_array = window.location.hash.slice(2).split(".") | |
| 7 format = hash_array[0] | |
| 8 width = hash_array[1] | |
| 9 if (format !== undefined) { | |
| 10 zp.formatter.links().filter("[href=#" + format + "]").click() | |
| 11 } | |
| 12 if (width !== undefined) { | |
| 13 zp.viewer_width.resize(width) | |
| 14 } | |
| 15 }, | |
| 16 set_hash: function(e) { | |
| 17 var | |
| 18 format = zp.formatter.current(), | |
| 19 width = zp.viewer_width.current, | |
| 20 hash = "#!" | |
| 21 hash += format | |
| 22 if (width !== "auto") { hash += "." + width } | |
| 23 if (hash === "#!pl") { hash = " " } | |
| 24 history.replaceState(null, "", hash) | |
| 25 if (e !== undefined) { e.preventDefault() } | |
| 26 }, | |
| 27 init: function() { | |
| 28 this.load_hash() | |
| 29 if (history.replaceState) { | |
| 30 this.set_hash() | |
| 31 $(document).on('click', $.proxy(this.set_hash, this)) | |
| 32 } | |
| 33 } | |
| 34 } | |
| 35 })(jQuery) |
