GeezerVison is showing github.com — feat(jQuery): upgrade to jQuery to 2.1.1 · wangjunji/angular.js@9e7cb3c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Gruntfile.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -161,7 +161,7 @@ module.exports = function(grunt) { | 161 | 161 | scenario: { | 162 | 162 | dest: 'build/angular-scenario.js', | 163 | 163 | src: [ | 164 | | - 'bower_components/jquery/jquery.js', | | 164 | + 'bower_components/jquery/dist/jquery.js', | 165 | 165 | util.wrap([files['angularSrc'], files['angularScenario']], 'ngScenario/angular') | 166 | 166 | ], | 167 | 167 | styles: { | |
Collapse file Copy file name to clipboardExpand all lines: angularFiles.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -143,7 +143,7 @@ var angularFiles = { | 143 | 143 | ], | 144 | 144 |
| 145 | 145 | 'karma': [ | 146 | | - 'bower_components/jquery/jquery.js', | | 146 | + 'bower_components/jquery/dist/jquery.js', | 147 | 147 | 'test/jquery_remove.js', | 148 | 148 | '@angularSrc', | 149 | 149 | 'src/publishExternalApis.js', | @@ -177,7 +177,7 @@ var angularFiles = { | 177 | 177 | ], | 178 | 178 |
| 179 | 179 | 'karmaJquery': [ | 180 | | - 'bower_components/jquery/jquery.js', | | 180 | + 'bower_components/jquery/dist/jquery.js', | 181 | 181 | 'test/jquery_alias.js', | 182 | 182 | '@angularSrc', | 183 | 183 | 'src/publishExternalApis.js', | |
Collapse file Copy file name to clipboardExpand all lines: bower.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "name": "AngularJS", | 3 | 3 | "devDependencies": { | 4 | | - "jquery": "1.10.2", | | 4 | + "jquery": "2.1.1", | 5 | 5 | "lunr.js": "0.4.3", | 6 | 6 | "open-sans-fontface": "1.0.4", | 7 | 7 | "google-code-prettify": "1.0.1", | |
Collapse file Copy file name to clipboardExpand all lines: docs/content/misc/faq.ngdoc +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,14 +75,15 @@ The size of the file is < 36KB compressed and minified. | 75 | 75 | Yes, you can use widgets from the [Closure Library](https://developers.google.com/closure/library/) | 76 | 76 | in Angular. | 77 | 77 |
| | 78 | + | 78 | 79 | ### Does Angular use the jQuery library? | 79 | 80 |
| 80 | 81 | Yes, Angular can use [jQuery](http://jquery.com/) if it's present in your app when the | 81 | 82 | application is being bootstrapped. If jQuery is not present in your script path, Angular falls back | 82 | 83 | to its own implementation of the subset of jQuery that we call {@link angular.element jQLite}. | 83 | 84 |
| 84 | | -Due to a change to use `on()`/`off()` rather than `bind()`/`unbind()`, Angular 1.2 only operates with | 85 | | -jQuery 1.7.1 or above. However, Angular does not currently support jQuery 2.x or above. | | 85 | +Angular 1.3 only supports jQuery 2.1 or above. jQuery 1.7 and newer might work correctly with Angular | | 86 | +but we don't guarantee that. | 86 | 87 |
| 87 | 88 |
| 88 | 89 | ### What is testability like in Angular? | |
Collapse file Copy file name to clipboardExpand all lines: docs/content/tutorial/step_12.ngdoc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,7 +104,8 @@ __`app/index.html`.__ | 104 | 104 | ``` | 105 | 105 |
| 106 | 106 | <div class="alert alert-error"> | 107 | | - **Important:** Be sure to use jQuery version `1.10.x`. AngularJS does not yet support jQuery `2.x`. | | 107 | + **Important:** Be sure to use jQuery version 2.1 or newer when using Angular 1.3; jQuery 1.x is | | 108 | + not officially supported. | 108 | 109 | Be sure to load jQuery before all AngularJS scripts, otherwise AngularJS won't detect jQuery and | 109 | 110 | animations will not work as expected. | 110 | 111 | </div> | |
Collapse file Copy file name to clipboardExpand all lines: src/Angular.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1459,7 +1459,9 @@ function bindJQuery() { | 1459 | 1459 | // bind to jQuery if present; | 1460 | 1460 | jQuery = window.jQuery; | 1461 | 1461 | // Use jQuery if it exists with proper functionality, otherwise default to us. | 1462 | | - // Angular 1.2+ requires jQuery 1.7.1+ for on()/off() support. | | 1462 | + // Angular 1.2+ requires jQuery 1.7+ for on()/off() support. | | 1463 | + // Angular 1.3+ technically requires at least jQuery 2.1+ but it may work with older | | 1464 | + // versions. It will not work for sure with jQuery <1.7, though. | 1463 | 1465 | if (jQuery && jQuery.fn.on) { | 1464 | 1466 | jqLite = jQuery; | 1465 | 1467 | extend(jQuery.fn, { | |
Collapse file Copy file name to clipboardExpand all lines: src/ng/compile.js +19-1Lines changed: 19 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2031,7 +2031,25 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | 2031 | 2031 | } | 2032 | 2032 | var fragment = document.createDocumentFragment(); | 2033 | 2033 | fragment.appendChild(firstElementToRemove); | 2034 | | - newNode[jqLite.expando] = firstElementToRemove[jqLite.expando]; | | 2034 | + | | 2035 | + // Copy over user data (that includes Angular's $scope etc.). Don't copy private | | 2036 | + // data here because there's no public interface in jQuery to do that and copying over | | 2037 | + // event listeners (which is the main use of private data) wouldn't work anyway. | | 2038 | + jqLite(newNode).data(jqLite(firstElementToRemove).data()); | | 2039 | + | | 2040 | + // Remove data of the replaced element. We cannot just call .remove() | | 2041 | + // on the element it since that would deallocate scope and event handlers that are still needed | | 2042 | + // for the new node. Instead, remove the data "manually". | | 2043 | + if (!jQuery) { | | 2044 | + delete jqLite.cache[firstElementToRemove[jqLite.expando]]; | | 2045 | + } else { | | 2046 | + // jQuery 2.x doesn't expose the data storage. Use jQuery.cleanData to clean up after the replaced | | 2047 | + // element. Note that we need to use the original method here and not the one monkey-patched by Angular | | 2048 | + // since the patched method emits the $destroy event causing the scope to be trashed and we do need | | 2049 | + // the very same scope to work with the new element. | | 2050 | + jQuery.cleanData.$$original([firstElementToRemove]); | | 2051 | + } | | 2052 | + | 2035 | 2053 | for (var k = 1, kk = elementsToRemove.length; k < kk; k++) { | 2036 | 2054 | var element = elementsToRemove[k]; | 2037 | 2055 | jqLite(element).remove(); // must do this way to clean up expando | |
Collapse file Copy file name to clipboardExpand all lines: src/ngMock/.jshintrc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | "browser": true, | 4 | 4 | "globals": { | 5 | 5 | "angular": false, | 6 | | - "expect": false | | 6 | + "expect": false, | | 7 | + "jQuery": false | 7 | 8 | } | 8 | 9 | } |
Collapse file Copy file name to clipboardExpand all lines: src/ngMock/angular-mocks.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1956,6 +1956,13 @@ angular.mock.e2e.$httpBackendDecorator = | 1956 | 1956 |
| 1957 | 1957 |
| 1958 | 1958 | angular.mock.clearDataCache = function() { | | 1959 | + // jQuery 2.x doesn't expose data attached to elements. We could use jQuery.cleanData | | 1960 | + // to clean up after elements but we'd first need to know which elements to clean up after. | | 1961 | + // Skip it then. | | 1962 | + if (window.jQuery) { | | 1963 | + return; | | 1964 | + } | | 1965 | + | 1959 | 1966 | var key, | 1960 | 1967 | cache = angular.element.cache; | 1961 | 1968 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/helpers/testabilityPatch.js +23-18Lines changed: 23 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,8 @@ beforeEach(function() { | 34 | 34 | }); | 35 | 35 |
| 36 | 36 | afterEach(function() { | | 37 | + var count, cache; | | 38 | + | 37 | 39 | if (this.$injector) { | 38 | 40 | var $rootScope = this.$injector.get('$rootScope'); | 39 | 41 | var $rootElement = this.$injector.get('$rootElement'); | @@ -46,25 +48,27 @@ afterEach(function() { | 46 | 48 | $log.assertEmpty && $log.assertEmpty(); | 47 | 49 | } | 48 | 50 |
| 49 | | - // complain about uncleared jqCache references | 50 | | - var count = 0; | | 51 | + if (!window.jQuery) { | | 52 | + // jQuery 2.x doesn't expose the cache storage. | 51 | 53 |
| 52 | | - // This line should be enabled as soon as this bug is fixed: http://bugs.jquery.com/ticket/11775 | 53 | | - //var cache = jqLite.cache; | 54 | | - var cache = angular.element.cache; | | 54 | + // complain about uncleared jqCache references | | 55 | + count = 0; | 55 | 56 |
| 56 | | - forEachSorted(cache, function(expando, key){ | 57 | | - angular.forEach(expando.data, function(value, key){ | 58 | | - count ++; | 59 | | - if (value && value.$element) { | 60 | | - dump('LEAK', key, value.$id, sortedHtml(value.$element)); | 61 | | - } else { | 62 | | - dump('LEAK', key, angular.toJson(value)); | 63 | | - } | | 57 | + cache = angular.element.cache; | | 58 | + | | 59 | + forEachSorted(cache, function (expando, key) { | | 60 | + angular.forEach(expando.data, function (value, key) { | | 61 | + count++; | | 62 | + if (value && value.$element) { | | 63 | + dump('LEAK', key, value.$id, sortedHtml(value.$element)); | | 64 | + } else { | | 65 | + dump('LEAK', key, angular.toJson(value)); | | 66 | + } | | 67 | + }); | 64 | 68 | }); | 65 | | - }); | 66 | | - if (count) { | 67 | | - throw new Error('Found jqCache references that were not deallocated! count: ' + count); | | 69 | + if (count) { | | 70 | + throw new Error('Found jqCache references that were not deallocated! count: ' + count); | | 71 | + } | 68 | 72 | } | 69 | 73 |
| 70 | 74 |
| @@ -95,8 +99,9 @@ function dealoc(obj) { | 95 | 99 | if (obj) { | 96 | 100 | if (angular.isElement(obj)) { | 97 | 101 | cleanup(angular.element(obj)); | 98 | | - } else { | 99 | | - for(var key in jqCache) { | | 102 | + } else if (!window.jQuery) { | | 103 | + // jQuery 2.x doesn't expose the cache storage. | | 104 | + for (var key in jqCache) { | 100 | 105 | var value = jqCache[key]; | 101 | 106 | if (value.data && value.data.$scope == obj) { | 102 | 107 | delete jqCache[key]; | |
|