tagAnchors while fb open

Page: 1

Author Post
udi111
Guest
hi,
fb.tagAnchors doesn't work for me while fb window is open.

fb.anchors.length = 0; //works
fb.tagAnchors($('div_id')); //doesn't work

i call an ajax function from an opened fb ajax window to reload a div on the main page.
am i doing sg wrong?
adam
Administrator
Registered: Aug 2008
Posts: 3382
Hey Adam,

I'm not sure what is meant by "doesn't work" because I'm not sure what you expect to happen when you make the fb.tagAnchors call. If you're hoping it will add to or modify an already opened gallery collection, then yes, it won't do that. That gallery collection is built at load time of the first item.

If you can tell me a bit more about what you're trying to do - or better yet, show it with an online example - then maybe I can say something more intelligent about this.
udi111
Guest
hi,
so there's a messagelist on the page, loaded with ajax, each has a fb ajax anchor (rel="floatbox" rev="type:ajax") to show the message (not a group) with fb.

every time i load the messagelist
fb.anchors.length = 0;
and
fb.tagAnchors($('div_id'));
are called in the function to rebuild the fb anchors list and this works fine (for example show inbox, delete message, show next page etc.).

but when i call the function from the opened fb (for example delete the message and reload the list in the background), the list reloads but after i close fb and click on any fb link nothing happens (i think because fb.anchors.length = 0; was called but fb.tagAnchors($('div_id')); did something wrong: the click on the link is captured but fb will not open).

i tried to be more clear (with my poor english).
hope you can help.
gregg
Guest
Hello, I had exactly the same problem today. in my case it was a script in an iframe floatbox that updated content on hte background page including adding new floatbox links.

in floatbox.js i added...

fb.anchors.length = 0;
setTimeout("fb.tagAnchors(document.body)",500);

right at the end of the 'end' function that closes the floatbox window so that just after the floatbox window is closed the tagAnchors call reactivates all the floatbox links on hte background page including those added by ajax calls from hte floatbox window.

i'm sure there will be a neater and more efficient solution that doesn't invlove modifying the floatbox.js but this solved it for me.

hope that is of use.
Administrator
Registered: Aug 2008
Posts: 3382
I think Gregg is on the right track, but hasn't nailed it. I suspect the problem is that the ajax content refresh is being done asynchronously and that the call to fb.tagAnchors is made after the ajax call is made but before the new ajax content fetch has completed. Gregg's timeout is a workaround for this and will probably be successful, but the better approach might be to handle the asynchronous nature of the ajax fetch. You would do this by making sure that the tagAnchors call was done as a callback to the ajax fetch and fired only once that fetch was complete. You could also do this by changing the ajax fetch type from asynchronous to synchronous thereby halting all processing until the fetch completed.

If the above doesn't work or can't be done for some reason, there are other approaches. One would be to add an onclick action of onclick="fb.loadAnchor(this);" to each new anchor that's being added via ajax. This way, if tagAnchors doesn't replace the onclick action, the anchor will still fire in floatbox when clicked.

A less elegant approach would be to use fb's loadPageOnClose:self option and handle the div's content change in your server side code.
udi111
Guest
hi guys,
note that taganchors somehow runs because the clicks are captured, only fb won't open.

gregg, i tried the settimeout but did not help.
when i insert fb.end() in the function before taganchors to close fb i get the same result BUT if i change the taganchors too (to settimeout) it works perfectly:
fb.end();
fb.anchors.length = 0;
setTimeout("fb.tagAnchors($('div_id'))",500);

byron, later i will have time to check your solution and report results.

thanks
adam
udi111
Guest
here are the results:
i added onclick="fb.loadAnchor(this);" to the anchors, but the result was the same.
after this i removed fb.tagAnchors($('div_id')); from the function and voil?: everything works (i also had to add return false; to the onclick).
this way is fine for me for now, not to tagAnchors on load but loadAnchor when clicked.
once again, tagAnchors runs fine while fb closed, does something wrong while fb open (the click is captured but fb will not open). the result in my prev post shows the same.
i am happy with this workaround but this is still a bug i think.
thanks for the help.
adam
udi111
Guest
admin wrote
A less elegant approach would be to use fb's loadPageOnClose:self option and handle the div's content change in your server side code.

by the way,
is there a way to call a javascript function on fb close?
and on fb loaded?
Administrator
Registered: Aug 2008
Posts: 3382
I'm glad you found an approach that works for you. Perhaps there is some bug preventing tagAnchors from succeeding in you circumstances. I will mark this down to look into, but it will be some time before I can get to that. I'm currently languishing on Pulau Pangkor and won't be home at my debug station for 7 more weeks. 8)

I'm still suspicious that the problem is the asynchronous nature of standard ajax fetches and that the proper solution is to find a way to wait until the ajax fetch has completed.

Also, I think the ability to attach code to floatbox events like start and end is helpful. I'll look at adding that when I'm back.
udi111
Guest
byron,
thanks for the excellent support.
i still don't know what can be wrong with the ajax calling method because i call exactly the same function from the page itself as from floatbox and tagAnchors runs fine while calling from the page.

have a nice time
adam
Administrator
Registered: Aug 2008
Posts: 3382
Adam,
I appreciate the careful and detailed problem description you provided. It's very helpful. Your finding that tagAnchors is managing to write the onclick action, but that action subsequently fails is particularly interesting. When you say that fb won't open, I assume you mean nothing happens, and not that the href'd page opens full page in the browser.

When the time comes that I can spend some time looking at this in detail, I may wish to contact you to get details of your page setup. Thanks again for the detailed report. This is exactly the sort of field-encountered problem that I want to resolve to keep floatbox as solid as possible.

Cheers...
udi111
Guest
admin wrote
When you say that fb won't open, I assume you mean nothing happens, and not that the href'd page opens full page in the browser.

right
admin wrote
When the time comes that I can spend some time looking at this in detail, I may wish to contact you to get details of your page setup.

sure.

Page: 1