(function () { "use strict"; angular .module("app.utils") .service("appUtils.stateHandler", stateHandler); function stateHandler() { return { save: saveHash, goto: goToHash }; // Public methods. function saveHash(){ localStorage.hashUrl = location.hash; if (document && document.cookie) { document.cookie = "hashUrl=" + location.hash; } } function goToHash(){ //location.hash = url != "#/login" ? url : "#/main/users/:0"; var hash = getCookie("hashUrl") || localStorage.hashUrl; location.hash = hash != "#/login" ? hash : "#/main/users/:0"; } // Internal methods. function getCookie(name) { var matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" )); return matches ? decodeURIComponent(matches[1]) : undefined; } } // IoC container. stateHandler.$inject = []; })();