view 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
line wrap: on
line source

//= require zp.formatter
(function($) {
  window.zp.hash_magic = {
    load_hash: function() {
      var format = window.location.hash.slice(1)
      if (format !== undefined) {
        zp.formatter.links().filter("[href=#" + format + "]").click()
      }
    },
    set_hash: function(e) {
      if (typeof e !== "undefined") {
        if (zp.formatter.links().filter(e.target).length === 0) return
        else e.preventDefault()
      }
      var
        format = zp.formatter.current(),
        hash = "#"
      hash += format
      if (hash === "#pl") { hash = " " }
      history.replaceState(null, "", hash)
    },
    init: function() {
      if (!$("#paste").length) return
      this.load_hash()
      if (history.replaceState) {
        this.set_hash()
        $(document).on('click', $.proxy(this.set_hash, this))
      }
    }
  }
})(jQuery)