From b8133e282ceebf502c7c08d849b176a929c9c450 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Wed, 30 Apr 2014 10:43:39 -0400 Subject: [PATCH] Data: Work around IE11 bug with onpageshow attribute Fixes #14894 --- src/data.js | 12 ++++++++---- test/data/data/dataAttrs.html | 16 ++++++++++++++++ test/unit/data.js | 6 ++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/data/data/dataAttrs.html diff --git a/src/data.js b/src/data.js index 8b285d266..e3f3578fe 100644 --- a/src/data.js +++ b/src/data.js @@ -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 index 000000000..5e6e442a6 --- /dev/null +++ b/test/data/data/dataAttrs.html @@ -0,0 +1,16 @@ + + + + + IE11 onpageshow strangeness (#14894) + + + + + Test for #14894 + + diff --git a/test/unit/data.js b/test/unit/data.js index b63c79b92..d3ae818ed 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -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 -- 2.39.5