Error after upgrade

Page: 1

Author Post
Member
Registered: Feb 2017
Posts: 2
Here is an error which happens after calling fb.activate().

Uncaught TypeError: Cannot read property 'activateMedia' of undefined
at Object.$v [as activate] (floatbox.js:formatted:224)

The call to fb.activate happens on "document ready". However if I delay the call there is no error, in other cases the error occurs randomly (in cases when the call to fb.activate is further in the code) Apparently something has not loaded yet for the activate function to work. How can I prevent that?
Member
Registered: Feb 2017
Posts: 2
The code below resolves the issue but it's not the best solution:

function fbActivate(){
try {
fb.activate();
}
catch(e) {
setTimeout(function(){
fbActivate();
}, 500);
}
}
Administrator
Registered: Aug 2008
Posts: 3382
To run Floatbox API functions at page start, it's best to use the fb.ready function. Functions queued by fb.ready will fire when both the document and the floatbox software is fully loaded and ready to go.
fb.ready( fb.activate );

But I can't think of any good reason why you might want to explicitly call fb.activate at page load time. Floatbox runs fb.activate automagically at page load time. There can be no advantage to having it run twice at that time. Normally, fb.activate is explicitly called only when some floatbox markup has been dynamically added to the page after the page is up and running. Its purpose is to add floatbox behaviours to dynamically added content that wasn't present when fb.activate ran at the initial page load.

Page: 1