From 5d09a1efd3ff98fc2fbba2f8f64230704f4a5e96 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 8 Mar 2012 15:42:35 -0800 Subject: fix(ng-view, ng-include): onload and $contentLoaded - change custom onload directive to special arguments recongnized by both ng-view and ng-include - rename $contentLoaded event to $viewContentLoaded and $includeContentLoaded - add event docs --- src/AngularPublic.js | 1 - src/directive/ngInclude.js | 14 +++++++++++++- src/directive/ngView.js | 30 +++++++++++++++--------------- 3 files changed, 28 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/AngularPublic.js b/src/AngularPublic.js index 8ee8bc06..5bc59653 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -69,7 +69,6 @@ function publishExternalAPI(angular){ script: scriptDirective, select: selectDirective, style: styleDirective, - onload: onloadDirective, option: optionDirective, ngBind: ngBindDirective, ngBindHtml: ngBindHtmlDirective, diff --git a/src/directive/ngInclude.js b/src/directive/ngInclude.js index 08b14488..68a03d35 100644 --- a/src/directive/ngInclude.js +++ b/src/directive/ngInclude.js @@ -63,6 +63,16 @@ */ + + +/** + * @ngdoc event + * @name angular.module.ng.$compileProvider.directive.ng:include#$includeContentLoaded + * @eventOf angular.module.ng.$compileProvider.directive.ng:include + * @eventType emit on the current ng:include scope + * @description + * Emitted every time the ng:include content is reloaded. + */ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile', function($http, $templateCache, $anchorScroll, $compile) { return { @@ -70,6 +80,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile' compile: function(element, attr) { var srcExp = attr.src, scopeExp = attr.scope || '', + onloadExp = attr.onload || '', autoScrollExp = attr.autoscroll; return function(scope, element, attr) { @@ -106,7 +117,8 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile' if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { $anchorScroll(); } - scope.$emit('$contentLoaded'); + scope.$emit('$includeContentLoaded'); + scope.$eval(onloadExp); } }).error(clearContent); } else { diff --git a/src/directive/ngView.js b/src/directive/ngView.js index 3c589354..74528ad9 100644 --- a/src/directive/ngView.js +++ b/src/directive/ngView.js @@ -93,6 +93,16 @@ */ + + +/** + * @ngdoc event + * @name angular.module.ng.$compileProvider.directive.ng:view#$viewContentLoaded + * @eventOf angular.module.ng.$compileProvider.directive.ng:view + * @eventType emit on the current ng:view scope + * @description + * Emitted every time the ng:view content is reloaded. + */ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$compile', '$controller', function($http, $templateCache, $route, $anchorScroll, $compile, @@ -100,9 +110,10 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c return { restrict: 'ECA', terminal: true, - link: function(scope, element) { + link: function(scope, element, attr) { var changeCounter = 0, - lastScope; + lastScope, + onloadExp = attr.onload || ''; scope.$on('$afterRouteChange', function(event, next, previous) { changeCounter++; @@ -142,7 +153,8 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c } link(lastScope); - lastScope.$emit('$contentLoaded'); + lastScope.$emit('$viewContentLoaded'); + lastScope.$eval(onloadExp); // $anchorScroll might listen on event... $anchorScroll(); @@ -155,15 +167,3 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c } }; }]; - - -var onloadDirective = valueFn({ - restrict: 'AC', - link: function(scope, elm, attr) { - var onloadExp = attr.onload || ''; //workaround for jquery bug #7537) - - scope.$on('$contentLoaded', function(event) { - scope.$eval(onloadExp); - }); - } -}); -- cgit v1.2.3