From 753fc9e58d5e554d4930548558efecc283557eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Borgesen?= Date: Wed, 6 Feb 2013 12:15:18 +0100 Subject: [PATCH] feat(JQLite): ready() now supports document.readyState=='complete' JQLite.ready() used for automatic bootstrapping (when jQuery is not present) now checks if document already is ready when first called. This simplifies bootstrapping when the angular script is loaded asynchronously. However if other scripts with angular app code are being loaded as well it is developers responsibility to ensure that these scripts are loaded after angular-loader.js is evaluated and before angular.js script is evaluated. --- docs/content/guide/bootstrap.ngdoc | 9 ++++----- src/jqLite.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/content/guide/bootstrap.ngdoc b/docs/content/guide/bootstrap.ngdoc index 3be24bb56281..f1a465172647 100644 --- a/docs/content/guide/bootstrap.ngdoc +++ b/docs/content/guide/bootstrap.ngdoc @@ -48,11 +48,10 @@ initialization. # Automatic Initialization -Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for -the {@link api/ng.directive:ngApp `ng-app`} directive which -designates your application root. If the {@link -api/ng.directive:ngApp `ng-app`} directive is found then Angular -will: +Angular initializes automatically upon `DOMContentLoaded` event or when the `angular.js` script is +evaluated if at that time `document.readyState` is set to `'complete'`. At this point Angular looks +for the {@link api/ng.directive:ngApp `ng-app`} directive which designates your application root. +If the {@link api/ng.directive:ngApp `ng-app`} directive is found then Angular will: * load the {@link guide/module module} associated with the directive. * create the application {@link api/AUTO.$injector injector} diff --git a/src/jqLite.js b/src/jqLite.js index 1d92f2ab0d55..2c209ecde516 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -327,9 +327,14 @@ var JQLitePrototype = JQLite.prototype = { fn(); } - this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9 - // we can not use jqLite since we are not done loading and jQuery could be loaded later. - JQLite(window).bind('load', trigger); // fallback to window.onload for others + // check if document already is loaded + if (document.readyState === 'complete'){ + setTimeout(trigger); + } else { + this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9 + // we can not use jqLite since we are not done loading and jQuery could be loaded later. + JQLite(window).bind('load', trigger); // fallback to window.onload for others + } }, toString: function() { var value = [];