You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: warnings.md
+35-11Lines changed: 35 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# jQuery Migrate Plugin - Warning Messages
2
2
3
-
To allow developers to identify and fix compatibility issues when migrating older jQuery code, the development (uncompressed) version of the plugin generates console warning messages whenever any of its functionality is called. The messages only appear once on the console for each unique message.
3
+
To allow developers to identify and fix compatibility issues when migrating older jQuery code, the development (uncompressed) version of the plugin generates console warning messages whenever any of its functionality is called. The messages only appear once on the console for each unique message.
4
4
5
5
**In most cases these messages are simply _warnings_; code should continue to work properly with later versions of jQuery as long as the jQuery Migrate plugin is used, but we recommend changing the code where possible to eliminate warnings so that the plugin does not need to be used.**
6
6
@@ -32,7 +32,7 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
32
32
33
33
### JQMIGRATE: Can't change the 'type' of an input or button in IE 6/7/8
34
34
35
-
**Cause:** IE 6, 7, and 8 throw an error if you attempt to change the type attribute of an input or button element, for example to change a radio button to a checkbox. Prior to 1.9, jQuery threw an error for every browser to create consistent behavior. As of jQuery 1.9 setting the type is allowed, but will still throw an error in oldIE.
35
+
**Cause:** IE 6, 7, and 8 throw an error if you attempt to change the type attribute of an input or button element, for example to change a radio button to a checkbox. Prior to 1.9, jQuery threw an error for every browser to create consistent behavior. As of jQuery 1.9 setting the type is allowed, but will still throw an error in oldIE.
36
36
37
37
**Solution:** For compatibility with oldIE, do not attempt to change the type of an input element. Instead, create a new element in your code and replace the old one.
38
38
@@ -45,13 +45,13 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
45
45
### JQMIGRATE: jQuery.boxModel is deprecated
46
46
### JQMIGRATE: jQuery.support.boxModel is deprecated
47
47
48
-
**Cause:** These two deprecated properties are `false` when the page is using Quirks mode, and `true` when the page is in standards mode. Quirks mode was never supported in jQuery so these properties were removed.
48
+
**Cause:** These two deprecated properties are `false` when the page is using Quirks mode, and `true` when the page is in standards mode. Quirks mode was never supported in jQuery so these properties were removed.
49
49
50
50
**Solution:** Do not use jQuery in Quirks mode, it has never been supported. See the previous item for solutions.
51
51
52
52
### JQMIGRATE: jQuery.parseJSON requires a valid JSON string
53
53
54
-
**Cause**: Before jQuery 1.9.0, the `$.parseJSON()` method allowed some invalid JSON strings and returned `null` as a result without throwing an error. This put it at odds with the `JSON.parse()` method. The two methods are aligned as of 1.9.0 and values such as an empty string are properly not considered valid by `$.parseJSON()`.
54
+
**Cause**: Before jQuery 1.9.0, the `$.parseJSON()` method allowed some invalid JSON strings and returned `null` as a result without throwing an error. This put it at odds with the `JSON.parse()` method. The two methods are aligned as of 1.9.0 and values such as an empty string are properly not considered valid by `$.parseJSON()`.
55
55
56
56
**Solution:** If you want to consider values such as `""` or `false` successful and treat them as `null`, check for them before calling `$.parseJSON()`. Since falsy values such as an empty string were previously returned as a `null` without complaint, this code will suffice in most cases:
57
57
```js
@@ -71,7 +71,7 @@ $.ajax({
71
71
72
72
### JQMIGRATE: jQuery.browser is deprecated
73
73
74
-
**Cause:**`jQuery.browser` was deprecated in version 1.3, and finally removed in 1.9. Browser sniffing is notoriously unreliable as means of detecting whether to implement particular features.
74
+
**Cause:**`jQuery.browser` was deprecated in version 1.3, and finally removed in 1.9. Browser sniffing is notoriously unreliable as means of detecting whether to implement particular features.
75
75
76
76
**Solution:** Where possible, use feature detection to make code decisions rather than trying to detect a specific browser. The [Modernizr](http://modernizr.com) library provides a wide variety of feature detections. As a last resort, you can directly look at the `navigator.userAgent` string to detect specific strings returned by the browser.
77
77
@@ -102,19 +102,19 @@ $.ajax({
102
102
103
103
### JQMIGRATE: jQuery.fn.toggle(handler, handler...) is deprecated
104
104
105
-
**Cause:** There are two completely different meanings for the `.toggle()` method. The use of `.toggle()` to show or hide elements is _not_ affected. The use of `.toggle()` as a specialized click handler was deprecated in 1.8 and removed in 1.9.
105
+
**Cause:** There are two completely different meanings for the `.toggle()` method. The use of `.toggle()` to show or hide elements is _not_ affected. The use of `.toggle()` as a specialized click handler was deprecated in 1.8 and removed in 1.9.
106
106
107
-
**Solution:** Rewrite the code that depends on `$().toggle()`, use the minified production version of the jQuery Migrate plugin to provide the functionality, or extract the `$().toggle()` method from the plugin's source and use it in the application.
107
+
**Solution:** Rewrite the code that depends on `$().toggle()`, use the minified production version of the jQuery Migrate plugin to provide the functionality, or extract the `$().toggle()` method from the plugin's source and use it in the application.
108
108
109
109
### JQMIGRATE: jQuery.fn.live() is deprecated; jQuery.fn.die() is deprecated
110
110
111
-
**Cause:** The `.live()` and `.die()` methods were deprecated in 1.7 due to their [performance and usability drawbacks](http://api.jquery.com/live), and are no longer supported.
111
+
**Cause:** The `.live()` and `.die()` methods were deprecated in 1.7 due to their [performance and usability drawbacks](http://api.jquery.com/live), and are no longer supported.
112
112
113
113
**Solution:** Rewrite calls to `.live()` using `.on()` or `.delegate()`. Instructions for doing so are provided in the [`.live()` API documentation](http://api.jquery.com/live).
114
114
115
115
### JQMIGRATE: AJAX events should be attached to document
116
116
117
-
**Cause:** As of jQuery 1.9, the global AJAX events (ajaxStart, ajaxStop, ajaxSend, ajaxComplete, ajaxError, and ajaxSuccess) are only triggered on the `document` element.
117
+
**Cause:** As of jQuery 1.9, the global AJAX events (ajaxStart, ajaxStop, ajaxSend, ajaxComplete, ajaxError, and ajaxSuccess) are only triggered on the `document` element.
118
118
119
119
**Solution:** Change the program to listen for the AJAX events on the document. For example, if the code currently looks like this:
**Cause:** jQuery 1.9 does not support globally triggered events. The only documented global events were the AJAX events and they are now triggered only on `document` as discussed above. jQuery never provided a documented interface for outside code to trigger global events.
131
131
132
-
**Solution:** Change the program to avoid the use of global events. The jQuery Migrate plugin warns about this case but does _not_ restore the previous behavior since it was undocumented.
132
+
**Solution:** Change the program to avoid the use of global events. The jQuery Migrate plugin warns about this case but does _not_ restore the previous behavior since it was undocumented.
133
133
134
134
### JQMIGRATE: jQuery.event.handle is undocumented and deprecated
### JQMIGRATE: Use of jQuery.fn.data('events') is deprecated
178
178
179
-
**Cause**: Prior to 1.9, `.data("events")` could be used to retrieve jQuery's undocumented internal event data structure for an element if no other code had defined a data element with the name "events". This special case has been removed in 1.9.
179
+
**Cause**: Prior to 1.9, `.data("events")` could be used to retrieve jQuery's undocumented internal event data structure for an element if no other code had defined a data element with the name "events". This special case has been removed in 1.9.
180
180
181
181
**Solution**: There is no public interface to retrieve this internal data structure, and it remains undocumented. The only useful applications might be for debugging. The data is available via `jQuery._data("events")` but this is not a documented interface.
**Cause**: Using one of jQuery's API methods to bind a "ready" event, e.g. `$( document ).on( "ready", fn )`, will cause the function to be called when the document is ready, but only if it is attached before the browser fires its own `DOMContentLoaded` event. That makes it unreliable for many uses, particularly ones where jQuery or its plugins are loaded asynchronously after page load.
210
210
211
211
**Solution**: Replace any use of `$( document ).on( "ready", fn )` with `$( document ).ready( fn )` or more simply, just `$( fn )`. These alternative methods work reliably even when the document is already loaded.
212
+
213
+
### JQMIGRATE: Additional params for 'jQuery.easing' functions are not documented and redundant
214
+
215
+
**Cause**: Additional params for 'jQuery.easing' methods were never documented and redundant, same behaviour could be easily achived by other means.
216
+
217
+
**Solution**: Instead of using time and duration arguments, etc; it is already sufficient to use only first "percentage" argument.
218
+
219
+
For example, if you want to implement [Cubic](https://en.wikipedia.org/wiki/Cubic_function) function, then instead of old approach -
220
+
221
+
```js
222
+
jQuery.easing.easeInCubic=function ( p, t, b, c, d ) {
223
+
return c * ( t /= d ) * t * t + b;
224
+
}
225
+
```
226
+
227
+
You could achive same effect with -
228
+
229
+
```js
230
+
jQuery.easing.easeInCubic=function ( p ) {
231
+
returnMath.pow( p, 3 );
232
+
}
233
+
```
234
+
235
+
See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58b6ad122ab425c4cc1a4da4a520#diff-9cd789a170c765edcf0f4854db386e1a) for other possible cases.
0 commit comments