开发者

fancybox - passing 'this' to onClosed function

开发者 https://www.devze.com 2023-02-10 02:07 出处:网络
Hi this is probly really simple but I juast cant seem to figure it out! if( is_logged_out( html ) ) { var throughClick = $(this);

Hi this is probly really simple but I juast cant seem to figure it out!

if( is_logged_out( html ) ) {
    var throughClick = $(this);
    $.fancybox( html, { 
        'autoDimensions' : false,
        'width' : 'auto', 
        'height' : 'auto', 
        'transitionIn' : 'none', 
        'transitionOut' : 'none',
       开发者_StackOverflow社区 'hideOnOverlayClick' : false, 
        'showCloseButton' : false, 
        'onClosed' : 
        function( throughClick ) {
            alert(throughClick.attr('name'));
            throughClick.trigger('click');      
        }
    });
}else{

All i want to do is pass the object of whichever button or link that was clicked, so once the user has logged back in it will process again.

Any help is much appreciated.


onClosed:function() { console.log(arguments) }

would lead you to orig :P that should have the origional element clicked

arguments[2].orig.hide() would hide the link clicked


You have to make sure you fix the 'whichever button or link' object in the throughClick variable. That's not necessarily done by the this variable. this is filled in by the calling function, which you don't always control, especially not when using

Probably, you better tell the object to call a function explicitly when clicked. This can be easily automated by enumerating them:

var onclickables = $.map
     ( ["#clickme1","#clickme2"]
     , function( i, e ) { return $(i); } 
     );

var html="";// whatever you need it to be

$.each(onclickables)( function( index, item ) {
    item.click( function(e){
       your_new_function( html, item ); // <=== here you know the object
    });
});


function your_new_function( html, throughClick ) {
  if( is_logged_out( html ) ) {          
      $.fancybox( html, { 
          'autoDimensions' : false,
          'width' : 'auto', 
          'height' : 'auto', 
          'transitionIn' : 'none', 
          'transitionOut' : 'none',
          'hideOnOverlayClick' : false, 
          'showCloseButton' : false, 
          'onClosed' : 
          function( throughClick ) {
              alert(throughClick.attr('name'));
              throughClick.trigger('click');      
          }
      });

I showed the idea in a jsfiddle, too.

0

精彩评论

暂无评论...
验证码 换一张
取 消