Search code examples
facebookfancyboxfacebook-javascript-sdkfacebook-iframefacebook-canvas

Fancybox Positioning Inside Facebook Canvas iFrame


OK so I have a iframe canvas app with its height set to "Settable" with the facebook javascrip sdk calls to FB.Canvas.setSize(); and FB.Canvas.setAutoGrow();. These are working perfectly, as the iframe gets set to a certain pixel height based on its content.

The problem is that when I make a call to Fancybox, it positions itself based on this height. I know that's exactly what its supposed to do as the fancybox jQuery returns the viewport by:

(line 673 of latest version of jquery.fancybox-1.3.4.js):

_get_viewport = function() {
return [
    $(window).width() - (currentOpts.margin * 2),
    $(window).height() - (currentOpts.margin * 2),
    $(document).scrollTop() + currentOpts.margin
];
},

But the problem is the iframe will, for a lot of viewers, be longer than their browser window. So the Fancybox centers itself in the iframe and ends up only partly visible to the majority of viewers. (i.e. iframe height is 1058px and users browser is say only 650px).

Is there a way to have fancybox just calculate the physical browser height? Or do I need to change some settings in my Facebook canvas app to make it work?

I like how the only scrollbar is the one on Facebook (the parent, if you will).

All suggestions GREATLY appreciated!


Solution

  • For fancybox 2 try:

    find:

    _start: function(index) {
    

    and replace with:

    _start: function(index) {
        if ((window.parent != window) && FB && FB.Canvas) {
            FB.Canvas.getPageInfo(
                function(info) {
                    window.canvasInfo = info;
                    F._start_orig(index);
                }
            );
        } else   {
            F._start_orig(index);
        }
    },
    
    _start_orig: function (index) {
    

    Then in function getViewport replace return rez; with:

    if (window.canvasInfo) {
        rez.h = window.canvasInfo.clientHeight;
        rez.x = window.canvasInfo.scrollLeft;
        rez.y = window.canvasInfo.scrollTop - window.canvasInfo.offsetTop;
    }
    
    return rez;
    

    and finally in _getPosition function replace line:

    } else if (!current.locked) {
    

    with:

    } else if (!current.locked || window.canvasInfo) {