]> 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 14:46:26 +0000 (10:46 -0400)
Fixes #14894

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

index 8b285d2668d3d90a83b9abcda4447c58f823cefd..e3f3578fe860ad4410353bbd2b72b733dd8de2a0 100644 (file)
@@ -87,11 +87,15 @@ jQuery.fn.extend({
                                if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
                                        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 ] );
+                                                       }
                                                }
                                        }
                                        data_priv.set( elem, "hasDataAttrs", 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 b63c79b92257543c508fac70de9a0a299a0d0bfe..d3ae818ed5da046a8866f92891552948cd2be025 100644 (file)
@@ -801,3 +801,9 @@ test("Check proper data removal of non-element descendants nodes (#8335)", 1, fu
 
        ok( !text.data("test"), "Be sure data is not stored in non-element" );
 });
+
+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