Skip to content

Commit a004d48

Browse files
committed
allow jquery to be declared after angular in the script loading order
1 parent 037f30a commit a004d48

6 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/Angular.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ var _undefined = undefined,
8383
PRIORITY_LAST = 99999,
8484
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
8585
Error = window.Error,
86-
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
87-
_ = window['_'],
8886
/** holds major version number for IE or NaN for real browsers */
8987
msie = parseInt((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1], 10),
90-
jqLite = jQuery || jqLiteWrap,
88+
jqLite, // delay binding since jQuery could be loaded after us.
89+
jQuery, // delay binding
9190
slice = Array.prototype.slice,
9291
push = Array.prototype.push,
9392
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
9493

9594
/** @name angular */
96-
angular = window[$angular] || (window[$angular] = {}),
95+
angular = window[$angular] || (window[$angular] = {}),
9796
/** @name angular.markup */
9897
angularTextMarkup = extensionMap(angular, 'markup'),
9998
/** @name angular.attrMarkup */
@@ -1006,6 +1005,7 @@ function angularInit(config){
10061005
}
10071006

10081007
function angularJsConfig(document, config) {
1008+
bindJQuery();
10091009
var scripts = document.getElementsByTagName("script"),
10101010
match;
10111011
config = extend({
@@ -1028,3 +1028,9 @@ function angularJsConfig(document, config) {
10281028
}
10291029
return config;
10301030
}
1031+
1032+
function bindJQuery(){
1033+
// bind to jQuery if present;
1034+
jQuery = window.jQuery;
1035+
angular.element = jqLite = jQuery || jqLiteWrap;
1036+
}

src/AngularPublic.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ extend(angular, {
4646
'isArray': isArray
4747
});
4848

49+
//try to bind to jquery now so that one can write angular.element().read()
50+
//but we will rebind on bootstrap again.
51+
bindJQuery();
52+
53+

src/angular.suffix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
jqLite(document).ready(function(){
2+
jqLiteWrap(document).ready(function(){
33
angularInit(angularJsConfig(document));
44
});
55

src/jqLite.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ JQLite.prototype = {
9797
}
9898

9999
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
100-
jqLite(window).bind('load', trigger); // fallback to window.onload for others
100+
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
101+
new JQLite(window).bind('load', trigger); // fallback to window.onload for others
101102
},
102103

103104
bind: function(type, fn){

src/scenario/angular.suffix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var $scenario = new angular.scenario.Runner(window);
22

3-
jqLite(document).ready(function() {
3+
jqLiteWrap(document).ready(function() {
44
angularScenarioInit($scenario, angularJsConfig(document));
55
});
66

test/testabilityPatch.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ if (window.jstestdriver) {
2626
beforeEach(function(){
2727
// This is to reset parsers global cache of expressions.
2828
compileCache = {};
29+
// reset to jQuery or default to us.
30+
bindJQuery();
2931
this.addMatchers({
3032
toBeInvalid: function(){
3133
var element = jqLite(this.actual);

0 commit comments

Comments
 (0)