-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-routeblocker.min.js
7 lines (7 loc) · 1.6 KB
/
angular-routeblocker.min.js
1
2
3
4
5
6
7
/*
* angular-routeblocker 0.0.3
* https://github.com/kirstein/angular-routeblocker
*
* Licensed under the MIT license
*/
!function(a){"use strict";function b(a,b){b="^"+b.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")+"$";for(var c,d="",e=/:(\w+)/g,f=0;null!==(c=e.exec(b));)d+=b.slice(f,c.index),d+="([^\\/]*)",f=e.lastIndex;return d+=b.substr(f),!!a.match(new RegExp(d))}function c(a){var b=a.port(),c=a.protocol();return b=g[c]===b?"":":"+b,c+"://"+a.host()+b}function d(a,b){var d=c(a,b),e=b.substring(d.length);return e.replace(h,"/")}function e(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1}function f(b,c){var d=[];return a.forEach(b,function(b){var e=c[b];(a.isArray(e)||a.isFunction(e))&&d.push(e)}),d}var g={http:80,https:443},h=/^(([^\#]*?)(#[^\/]*?))\/(\?.*)?/,i="block",j=a.module("ngRouteBlocker",[]);j.provider("$routeBlocker",function(){var b=[i];this.removeProperty=function(c){if(c){if(a.isArray(c))return this.removeProperty.apply(this,c);a.forEach(b,function(a,b,d){a===c&&d.splice(b,1)})}},this.getProperties=function(){return b},this.addProperty=function(c){return a.forEach([].concat(c),function(c){if(!a.isString(c))throw new Error("Invalid RouteBlocker property name");e(b,c)||b.push(c)}),b},this.$get=function(){return{getProperties:this.getProperties}}}),j.run(["$routeBlocker","$location","$route","$rootScope","$injector",function(c,e,g,h,i){var j=c.getProperties();j.length&&h.$on("$locationChangeStart",function(c,h){var k=!1,l=d(e,h);a.forEach(g.routes,function(d,e){var g=f(j,d);!k&&g.length&&b(l,e)&&a.forEach(g,function(a){k||i.invoke(a)||(k=!0,c.preventDefault())})})})}])}(angular);