view app/assets/javascripts/zp.hash_magic.js @ 347:3ce44f960d3a

coffee: autosize_box_fix.
author edogawaconan <me@myconan.net>
date Thu, 03 Jul 2014 14:53:46 +0900
parents 4b91c0c1938c
children
line wrap: on
line source

//= require zp.formatter
(function($) {
  window.zp.hash_magic = {
    load_hash: function() {
      var
        format = window.location.hash.slice(1),
        tab_link = function(fmt) {
                     return zp.formatter.links().filter("[href='#" + fmt + "']")
                   }
      if(!tab_link(format).length) format = "pl"
      tab_link(format).click()
    },
    set_hash: function(e) {
      var
        format = zp.formatter.current(),
        newpath = window.location.pathname
      if (format !== "pl") { newpath += "#" + format }
      history.replaceState(null, "", newpath)
    },
    init: function() {
      if (!$("#paste").length) return
      this.load_hash()
      if (history.replaceState) {
        this.set_hash()
        zp.formatter.links().on('shown.bs.tab', this.set_hash)
      }
    }
  }
})(jQuery)