Shadowbox - How to switch or replace content? How to close and open another dialog?

谁说胖子不能爱 提交于 2019-12-05 10:58:00

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

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);
    }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!