Fail to override default options

Page: 1

Author Post
jasoncat
Guest
I am using v3.12, great job!

But I found that several default options could not be overridden through a custom 'setFloatboxOptions' function. Such options include (incomplete list): preloadAll, urlGraphics,urlLanguages...
Administrator
Registered: Aug 2008
Posts: 3382
Correct.
To quote the Options Reference document that is on the floatbox site and also in the download package:

Quote
Configuration Options
The options in this section can only be set or changed directly in the floatbox.js code. They have no effect if set through rev attributes or the page-level setFloatboxOptions function.
jasoncat
Guest
Ah, sorry I missed that. Is there a technical reason why they cannot be overridden? To me it makes sense to override at least some of these options (e.g. preloadAll) for different pages.

Thanks!
Administrator
Registered: Aug 2008
Posts: 3382
Not a cast-in-stone technical reason, but there's two phases involved in loading floatbox. The first phase is the initialization that happens as soon as the document is ready. This phase includes inventorying and adding onclick actions to the anchors, setting up a bunch of variables, fetching the localized language strings, and initiating image preloading. The second phase occurs when an anchor is clicked (or initiated by script). It is during this second phase that the page and rev attribute options are picked up, the floatbox built, and the content displayed. So the configuration setting vars can only be set in the js file because they are used during the initialization phase, prior to the other option sources being parsed in the load phase.

A few code changes and additions would allow for the page options (the setFloatboxOptions function) to be picked up in the initialization phase as well. You're not the first person to think that this would be useful, so this change will likely make it into the next version, whenever that is. Give the people what they want... :D
jasoncat
Guest
Wow, very pleasant explanations. Thank you!
Administrator
Registered: Aug 2008
Posts: 3382
Sorry, I was not thinking clearly in my previous response. It may be a pleasant response, but it's not an accurate one.

Yes, there is a show-stopper reason why the settings defined in the Configuration Options section can't be picked up from a setFloatboxOptions function on the host page using the current approach. The setFloatboxOptions function works by assigning option settings as properties of the global fb object. The fb object is created by being assigned the results of the floatbox initialization code. It exists only when initialization is complete. Prior to and during initialization fb is undefined and any attempts to execute a function that references fb will throw an error. So configuration settings required during initialization must be established by a different mechanism, such as directly in the js file. It's a bootstrap issue.

Having said all that, it would be do-able to change the way the page-specific options are set so that there is no reliance on the fb global var. This would involve replacing the setFloatboxOptions function with an object defined by code that might look like the following:
fbPageOptions = {
navType: 'both',
showUpperNav: 'once',
enableCookies: true,
preloadAll = false
};
Options specified like that could be picked up during initialization. Would this be of value?

Page: 1