# HG changeset patch # User edogawaconan # Date 1404367414 -32400 # Node ID f802099acd374256882396e97fc9d79a4d0c5017 # Parent 55287d8a5a0406f704555c062fd253b1140ee705 coffee: hash_magic. diff -r 55287d8a5a04 -r f802099acd37 app/assets/javascripts/zp.hash_magic.js --- a/app/assets/javascripts/zp.hash_magic.js Thu Jul 03 14:59:21 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -//= 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) diff -r 55287d8a5a04 -r f802099acd37 app/assets/javascripts/zp.hash_magic.js.coffee --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/assets/javascripts/zp.hash_magic.js.coffee Thu Jul 03 15:03:34 2014 +0900 @@ -0,0 +1,21 @@ +#= require zp.formatter +window.zp.hash_magic = + load_hash: -> + format = window.location.hash.slice(1) + tab_link = (fmt) -> zp.formatter.links().filter("[href='##{fmt}']") + + format = "pl" unless tab_link(format).length + tab_link(format).click() + + set_hash: (e) -> + format = zp.formatter.current() + newpath = window.location.pathname + newpath += "##{format}" if (format != "pl") + history.replaceState null, "", newpath + + init: -> + return unless $("#paste").length + @load_hash() + if (history.replaceState) + @set_hash() + zp.formatter.links().on("shown.bs.tab", this.set_hash)