Migrate from document.defaultView => window. Fixes #10373 #524

Closed
wants to merge 4 commits into from

7 participants

@rwaldron
jQuery Foundation member

No description provided.

@paulirish
jQuery Foundation member

link to ticket where i brought this up: http://bugs.jquery.com/ticket/10373

@paulirish
jQuery Foundation member

You're aliasing window.getComputedStyle as a local getComputedStyle variable but that seems needless.
Instead, just check (window.getComputedStyle) in the conditionals and use it straight out within the block.

doing this you'd save another 4 (OMG FOUR!) bytes

@rwaldron
jQuery Foundation member
247971   (-266) jquery.js
 93914   (-103) jquery.min.js
 33197    (-16) jquery.min.js.gz         
@jdalton
jQuery Foundation member

this breaks cross-iframe happiness cuz before it would use the element's ownerDocument.

@davidmurdoch

@jdalton, how's so? Are you making jQuery document aware? (http://bugs.jquery.com/ticket/8405#comment:10)

@mikesherov
jQuery Foundation member

@jdalton, just curious... what difference does it make if we're using the getComputedStyle function of the window instead of the same function on the ownerDocument?

@timmywil
jQuery Foundation member

I share the same concern as @jdalton.

@rwaldron
jQuery Foundation member

@jdalton thanks for the heads up, ping me on IRC :)

@jdalton
jQuery Foundation member

@davidmurdoch @mikesherov One of the cool things about being document agnostic is that you can have jQuery in one (i)frame/primary document and script elements in other (i)frames w/o also having jQuery loaded in all (i)frames. I'm not sure how much compat jQuery has for this, but I thought it was a rad enough feature to add to my own lib. So basically before:

  // elem is from another iframe so its document, window, & defaultView are different
  elem.ownerDocument.defaultView

Using the primary window's method kills that functionality.
The use of ownerDocument and the private getWindow() function makes me think that at one time cross-frame scripting was considered a feature.

@rwaldron
jQuery Foundation member

This test confirms that it is iframe safe: http://jsfiddle.net/rwaldron/4NWcY/

@gnarf
jQuery Foundation member

@jdalton - Little bit of research here - getComputedStyle doesn't seem to care what window its on...

@jdalton
jQuery Foundation member

It doesn't get the same result in FF 3.6; see this test.
The reason this raised red flags for me is normally foreign nodes cause errors to be thrown when inserting/attempting-to-mix-with the primary document's nodes.

@rwaldron
jQuery Foundation member

Thanks @jdalton ... I just confirmed that FF3.6 is indeed unable to get the computed style unless called from the correct context

Perhaps when FF3.6 is EOL'ed, we can re-open this

@rwaldron rwaldron closed this Sep 29, 2011
@gnarf
jQuery Foundation member

lame - but awesome - thanks for finding the hole @jdalton

@jdalton
jQuery Foundation member

It doesn't work in Fennec either (produces the same result as FF 3.6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment