views:

79

answers:

1

I am using fancybox for my lightbox needs.

I have a need to open a link from a raphael element (in this demo a circle).

Normally you would create a link and style it like so:

<a id="test" href="ajax.html">Click Me</a></li>
<script type="text/javascript">
$(document).ready(function() {
    $('#test').fancybox({
        'width'           : '75%',
        'height'          : '75%',
        'autoScale'       : false,
        'transitionIn'    : 'none',
        'transitionOut'   : 'none',
        'type'            : 'iframe'
    });

To complicate things the circle is in it's own javascript file which is declared after fancybox is:

<script src="./fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
<script src="demo02.js" type="text/javascript" charset="utf-8"></script>

The abridged version of demo02.js looks like:

var Demo = {
    initialize: function() {
        var dim = this.getWindowDimensions();
        this.paper = Raphael("canvas", dim.width, dim.height);
        // set events
        (document.onresize ? document : window).onresize = function() {
            Demo.resize();
        }

        // add circle
        var circle = this.paper.circle(150, 120, 100);
        circle[0].style.cursor = "pointer";
        circle.attr({
            fill: "green",
            stroke: "#333",
            "stroke-width": 10,
            href: "ajax.html",
        });
    },
...

So I tried several ways to style the link. One naive attempt was to simply add the id of test to the attr.

I also tried the following:

$(circle.node).fancybox({
$('circle.node').fancybox({
$('#circle.node').fancybox({
$('#canvas.circle.node').fancybox({
$('#Demo.circle.node').fancybox({

And none of them work. The link is always opened as a new link and not in the fancy box.

What am I doing wrong and what do I need to do to correct it?

A: 

Fixed it.

Instead of using the href attribute, I called fancybox directly from within the onclick handler for the node giving me this:

    var circle = this.paper.circle(150, 120, 100);
    circle[0].style.cursor = "pointer";
    circle.attr({
        fill: "green",
        stroke: "#333",
        "stroke-width": 10,
    });
    circle.node.onclick = function () {
        $.fancybox({
            'href'          : 'ajax.html',
            'width'         : '75%',
            'height'        : '75%',
            'autoScale'     : false,
            'transitionIn'  : 'none',
            'transitionOut' : 'none',
            'type'          : 'iframe'
        });

        if (circle.attr("fill") == "red") {
            circle.attr("fill", "green");
        } else {
            circle.attr("fill", "red");
        }
    };

Which works!

graham.reeds