From c79aba92f6b058742c9ae20a9382f6abc68afcea Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Sun, 9 Jan 2011 00:57:24 -0800
Subject: bootstrap angular on "document ready" instead of window.onload
- use jqLite api to bootstrap angular
- when jQuery is present DOMContentLoaded or hacks for IE are used
- when jqLite is present DOMContentLoaded is used for modern browsers
and IE9 and window.onload is used for other browsers.
- test html for comparing DOMContentLoaded with window.onload
Closes #224
---
perf/DCLvsWindowOnLoad.html | 37 +++++++++++++++++++++++++++++++++++++
src/angular.prefix | 2 +-
src/angular.suffix | 9 +++------
src/jqLite.js | 13 +++++++++++++
src/scenario/angular.prefix | 2 +-
src/scenario/angular.suffix | 9 +++------
6 files changed, 58 insertions(+), 14 deletions(-)
create mode 100644 perf/DCLvsWindowOnLoad.html
diff --git a/perf/DCLvsWindowOnLoad.html b/perf/DCLvsWindowOnLoad.html
new file mode 100644
index 00000000..b44b9114
--- /dev/null
+++ b/perf/DCLvsWindowOnLoad.html
@@ -0,0 +1,37 @@
+
+
+
+
+
+ DOMContentLoaded test
+
+
+
+
+ DOMContentLoaded test
+ {{ 'yay!' || 'angular starting...' }}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/angular.prefix b/src/angular.prefix
index a1b4e151..be874795 100644
--- a/src/angular.prefix
+++ b/src/angular.prefix
@@ -21,4 +21,4 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-(function(window, document, previousOnLoad){
+(function(window, document){
diff --git a/src/angular.suffix b/src/angular.suffix
index 7e86c5d5..3da27dc0 100644
--- a/src/angular.suffix
+++ b/src/angular.suffix
@@ -1,9 +1,6 @@
- window.onload = function(){
- try {
- if (previousOnLoad) previousOnLoad();
- } catch(e) {}
+ jqLite(document).ready(function(){
angularInit(angularJsConfig(document));
- };
+ });
-})(window, document, window.onload);
+})(window, document);
diff --git a/src/jqLite.js b/src/jqLite.js
index cbba69ad..cbb2c7b8 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -87,6 +87,19 @@ JQLite.prototype = {
})(this[0]);
},
+ ready: function(fn) {
+ var fired = false;
+
+ function trigger() {
+ if (fired) return;
+ fired = true;
+ fn();
+ }
+
+ this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
+ jqLite(window).bind('load', trigger); // fallback to window.onload for others
+ },
+
bind: function(type, fn){
var self = this,
element = self[0],
diff --git a/src/scenario/angular.prefix b/src/scenario/angular.prefix
index fb9ae147..03ab29cb 100644
--- a/src/scenario/angular.prefix
+++ b/src/scenario/angular.prefix
@@ -21,5 +21,5 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-(function(window, document, previousOnLoad){
+(function(window, document){
var _jQuery = window.jQuery.noConflict(true);
diff --git a/src/scenario/angular.suffix b/src/scenario/angular.suffix
index 66843013..f3ef9f0d 100644
--- a/src/scenario/angular.suffix
+++ b/src/scenario/angular.suffix
@@ -1,10 +1,7 @@
var $scenario = new angular.scenario.Runner(window);
- window.onload = function() {
- try {
- if (previousOnLoad) previousOnLoad();
- } catch(e) {}
+ jqLite(document).ready(function() {
angularScenarioInit($scenario, angularJsConfig(document));
- };
+ });
-})(window, document, window.onload);
+})(window, document);
--
cgit v1.2.3