5

I'm trying to use shadowbox in multiple occasions: sometimes I happen to need more than one dialog at the same time.

In this simple example I try to close one existing window and re-open another one but is not opening the second one. What I'm doing wrong?

<!DOCTYPE HTML>
<html>
<head>
    <link rel="stylesheet" href="shadowbox.css" type="text/css">
    <style type="text/css" media="screen">
        #sb-body, #sb-loading { background:#eee; }
    </style>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script>
    <script src="shadowbox.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript">

        Shadowbox.init();

        window.onload = function(){

            Shadowbox.open({
                content: 'First window. <a id="open-second" href="http://www.google.com">open another window</a>.',
                player: "html"
            });

            $('#open-second').live('click', function(e){
                e.preventDefault();

                Shadowbox.close();
                Shadowbox.open({
                    content: 'Second window.',
                    player: "html"
                });
            });
        };
    </script>
</head>
<body>blabla.</body>
</html>

Regards,
Adit

Adit Saxena
  • 1,617
  • 15
  • 25

2 Answers2

1

Sorry 'bout this, but I think I'll move towards colorbox as it seems far more stable:

$('#second-btn').live('click', function(e){
  e.preventDefault();
  $.colorbox({
    onComplete: function(){
      $('#cboxLoadedContent').append('second opened');
      $('#cboxClose').attr('id', 'cboxClose_disabled');
    },
    html:'<p>Second <a id="first-btn" href="x">first</a></p>',
    width: 500, height: 200
  });
});

function showfirst(){
  $.colorbox({
    onLoad: function(){ $('#cboxClose_disabled').attr('id', 'cboxClose'); },
    onComplete: function(){ $('#cboxLoadedContent').append('first opened') },
    html:'<p>First <a id="second-btn" href="x">second</a></p>',
    width: 500, height: 200
  });
}

$('#first-btn').live('click', function(e){
  e.preventDefault();
  showfirst()
});

showfirst();

Hey, am I talking alone?! XD

Adit Saxena
  • 1,617
  • 15
  • 25
  • I had the same issue as you, or rather, I was trying to get one shadowbox to open or refresh with new content once an internal link was pressed. I took your advice and moved over to Colorbox. Works and does what I want. Thanks :) – webmaster alex l Aug 05 '12 at 05:40
0

Here's what I'll use; not happy with this as:
- I'm forcing a widely used plugin doing a simple task (close a window and open another)
- it needs to override each shadowbox feature (now only player "html" is implemented).

Here a full working example.

var shadowbox_orig_open = Shadowbox.open;
Shadowbox.reOpenable = function(new_opts) {
    if(Shadowbox.isOpen()){
        // close other dialog
        Shadowbox.options.onClose(Shadowbox.getCurrent());

        if(new_opts.player == "html"){
            $('#sb-player').fadeOut('normal', function(){ $(this).html(new_opts.content).fadeIn(); });
        }else{
            // ???
        }

        // set other new hooks
        Shadowbox.options = new_opts.options;
    }else{
        shadowbox_orig_open(new_opts);
    }
};
Adit Saxena
  • 1,617
  • 15
  • 25