Step through instances looking for element?

Page: 1

Author Post
Member
Registered: Apr 2009
Posts: 52
Location: Everett, WA
Hello!

Long-time since I've posted... haven't needed to because your code rocks. :)

However, I recently upgraded from 603 to 733 and a few things broke. :(

Specificaly, it appears you've changed how instances work with multiple floatboxes.

I've looked at the support documentation but don't see any way to cycle through instances.

fb.getInstance ( name ) will give me a specific instance by name and fb.getOwnerInstance ( node ) returns a specific instance that contains the passed node/id.

Which is great but let's say I have three iframe floatboxes open and I want to cycle through them and the underlying parent document to see if any of the documents contain a particular node and if so do something with it. How would I go about that?

I tried using fb.$( id, doc ) but it only returns a single node and in my use case there would be possibly many instances of that node on different documents open at the given time.

Any help is of course greatly appreciated, I'm sure I just haven't dug deeply enough so if it's obvious, my apologies... I did search the forum for answers but the only thing I found was from 2010 and I'm sure it's outdated.

Thanks!

-b
Administrator
Registered: Aug 2008
Posts: 3382
You were perhaps iterating through the old fb.instances array which has indeed gone away (for reasons which I won't attempt to justify here).

Don't overlook the new fb.select API function, which provides a CSS-like element matching interface, similar to jQuery selectors and based on document.querySelectorAll (but returning an array instead of a node list).

Get all iframes on a page with a simple fb.select( 'iframe' ).
Get all iframes that are presented as floatbox content by adding the 'fbContent' class name to that selector: fb.select( 'iframe.fbContent' ).

When you have a reference to an iframe element, its window and document objects are available as .contentWindow and .contentDocument properties on that reference.

For example:
theFrames = fb.select( 'iframe.fbContent' );
for ( i = 0; i < theFrames.length; i++ ) {
theNode = fb.$( theId, theFrames[ i ].contentDocument );
if ( theNode ) {
alert( &#039;jackpot!&#039; );
}
}
(I haven't run this snippet but it looks correct on paper to me.)
Member
Registered: Apr 2009
Posts: 52
Location: Everett, WA
Thanks B,

I had to adjust it slightly by adding "top" so it would get all floatbox iframes from the base page up but otherwise worked great.

theFrames = top.fb.select( &#039;iframe.fbContent&#039; );


Thanks!

-b

Page: 1