diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/assets/javascripts/zp.hash_magic.js	Sun May 12 02:43:38 2013 +0900
@@ -0,0 +1,35 @@
+//= require zp.formatter
+//= require zp.viewer_width
+(function($) {
+  window.zp.hash_magic = {
+    load_hash: function() {
+      var hash_array = window.location.hash.slice(2).split(".")
+      format = hash_array[0]
+      width = hash_array[1]
+      if (format !== undefined) {
+        zp.formatter.links().filter("[href=#" + format + "]").click()
+      }
+      if (width !== undefined) {
+        zp.viewer_width.resize(width)
+      }
+    },
+    set_hash: function(e) {
+      var
+        format = zp.formatter.current(),
+        width = zp.viewer_width.current,
+        hash = "#!"
+      hash += format
+      if (width !== "auto") { hash += "." + width }
+      if (hash === "#!pl") { hash = " " }
+      history.replaceState(null, "", hash)
+      if (e !== undefined) { e.preventDefault() }
+    },
+    init: function() {
+      this.load_hash()
+      if (history.replaceState) {
+        this.set_hash()
+        $(document).on('click', $.proxy(this.set_hash, this))
+      }
+    }
+  }
+})(jQuery)