Check if jQuery "Fancybox" is registered?

I am updating jQuery fancybox as follows:

        $(document).ready(function() {

        $("#help").fancybox({
            'width': '90%',
            'height': '90%',
            'autoScale': true,
            'transitionIn': 'elastic',
            'transitionOut': 'none',
            'titleShow': false,
            'type': 'iframe'
        });
         });

However, on the transfer / postback page, it is registered several times, which slows it down to the point of hacking. Is there a way to check if an event is registered, and if not, register it?

Pseudocode:

 //check if fancybox has not been registered
if($("help").fancybox == null))
{
     //register fancy box
}
+2
source share
4 answers

When fancybox starts, it adds an entry fancyboxto the jQuery object data.

You can check availability:

if( ! $("#help").data().fancybox )
{
     //register fancy box
}
+3
source

Fancybox uses $ (element) .data () to store the configuration associated with the element. You just need to check if it exists fancybox.

$("#fancy").data("fancybox");

See fiddle for more fnu.

+2

#help fancybox.js , . Fancybox.js fancybox.

#help. , HTTP- .

: http://api.jquery.com/jQuery.ajax/

error function, .

$(document).ready(function() {

    // Look for #help
    if ( $('#help').html() !== null ) {

        // Load, init and config the fancybox
        $.ajax({
            url: '/js/path/to/fancybox.js',
            type: 'GET',
            dataType: 'script',
            success: function() {

                // Init Fancybox
                $("#help").fancybox({
                    'width': '90%',
                    'height': '90%',
                    'autoScale': true,
                    'transitionIn': 'elastic',
                    'transitionOut': 'none',
                    'titleShow': false,
                    'type': 'iframe'
                });
            }
        });

    }
});
+1

, Fancybox 2 :

parent.jQuery.fancybox.isOpen

, :

parent.jQuery.fancybox.isOpened

true, fancybox .

0

All Articles