fb.end() and fb.tagAnchors(id)

Page: 1

Author Post
theprodigy
Guest
My apologies if this has already been answered, but I briefly scanned and didn't see anything.

I seem to be running into a slight problem. I am using floatbox for forms on my site. Then ajax the form to the server, get the response back, refresh the page, and close floatbox. It all seems to work perfectly except for this one section.

I am building a calendar application for the site. The Add Event link pulls up a floatbox form. You submit date, time, and event. If a date has an event scheduled, the day on the calendar is a link. You click the link, a floatbox pulls up with a list of all events scheduled for that day.

The issue I'm running into is:

When a new event is submitted, I ajax a new calendar. All the links that were previously there still work, but the newest day (the one with the new event), doesn't work. No floatbox pulls up. I am using fb.tagAnchors(id), but I think the problem lies in the fact that the floatbox is still in the process of closing when that function gets called. Is there anyway of detecting when the floatbox has finished closing? Should there be an issue with tagAnchors if the overlay is still present and floatbox is still closing? Is there a work around?

Thanks in advance for your help
Administrator
Registered: Aug 2008
Posts: 3382
This is an interesting problem that has been discussed before in this topic. But in that case I did not have a helpful answer and did not understand the issue. (My excuse is I was on vacation and traveling at the time. 8) )

Here's what's going on. TagAnchors basically does two things: it sets the onclick action on floatbox anchors so that clicking them will invoke floatbox, and it inventories those anchors and their properties and keeps that inventory in an array. It is the inventory that is giving you grief.

Each anchor record in the inventory array is associated with a floatbox "level". That is, records gathered when no floatbox is displayed have level=0. Those gathered when one floatbox is displayed have level=1. Etc. Level is determined by how many floatboxes are currently opened. When a floatbox is closed, all anchor records associated with that level are discarded.

So, when you run tagAnchors from an open floatbox, those anchors get assigned to that open floatbox. When that floatbox closes, those anchor records are discarded.

But you're probably more interested in a solution rather than an explanation. The trick will be to run tagAnchors() after the closing of the floatbox has completed. In the new about-to-be-released version, this will be easy as it adds user-defined callback functions that can be set for various events, including afterBoxEnd.

In the current version, there are two approaches that could be tried. My apologies, but I don't have time to set up a test for them right now. I'm hoping you can test them out and report back what works.
1) Set a rev option on the Add Event link that looks like this:
rev="loadPageOnClose=`javascript:fb.tagAnchors(node);`"
2) Put your current tagAnchors call on a timeout:
top.setTimeout(function() {fb.tagAnchors(node);}, 1000);

The first one is preferred if it works. The problem with the second one is that you have to guess at the right value for the timeout. I don't know that the 1 second shown is the right value. You want something that's always guaranteed to be after the box completely closes, but before the user wants to click the new link.
theprodigy
Guest
You rock!!!

I added loadPageOnClose=`javascript:fb.tagAnchors([node]);` to my current rev attribute, and it works beautifully.

Looking forward to the newest release. It sounds great!

Thanks a bunch for your help

Page: 1