Skip to content

Commit e805d74

Browse files
committed
Effects: restore and warn on arity of jQuery.easing functions
Uses Function#bind, so it has obvious downside, but it seems acceptable for migrate plugin Fixes #111
1 parent b9116c5 commit e805d74

File tree

4 files changed

+74
-11
lines changed

4 files changed

+74
-11
lines changed

src/effects.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var oldTweenRun = jQuery.Tween.prototype.run;
2+
3+
jQuery.Tween.prototype.run = function( percent ) {
4+
if ( jQuery.easing[ this.easing ].length > 1 ) {
5+
migrateWarn(
6+
"easing function " +
7+
"\"jQuery.easing." + this.easing.toString() +
8+
"\" should use only first argument"
9+
);
10+
11+
jQuery.easing[ this.easing ] = jQuery.easing[ this.easing ].bind(
12+
jQuery.easing,
13+
percent, this.options.duration * percent, 0, 1, this.options.duration
14+
);
15+
}
16+
17+
oldTweenRun.apply( this, arguments );
18+
};

test/effects.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module( "effects" );
2+
3+
QUnit.test( "jQuery.easing", function( assert ) {
4+
assert.expect( 5 );
5+
6+
jQuery.easing.test = function( p, n, firstNum, diff ) {
7+
assert.notEqual( p, undefined );
8+
assert.notEqual( n, undefined );
9+
assert.notEqual( firstNum, undefined );
10+
assert.notEqual( diff, undefined );
11+
};
12+
13+
var div = jQuery( "<div>test</div>" );
14+
15+
div.appendTo( "#qunit-fixture" );
16+
17+
expectWarning( "easing", function() {
18+
div.animate( { width: 20 }, 10, "test" );
19+
} );
20+
} );

test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<script src="event.js"></script>
4343
<script src="traversing.js"></script>
4444
<script src="deferred.js"></script>
45+
<script src="effects.js"></script>
4546
</head>
4647
<body>
4748
<div id="qunit"></div>

warnings.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# jQuery Migrate Plugin - Warning Messages
22

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.
44

55
**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.**
66

@@ -32,7 +32,7 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
3232

3333
### JQMIGRATE: Can't change the 'type' of an input or button in IE 6/7/8
3434

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.
3636

3737
**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.
3838

@@ -45,13 +45,13 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
4545
### JQMIGRATE: jQuery.boxModel is deprecated
4646
### JQMIGRATE: jQuery.support.boxModel is deprecated
4747

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.
4949

5050
**Solution:** Do not use jQuery in Quirks mode, it has never been supported. See the previous item for solutions.
5151

5252
### JQMIGRATE: jQuery.parseJSON requires a valid JSON string
5353

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()`.
5555

5656
**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:
5757
```js
@@ -71,7 +71,7 @@ $.ajax({
7171

7272
### JQMIGRATE: jQuery.browser is deprecated
7373

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.
7575

7676
**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.
7777

@@ -102,19 +102,19 @@ $.ajax({
102102

103103
### JQMIGRATE: jQuery.fn.toggle(handler, handler...) is deprecated
104104

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.
106106

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.
108108

109109
### JQMIGRATE: jQuery.fn.live() is deprecated; jQuery.fn.die() is deprecated
110110

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.
112112

113113
**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).
114114

115115
### JQMIGRATE: AJAX events should be attached to document
116116

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.
118118

119119
**Solution:** Change the program to listen for the AJAX events on the document. For example, if the code currently looks like this:
120120
```javascript
@@ -129,7 +129,7 @@ $(document).ajaxStart(function(){ $("#status").text("Ajax started"); });
129129

130130
**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.
131131

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.
133133

134134
### JQMIGRATE: jQuery.event.handle is undocumented and deprecated
135135

@@ -176,7 +176,7 @@ $(document).ajaxStart(function(){ $("#status").text("Ajax started"); });
176176

177177
### JQMIGRATE: Use of jQuery.fn.data('events') is deprecated
178178

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.
180180

181181
**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.
182182

@@ -209,3 +209,27 @@ $(document).ajaxStart(function(){ $("#status").text("Ajax started"); });
209209
**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.
210210

211211
**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+
return Math.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

Comments
 (0)