aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2014-04-30 10:43:39 -0400
committerDave Methvin <dave.methvin@gmail.com>2014-04-30 11:00:14 -0400
commit062a7d63e4d1a55d72d64152381d93d60b0231e4 (patch)
tree86ebc61c07bf09a6a02105ce3740ce8c1afd19fe
parentf833c9af573462cdec5637db8e58015b288a0a7e (diff)
downloadjquery-062a7d63e4d1a55d72d64152381d93d60b0231e4.tar.gz
jquery-062a7d63e4d1a55d72d64152381d93d60b0231e4.zip
Data: Work around IE11 bug with onpageshow attribute
Fixes #14894 (cherry picked from commit b8133e282ceebf502c7c08d849b176a929c9c450) Conflicts: src/data.js test/unit/data.js
-rw-r--r--src/data.js13
-rw-r--r--test/data/data/dataAttrs.html16
-rw-r--r--test/unit/data.js6
3 files changed, 30 insertions, 5 deletions
diff --git a/src/data.js b/src/data.js
index 03994cdb3..612d91ba0 100644
--- a/src/data.js
+++ b/src/data.js
@@ -287,12 +287,15 @@ jQuery.fn.extend({
if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
i = attrs.length;
while ( i-- ) {
- name = attrs[i].name;
- if ( name.indexOf("data-") === 0 ) {
- name = jQuery.camelCase( name.slice(5) );
-
- dataAttr( elem, name, data[ name ] );
+ // Support: IE11+
+ // The attrs elements can be null (#14894)
+ if ( attrs[ i ] ) {
+ name = attrs[ i ].name;
+ if ( name.indexOf( "data-" ) === 0 ) {
+ name = jQuery.camelCase( name.slice(5) );
+ dataAttr( elem, name, data[ name ] );
+ }
}
}
jQuery._data( elem, "parsedAttrs", true );
diff --git a/test/data/data/dataAttrs.html b/test/data/data/dataAttrs.html
new file mode 100644
index 000000000..5e6e442a6
--- /dev/null
+++ b/test/data/data/dataAttrs.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>IE11 onpageshow strangeness (#14894)</title>
+ <script src="../../jquery.js"></script>
+ <script>
+ $(function(){
+ window.parent.iframeCallback( $( "body" ).data().result );
+ });
+ </script>
+</head>
+<body x-what="test" data-result="ok" onload="x=1" onpageshow="x=1">
+ Test for #14894
+</body>
+</html>
diff --git a/test/unit/data.js b/test/unit/data.js
index 05fc5f193..14acd427e 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -677,3 +677,9 @@ test( "JSON data- attributes can have newlines", function() {
equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
x.remove();
});
+
+testIframeWithCallback( "enumerate data attrs on body (#14894)", "data/dataAttrs.html", function( result ) {
+ expect(1);
+
+ equal(result, "ok", "enumeration of data- attrs on body" );
+}); \ No newline at end of file