Skip to content

Commit

Permalink
release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Jan 19, 2017
1 parent 2f81a0b commit 25614ee
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 13 deletions.
93 changes: 83 additions & 10 deletions release/angular-ui-router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* State-based routing for AngularJS
* @version v0.3.2
* @version v0.4.0
* @link http://angular-ui.github.com/
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
Expand Down Expand Up @@ -563,6 +563,57 @@ function $Resolve( $q, $injector) {
angular.module('ui.router.util').service('$resolve', $Resolve);



/**
* @ngdoc object
* @name ui.router.util.$templateFactoryProvider
*
* @description
* Provider for $templateFactory. Manages which template-loading mechanism to
* use, and will default to the most recent one ($templateRequest on Angular
* versions starting from 1.3, $http otherwise).
*/
function TemplateFactoryProvider() {
var shouldUnsafelyUseHttp = angular.version.minor < 3;

/**
* @ngdoc function
* @name ui.router.util.$templateFactoryProvider#shouldUnsafelyUseHttp
* @methodOf ui.router.util.$templateFactoryProvider
*
* @description
* Forces $templateFactory to use $http instead of $templateRequest. This
* might cause XSS, as $http doesn't enforce the regular security checks for
* templates that have been introduced in Angular 1.3. Note that setting this
* to false on Angular older than 1.3.x will crash, as the $templateRequest
* service (and the security checks) are not implemented on these versions.
*
* See the $sce documentation, section
* <a href="https://docs.angularjs.org/api/ng/service/$sce#impact-on-loading-templates">
* Impact on loading templates</a> for more details about this mechanism.
*
* @param {boolean} value
*/
this.shouldUnsafelyUseHttp = function(value) {
shouldUnsafelyUseHttp = !!value;
};

/**
* @ngdoc object
* @name ui.router.util.$templateFactory
*
* @requires $http
* @requires $templateCache
* @requires $injector
*
* @description
* Service. Manages loading of templates.
*/
this.$get = ['$http', '$templateCache', '$injector', function($http, $templateCache, $injector){
return new TemplateFactory($http, $templateCache, $injector, shouldUnsafelyUseHttp);}];
}


/**
* @ngdoc object
* @name ui.router.util.$templateFactory
Expand All @@ -574,8 +625,7 @@ angular.module('ui.router.util').service('$resolve', $Resolve);
* @description
* Service. Manages loading of templates.
*/
$TemplateFactory.$inject = ['$http', '$templateCache', '$injector'];
function $TemplateFactory( $http, $templateCache, $injector) {
function TemplateFactory($http, $templateCache, $injector, shouldUnsafelyUseHttp) {

/**
* @ngdoc function
Expand Down Expand Up @@ -647,9 +697,15 @@ function $TemplateFactory( $http, $templateCache, $injector) {
this.fromUrl = function (url, params) {
if (isFunction(url)) url = url(params);
if (url == null) return null;
else return $http
.get(url, { cache: $templateCache, headers: { Accept: 'text/html' }})
.then(function(response) { return response.data; });
else {
if(!shouldUnsafelyUseHttp) {
return $injector.get('$templateRequest')(url);
} else {
return $http
.get(url, { cache: $templateCache, headers: { Accept: 'text/html' }})
.then(function(response) { return response.data; });
}
}
};

/**
Expand All @@ -672,7 +728,7 @@ function $TemplateFactory( $http, $templateCache, $injector) {
};
}

angular.module('ui.router.util').service('$templateFactory', $TemplateFactory);
angular.module('ui.router.util').provider('$templateFactory', TemplateFactoryProvider);

var $$UMFP; // reference to $UrlMatcherFactoryProvider

Expand Down Expand Up @@ -1286,7 +1342,7 @@ function $UrlMatcherFactory() {
"int": {
encode: valToString,
decode: function(val) { return parseInt(val, 10); },
is: function(val) { return isDefined(val) && this.decode(val.toString()) === val; },
is: function(val) { return val !== undefined && val !== null && this.decode(val.toString()) === val; },
pattern: /\d+/
},
"bool": {
Expand Down Expand Up @@ -3409,6 +3465,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
return $q.reject(error);
});

transition.catch(angular.noop);
return transition;
};

Expand Down Expand Up @@ -3452,7 +3509,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {

if (!isDefined(state)) { return undefined; }
if ($state.$current !== state) { return false; }
return params ? equalForKeys(state.params.$$values(params), $stateParams) : true;

return !params || objectKeys(params).reduce(function(acc, key) {
var paramDef = state.params[key];
return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]);
}, true);
};

/**
Expand Down Expand Up @@ -3528,7 +3589,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
}
}

return true;
return objectKeys(params).reduce(function(acc, key) {
var paramDef = state.params[key];
return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]);
}, true);
};


Expand Down Expand Up @@ -4105,12 +4169,21 @@ function $ViewDirectiveFill ( $compile, $controller, $state, $interpolate
priority: -400,
compile: function (tElement) {
var initial = tElement.html();
if (tElement.empty) {
tElement.empty();
} else {
// ng 1.0.0 doesn't have empty(), which cleans up data and handlers
tElement[0].innerHTML = null;
}

return function (scope, $element, attrs) {
var current = $state.$current,
name = getUiViewName(scope, attrs, $element, $interpolate),
locals = current && current.locals[name];

if (! locals) {
$element.html(initial);
$compile($element.contents())(scope);
return;
}

Expand Down
Loading

0 comments on commit 25614ee

Please sign in to comment.