]> source.dussan.org Git - jquery.git/commitdiff
Data: Work around IE11 bug with onpageshow attribute
authorDave Methvin <dave.methvin@gmail.com>
Wed, 30 Apr 2014 14:43:39 +0000 (10:43 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 30 Apr 2014 15:00:14 +0000 (11:00 -0400)
Fixes #14894
(cherry picked from commit b8133e282ceebf502c7c08d849b176a929c9c450)

Conflicts:
src/data.js
test/unit/data.js

src/data.js
test/data/data/dataAttrs.html [new file with mode: 0644]
test/unit/data.js

index 03994cdb393927a4298cab0ebfa49ceeb1e3bcd0..612d91ba0ed20b2bb8fcbb377b51c50673d9eb8c 100644 (file)
@@ -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 (file)
index 0000000..5e6e442
--- /dev/null
@@ -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>
index 05fc5f193fbc4f64cbc357c383448d97d6195daf..14acd427e575b86e43391c9aac59defe7fe72539 100644 (file)
@@ -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