mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-06 23:07:56 +08:00
7 lines
961 B
JavaScript
7 lines
961 B
JavaScript
/*!
|
|
* Hasher <http://github.com/millermedeiros/hasher>
|
|
* @author Miller Medeiros
|
|
* @version 1.1.2 (2012/10/31 03:19 PM)
|
|
* Released under the MIT License
|
|
*/
|
|
(e=>{var i,a,n=signals.Signal,s=/#(.*)$/,h=/^#/;const t=e=>e?e.replace(new RegExp("^\\/|\\$","g"),""):"",o=()=>{var i=s.exec(e.location.href);return i&&i[1]?decodeURIComponent(i[1]):""},c=e=>{if(i!==e){var a=i;i=e,l.changed.dispatch(t(e),t(a))}},d=()=>{var e=o();e!==i&&c(e)},r=e=>(e=e.join("/"))?"/"+e.replace(h,""):e,l={changed:new n,initialized:new n,init:()=>{a||(i=o(),e.addEventListener("hashchange",d),a=!0,l.initialized.dispatch(t(i)))},stop:()=>{a&&(e.removeEventListener("hashchange",d),a=!1)},setHash:(...a)=>{(a=r(a))!==i&&(c(a),a===i&&(e.location.hash="#"+encodeURI(a)))},replaceHash:(...a)=>{(a=r(a))!==i&&(c(a),a===i&&e.location.replace("#"+encodeURI(a)))},dispose:()=>{l.stop(),l.initialized.dispose(),l.changed.dispose(),e.hasher=null}};l.initialized.memorize=!0,e.hasher=l})(this);
|