Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 19ecdb5

Browse files
gkalpakNarretz
authored andcommitted
fix(ngJq): properly detect when ng-jq is empty
Previously, even when `ng-jq` was empty (which should force the use of jqLite), Angular tried to find jQuery on `window['']`. If it didn't find anything there, it would fall back to jqLite (as expected). Nonetheless, trying to access `window['']` calls `getElementById('')`, which issues a warning in Firefox (maybe others). This fix properly detects when `ng-jq` is empty and avoids trying to access `window['']`. Fixes #12741
1 parent 30aa3ef commit 19ecdb5

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Angular.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1673,10 +1673,9 @@ function bindJQuery() {
16731673

16741674
// bind to jQuery if present;
16751675
var jqName = jq();
1676-
jQuery = window.jQuery; // use default jQuery.
1677-
if (isDefined(jqName)) { // `ngJq` present
1678-
jQuery = jqName === null ? undefined : window[jqName]; // if empty; use jqLite. if not empty, use jQuery specified by `ngJq`.
1679-
}
1676+
jQuery = isUndefined(jqName) ? window.jQuery : // use jQuery (if present)
1677+
!jqName ? undefined : // use jqLite
1678+
window[jqName]; // use jQuery specified by `ngJq`
16801679

16811680
// Use jQuery if it exists with proper functionality, otherwise default to us.
16821681
// Angular 1.2+ requires jQuery 1.7+ for on()/off() support.

test/e2e/fixtures/ngJq/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
{{jqueryVersion}}
55

66
<script src="../../../../bower_components/jquery/dist/jquery.js"></script>
7+
<script type="text/javascript">
8+
// Verify that empty ng-jq is not accessing `window['']`.
9+
// (See https://github.com/angular/angular.js/issues/12741 for more details)
10+
window[''] = window.jQuery;
11+
</script>
712
<script src="angular.js"></script>
813
<script type="text/javascript" src="script.js"></script>
914
</body>

0 commit comments

Comments
 (0)