Navigation Menu

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

Commit

Permalink
fix(ngJq): properly detect when ng-jq is empty
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gkalpak authored and Narretz committed Sep 14, 2015
1 parent 30aa3ef commit 19ecdb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Angular.js
Expand Up @@ -1673,10 +1673,9 @@ function bindJQuery() {

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

// Use jQuery if it exists with proper functionality, otherwise default to us.
// Angular 1.2+ requires jQuery 1.7+ for on()/off() support.
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/fixtures/ngJq/index.html
Expand Up @@ -4,6 +4,11 @@
{{jqueryVersion}}

<script src="../../../../bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript">
// Verify that empty ng-jq is not accessing `window['']`.
// (See https://github.com/angular/angular.js/issues/12741 for more details)
window[''] = window.jQuery;
</script>
<script src="angular.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
Expand Down

0 comments on commit 19ecdb5

Please sign in to comment.