-
Notifications
You must be signed in to change notification settings - Fork 476
Add fix for $.fn.data calls #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { migrateWarn } from "../main.js"; | ||
import { camelCase } from "../utils.js"; | ||
|
||
var oldData = jQuery.data; | ||
var oldData = jQuery.data, | ||
oldFnData = jQuery.fn.data; | ||
|
||
jQuery.data = function( elem, name, value ) { | ||
var curData, sameKeys, key; | ||
|
@@ -38,3 +39,42 @@ jQuery.data = function( elem, name, value ) { | |
|
||
return oldData.apply( this, arguments ); | ||
}; | ||
|
||
jQuery.fn.extend( { | ||
data: function( key, value ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use tabs for indentation, not spaces. This applies to most of the added lines. |
||
var args, result; | ||
if ( arguments.length === 0 && typeof Proxy !== "undefined" ) { | ||
result = oldFnData.call( this ); | ||
if(!result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return result; | ||
} | ||
// eslint-disable-next-line no-undef | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it needed when all variables are used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got an eslint error that Proxy is not defined, could it be only for me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this. Instead of silencing the whole rule, please add another override entry to |
||
return new Proxy( result, { | ||
get: function( target, prop ) { | ||
if ( | ||
prop !== camelCase( prop ) && | ||
target[ prop ] === undefined | ||
) { | ||
migrateWarn( | ||
"jQuery.fn.data() always sets/gets camelCased names: " + | ||
prop | ||
); | ||
return target[ camelCase( prop ) ]; | ||
} | ||
return target[ prop ]; | ||
} | ||
} ); | ||
} | ||
if ( arguments.length > 0 && typeof key === "string" && key !== camelCase( key ) ) { | ||
migrateWarn( | ||
"jQuery.fn.data() always sets/gets camelCased names: " + key | ||
); | ||
args = | ||
arguments.length > 1 ? | ||
[ camelCase( key ), value ] : | ||
[ camelCase( key ) ]; | ||
return oldFnData.apply( this, args ); | ||
} | ||
return oldFnData.apply( this, arguments ); | ||
} | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use tabs for indentation, e.g. here: