]> source.dussan.org Git - jquery.git/commitdiff
CSS: Do not throw on frame elements in FF
authorOleg Gaidarenko <markelog@gmail.com>
Sun, 15 Jun 2014 21:26:49 +0000 (01:26 +0400)
committerOleg Gaidarenko <markelog@gmail.com>
Sun, 15 Jun 2014 23:21:34 +0000 (03:21 +0400)
IE9-10 throws on elements created in popups (see #14150), FF meanwhile throws
on frame elements through "defaultView.getComputedStyle" (see #15098)

Use "defaultView" if in the popup which would fix IE issue,
use "window.getComputedStyle" which would fix FF issue.

And everybody wins, except performance, but who cares right?

Fixes #15098
Ref e488d985cfb10ab8c684bbc6a9b8ff3eae23bf83

src/css/curCSS.js
test/unit/css.js

index 1f3b7342884f18677f937e77cb8f7aff3e93bdda..9ab4f1126d06b5881de6b1945235db492890a0d2 100644 (file)
@@ -11,7 +11,14 @@ var getStyles, curCSS,
 
 if ( window.getComputedStyle ) {
        getStyles = function( elem ) {
-               return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+               // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
+               // IE throws on elements created in popups
+               // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
+               if ( elem.ownerDocument.defaultView.opener ) {
+                       return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+               }
+
+               return window.getComputedStyle( elem, null );
        };
 
        curCSS = function( elem, name, computed ) {
index 28bc684ef80ee3e492bfc17928b9fe28c44d909b..2051a2d0062317d44c537641e88eb4d2da1e3f3b 100644 (file)
@@ -1126,4 +1126,27 @@ test( "show() after hide() should always set display to initial value (#14750)",
                });
        }
 })();
+
+test( "Do not throw on frame elements from css method (#15098)", 1, function() {
+       var frameWin, frameDoc,
+               frameElement = document.createElement( "iframe" ),
+               frameWrapDiv = document.createElement( "div" );
+
+       frameWrapDiv.appendChild( frameElement );
+       document.body.appendChild( frameWrapDiv );
+       frameWin = frameElement.contentWindow;
+       frameDoc = frameWin.document;
+       frameDoc.open();
+       frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
+       frameDoc.close();
+
+       frameWrapDiv.style.display = "none";
+
+       try {
+               jQuery( frameDoc.body ).css( "direction" );
+               ok( true, "It didn't throw" );
+       } catch ( _ ) {
+               ok( false, "It did throw" );
+       }
+});
 }