WordPress.org

Ready to get started?Download WordPress

Forums

Simple Lightbox
[resolved] Clash with jQuery (7 posts)

  1. johnevanofski
    Member
    Posted 1 year ago #

    Hi there,

    I'm having an issue where the jQuery Easing plugin appears to be clashing with this plugin and subsequently disabling jQuery on my page.

    The error comes in at line 46 on the jQuery Easing v1.3; this issue resolves when I disable the lightbox plugin.

    "Uncaught TypeError:Property 'undefined' of object #<Object> is not a function

    Thank you!

    http://wordpress.org/extend/plugins/simple-lightbox/

  2. johnevanofski
    Member
    Posted 1 year ago #

    Here's the page effected: http://johnevanofski.net

  3. Archetyped
    Member
    Plugin Author

    Posted 1 year ago #

    Hi, I'm not seeing the same error you're referring to, but it does look like jQuery is being loaded twice for the page. The first time appears to be hardcoded in the theme's markup, while the other is loaded by WordPress itself.

    Themes and plugins should always load scripts and styles via WP's file loading API (e.g. using wp_enqueue_script()). WP will automatically stop scripts from being loaded multiple times when scripts are loaded in this way, which can alleviate many issues.

    Let me know if you're still experiencing the same issue once you get the theme's scripts loaded using wp_enqueue_script() and I'd be glad to take another look.

  4. johnevanofski
    Member
    Posted 1 year ago #

    That seems to have resolved the issue, I used:

    <?php
        function my_scripts_method() {
            wp_enqueue_script(
                'easing',
                get_template_directory_uri() . '/js/jquery.easing.1.3.js',
                array('jquery')
            );
        }
        add_action('wp_enqueue_scripts', 'my_scripts_method');
        ?>

    Also note to anyone with the problem in the future you will need to take your $(...) method out in leu of jQuery(...)

  5. Archetyped
    Member
    Plugin Author

    Posted 1 year ago #

    Glad your issue was resolved.

    Also, the use of $() as an alias for jQuery() should not be affected. Did you mean something else?

  6. johnevanofski
    Member
    Posted 1 year ago #

    No, it appears that I have to use the jQuery() alias otherwise the code doesn't work.

    It even says something about it in the wp_enqueue_script() doc

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers

  7. Archetyped
    Member
    Plugin Author

    Posted 1 year ago #

    As long as you wrap the code in an immediately executing anonymous function (as described in the link you posted), $() can be freely used as an alias for jQuery() throughout your code without issue.

    Any publicly distributed library that uses jQuery should be expected to do this as well to avoid conflicts with other code.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags