Skip to content

Commit

Permalink
Set up an event listener on {appFrame}.document.body if the angular-s…
Browse files Browse the repository at this point in the history
…cenario.angularInit() fails to connect.

Make sure the manual bootstrap fires the above event.
  • Loading branch information
chrismilleruk committed Mar 20, 2013
1 parent dd547fa commit 641f992
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 9 additions & 2 deletions app/lib/angular/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,9 @@ function encodeUriQuery(val, pctEncodeSpaces) {
</doc:example>
*
*/
function angularInit(element, bootstrap) {
function angularInit(element, callback, errCallback) {
var elements = [element],
document = element.ownerDocument || element,
appElement,
module,
names = ['ng:app', 'ng-app', 'x-ng-app', 'data-ng-app'],
Expand Down Expand Up @@ -933,7 +934,9 @@ function angularInit(element, bootstrap) {
}
});
if (appElement) {
bootstrap(appElement, module ? [module] : []);
callback(appElement, module ? [module] : []);
} else if (callback !== bootstrap && errCallback) {
errCallback();
}
}

Expand Down Expand Up @@ -968,6 +971,10 @@ function bootstrap(element, modules) {
var cls = ': ' + modules[2] + ';';
cls = 'ng-app' + (cls||'');
element.addClass(cls);

// ..when it has already run.
var document = element[0].ownerDocument || element[0];
JQLite(document.body).triggerHandler('ngBootstrap');
});
}]
);
Expand Down
18 changes: 15 additions & 3 deletions test/lib/angular/angular-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -10298,8 +10298,9 @@ function encodeUriQuery(val, pctEncodeSpaces) {
</doc:example>
*
*/
function angularInit(element, bootstrap) {
function angularInit(element, callback, errCallback) {
var elements = [element],
document = element.ownerDocument || element,
appElement,
module,
names = ['ng:app', 'ng-app', 'x-ng-app', 'data-ng-app'],
Expand Down Expand Up @@ -10338,7 +10339,9 @@ function angularInit(element, bootstrap) {
}
});
if (appElement) {
bootstrap(appElement, module ? [module] : []);
callback(appElement, module ? [module] : []);
} else if (callback !== bootstrap && errCallback) {
errCallback();
}
}

Expand Down Expand Up @@ -10373,6 +10376,10 @@ function bootstrap(element, modules) {
var cls = ': ' + modules[2] + ';';
cls = 'ng-app' + (cls||'');
element.addClass(cls);

// ..when it has already run.
var document = element[0].ownerDocument || element[0];
JQLite(document.body).triggerHandler('ngBootstrap');
});
}]
);
Expand Down Expand Up @@ -24637,7 +24644,7 @@ angular.scenario.Application.prototype.executeAction = function(action) {
if (!$window.angular) {
return action.call(this, $window, _jQuery($window.document));
}
angularInit($window.document, function(element) {
var scenarioBootstrap = function(element) {
var $injector = $window.angular.element(element).injector();
var $element = _jQuery(element);

Expand All @@ -24650,6 +24657,11 @@ angular.scenario.Application.prototype.executeAction = function(action) {
action.call(self, $window, $element);
});
});
};
angularInit($window.document, scenarioBootstrap, function(){
$window.angular.element($window.document.body).bind('ngBootstrap', function(){
angularInit($window.document, scenarioBootstrap);
});
});
};

Expand Down

0 comments on commit 641f992

Please sign in to comment.