Mercurial > zeropaste
view app/assets/javascripts/zp.hash_magic.js @ 331:7c7b7906ebd9
Some more coding style.
author | edogawaconan <me@myconan.net> |
---|---|
date | Mon, 14 Apr 2014 17:21:16 +0900 |
parents | e855e58d137e |
children | 4b91c0c1938c |
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) { if (typeof e !== "undefined") { if (zp.formatter.links().filter(e.target).length === 0) return else e.preventDefault() } 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() $(document).on('click', $.proxy(this.set_hash, this)) } } } })(jQuery)