I am building an application using Fancybox, so I post my findings on various related topics. I find a discussion about the problems that I have encountered. Amit Sidhpura's solution perfectly checks if the Fancybox JS script is present in dom or, in other words, if the $ .fancybox plugin is present.
However, it does not tell you whether the Fancybox was initialized or not. To do this, you can do the following:
function fancyboxIsInit() { var fbInit = false; if( typeof $.each( $(document).data('events') !== 'undefined' ) { $.each( $(document).data('events').click, function(i, v) { if( v.namespace === 'fb-start' ) fbInit = true; }); } return fbInit; }
Or the following:
function fancyboxIsInit() { var fbInit = false; if (typeof $._data(document, 'events') !== 'undefined') { $.each($._data(document, 'events').click, function (i, v) { if (v.namespace === 'fb-start') fbInit = true; }); } return fbInit; }
Depending on the version of jQuery used.
JSFiddle:
Check out JsFiddle for reference.
Marventus
source share