This popup does not work with latest native wordpress jQuery v1.11.0

I need to load some content into a pop-up and following an example here. It works great as standalone but when I am trying to implement into wordpress using the native jQuery v1.11.0 it does not work. However it works again using the original jquery source http://code.jquery.com/jquery-latest.pack.js given in the code.

Javascript

$(document).ready(function() {  
    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
    var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //transition effect     
        $('#mask').fadeIn(1000);    
        $('#mask').fadeTo("slow",0.8);  

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);

        //transition effect
        $(id).fadeIn(1000); 

    });

    //if close button is clicked
    $('.window .close').click(function (e) {
        e.preventDefault(); //Cancel the link behavior

        $('#mask').hide();
        $('.window').hide();
    });     

    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });         

    $(window).resize(function () {

        var box = $('#boxes .window');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        box.css('top',  winH/2 - box.height()/2);
        box.css('left', winW/2 - box.width()/2);

    });
});

Html

<a href="#dialog" name="modal">Simple Window Modal</a>
    <div id="boxes">
        <div id="dialog" class="window">
        Simple Modal Window | <a href="#"class="close"/>Close it</a>
        </div>

    <div id="mask"></div><!-- Mask to cover the whole screen -->
    </div><!-- end of boxes -->

Any ideas how to make the code work with the latest wordpress's jquery, which actually is jQuery v1.11.0 as seen in the view-source. As it does not really make a lot of sense to load two sources of jquery and I would like it to work with the one that wordpress comes with.


UPDATE : As advised I have replace all the $ with jQuery and have used wp_enqueue_script and wp_register_script and my pop up is working as expected. I just need someone to take a look at how I enqueued the script. Is something wrong here ?

function adding_scripts() {
wp_register_script( 'my_amazing_script', get_template_directory_uri() . '/pop-stuff.js', array('jquery') ); 
wp_enqueue_script( 'my_amazing_script', get_template_directory_uri() . '/pop-stuff.js', array() );
}

add_action( 'wp_enqueue_scripts', 'adding_scripts' );

In WordPress, the $() syntax is always used by other scripting library, and causing the conflict issue and fail to call the jQuery function. You should use jQuery() instead

Reference : link

链接地址: http://www.djcxy.com/p/61210.html

上一篇: WordPress的后端缓存错误?

下一篇: 此弹出窗口不适用于最新的原生wordpress jQuery v1.11.0