Skip to content
Permalink
Browse files

Data: Work around IE11 bug with onpageshow attribute

Fixes #14894
  • Loading branch information
dmethvin committed Apr 30, 2014
1 parent c34dbf5 commit b8133e282ceebf502c7c08d849b176a929c9c450
Showing with 30 additions and 4 deletions.
  1. +8 −4 src/data.js
  2. +16 −0 test/data/data/dataAttrs.html
  3. +6 −0 test/unit/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 );
@@ -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>
@@ -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" );
});

0 comments on commit b8133e2

Please sign in to comment.
You can’t perform that action at this time.