I encountered the following Javascript error in fancybox.js (see attached screenshot). Firefox ignored the error and initialized Fancybox correctly, but Safari caught the error and Fancybox failed to load. I don't know how to roll a proper patch, so I'll just explain how I fixed the problem:

I changed line 11 of fancybox.js from:

if (settings.options[events[i]].length && typeof(settings.options[events[i]]) == 'string') {

to:

if (typeof(settings.options[events[i]]) != 'undefined' && typeof(settings.options[events[i]]) == 'string' && settings.options[events[i]].length) {

It seems that settings.options[events[i]].length was throwing an error because settings.options[events[i]] was evaluating to "undefined", and therefore was not an object. I simply added a check to ensure that it's not "undefined", before attempting to retrieve the object's length property.

I hope this helps!

CommentFileSizeAuthor
fancybox-js-error.jpg130.19 KBAnonymous (not verified)

Comments

Island Usurper’s picture

It should be ok just to make the typeof() == 'string' check first, without seeing if it's 'undefined'.

This fix is necessary because of the way for() works in JavaScript. Not only is i 0, 1, 2, 3, etc., but it also gets 'filter', and 'length'. As quirky as PHP is, in many ways JavaScript is worse.