aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2011-02-04 16:42:21 -0800
committerMisko Hevery2011-02-16 00:48:22 -0500
commita004d487c4bb48b2bec19b60bc5ddc5244029be5 (patch)
tree48fe97cf0c79dc7126e7bfc5a40441738cb8dbab
parent037f30a0c9f819aedf47f0da782e8d1fec0d6489 (diff)
downloadangular.js-a004d487c4bb48b2bec19b60bc5ddc5244029be5.tar.bz2
allow jquery to be declared after angular in the script loading order
-rw-r--r--src/Angular.js14
-rw-r--r--src/AngularPublic.js5
-rw-r--r--src/angular.suffix2
-rw-r--r--src/jqLite.js3
-rw-r--r--src/scenario/angular.suffix2
-rw-r--r--test/testabilityPatch.js2
6 files changed, 21 insertions, 7 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 4187e9ad..b856aa24 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -83,17 +83,16 @@ var _undefined = undefined,
PRIORITY_LAST = 99999,
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
Error = window.Error,
- jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
- _ = window['_'],
/** holds major version number for IE or NaN for real browsers */
msie = parseInt((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1], 10),
- jqLite = jQuery || jqLiteWrap,
+ jqLite, // delay binding since jQuery could be loaded after us.
+ jQuery, // delay binding
slice = Array.prototype.slice,
push = Array.prototype.push,
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
/** @name angular */
- angular = window[$angular] || (window[$angular] = {}),
+ angular = window[$angular] || (window[$angular] = {}),
/** @name angular.markup */
angularTextMarkup = extensionMap(angular, 'markup'),
/** @name angular.attrMarkup */
@@ -1006,6 +1005,7 @@ function angularInit(config){
}
function angularJsConfig(document, config) {
+ bindJQuery();
var scripts = document.getElementsByTagName("script"),
match;
config = extend({
@@ -1028,3 +1028,9 @@ function angularJsConfig(document, config) {
}
return config;
}
+
+function bindJQuery(){
+ // bind to jQuery if present;
+ jQuery = window.jQuery;
+ angular.element = jqLite = jQuery || jqLiteWrap;
+}
diff --git a/src/AngularPublic.js b/src/AngularPublic.js
index 4654acb1..b62483f8 100644
--- a/src/AngularPublic.js
+++ b/src/AngularPublic.js
@@ -46,3 +46,8 @@ extend(angular, {
'isArray': isArray
});
+//try to bind to jquery now so that one can write angular.element().read()
+//but we will rebind on bootstrap again.
+bindJQuery();
+
+
diff --git a/src/angular.suffix b/src/angular.suffix
index 3da27dc0..fcd3e577 100644
--- a/src/angular.suffix
+++ b/src/angular.suffix
@@ -1,5 +1,5 @@
- jqLite(document).ready(function(){
+ jqLiteWrap(document).ready(function(){
angularInit(angularJsConfig(document));
});
diff --git a/src/jqLite.js b/src/jqLite.js
index b607c095..ad7734c9 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -97,7 +97,8 @@ JQLite.prototype = {
}
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
- jqLite(window).bind('load', trigger); // fallback to window.onload for others
+ // we can not use jqLite since we are not done loading and jQuery could be loaded later.
+ new JQLite(window).bind('load', trigger); // fallback to window.onload for others
},
bind: function(type, fn){
diff --git a/src/scenario/angular.suffix b/src/scenario/angular.suffix
index f3ef9f0d..3ab796d2 100644
--- a/src/scenario/angular.suffix
+++ b/src/scenario/angular.suffix
@@ -1,6 +1,6 @@
var $scenario = new angular.scenario.Runner(window);
- jqLite(document).ready(function() {
+ jqLiteWrap(document).ready(function() {
angularScenarioInit($scenario, angularJsConfig(document));
});
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index e0086b8a..32272a4d 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -26,6 +26,8 @@ if (window.jstestdriver) {
beforeEach(function(){
// This is to reset parsers global cache of expressions.
compileCache = {};
+ // reset to jQuery or default to us.
+ bindJQuery();
this.addMatchers({
toBeInvalid: function(){
var element = jqLite(this.actual);