Wordpress JS冲突(?)-jQuery

Wordpress JS冲突(?)-jQuery,jquery,prettyphoto,Jquery,Prettyphoto,为了解决这个问题,我整个下午都在发狂,但我想我只是不知道足够多的Javascript来看看该怎么做。读了很多很多帖子,包括这里,但我还是不知道该怎么办 我目前正在使用一个Wordpress主题,这是我从一个设计师那里买来的,从那时起,他就消失了,没有回复任何关于这个主题的信息 关于这个主题,我已经使用了一年多的简单而优雅的lightbox插件() 过去一切都很好,但今天我突然发现“灯箱”效果现在被取消了:所有照片现在都在主页下方打开,而不是出现在浮动窗口中——看起来真的很难看(参见这里的示例)

为了解决这个问题,我整个下午都在发狂,但我想我只是不知道足够多的Javascript来看看该怎么做。读了很多很多帖子,包括这里,但我还是不知道该怎么办

我目前正在使用一个Wordpress主题,这是我从一个设计师那里买来的,从那时起,他就消失了,没有回复任何关于这个主题的信息

关于这个主题,我已经使用了一年多的简单而优雅的lightbox插件()

过去一切都很好,但今天我突然发现“灯箱”效果现在被取消了:所有照片现在都在主页下方打开,而不是出现在浮动窗口中——看起来真的很难看(参见这里的示例)

据我所知,这可能是一种javascript冲突发生在我的主题中,但我不能把我的手指放在它上面。我的JS目录中有一个jQuery1.8.2文件,但是用1.9.1版本替换它并没有带来任何乐趣

Firebug给了我以下JS错误:

    TypeError: $ is not a function
     $('#navigation ul.menu').supersubs({          -   seso.js (line 2)
Error: Permission denied to access property 'toString'
TypeError: $ is not a function
     $('#navigation ul.menu').supersubs({              - seso.js (line 2)
    
“Seso.js”是我的主题(名为“Seso”)附带的文件,其代码如下:

jQuery(document).ready(function() {
    $('#navigation ul.menu').supersubs({ 
            minWidth:    15,
            maxWidth:    30,
            extraWidth:  1     
        }).superfish({ hoverClass: "sfHover", speed: 'slow', dropShadows: false, delay: 0, animation: {height:'show'}});
    $('.up a[href$="top"]').click( function() {
        $.scrollTo( $('#top'), {speed:1200} );
    })
    $('#navigation ul.menu>li>ul>li, #navigation ul.menu>li>ul>li>ul>li').hover(function() { //mouse in
        $(this).stop().animate({ paddingLeft: '5px' }, 300);
    }, function() { //mouse out
    $(this).stop().animate({ paddingLeft: 0 }, 300);
    });
    $(".socialtip").tipTip();
    jQuery(".toggle_body").hide(); 

    jQuery("h4.toggle").toggle(function(){
        jQuery(this).addClass("toggle_active");
        }, function () {
        jQuery(this).removeClass("toggle_active");
    });

    jQuery("h4.toggle").click(function(){
        jQuery(this).next(".toggle_body").slideToggle();

    });
    $("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'facebook',slideshow:5000});
    var enable_image_hover = function(image){
        if(image.is(".portfolio")){
            if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {} else {
                if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
                    image.hover(function(){
                        jQuery(".image_overlay",this).css("visibility", "visible");
                    },function(){
                        jQuery(".image_overlay",this).css("visibility", "hidden");
                    }).children('img').after('<span class="image_overlay"></span>');
                }else{
                    image.hover(function(){
                        jQuery(".image_overlay",this).animate({
                            opacity: '1'
                        },"fast");
                    },function(){
                        jQuery(".image_overlay",this).animate({
                            opacity: '0'
                        },"fast");
                    }).children('img').after(jQuery('<span class="image_overlay"></span>').css({opacity: '0',visibility:'visible'}));
                }
            }
        }       
    }

    $('.portfolio').preloader({
        delay:200,
        imgSelector:'.imgbg img',
        beforeShow:function(){
            $(this).closest('.image_frame').addClass('preloading');
        },
        afterShow:function(){
            var image = jQuery(this).closest('.image_frame').removeClass('preloading').children("a");
            enable_image_hover(image);
        }
    });
    $('.post').preloader({
        delay:100,
        imgSelector:'.postimage img',
        beforeShow:function(){
            $(this).closest('.postimage').addClass('preloading');
        },
        afterShow:function(){
            var image = jQuery(this).closest('.postimage').removeClass('preloading');
        }
    });
});
(function($) {

    $.fn.preloader = function(options) {
        var settings = $.extend({}, $.fn.preloader.defaults, options);


        return this.each(function() {
            settings.beforeShowAll.call(this);
            var imageHolder = $(this);

            var images = imageHolder.find(settings.imgSelector).css({opacity:0, visibility:'hidden'});  
            var count = images.length;
            var showImage = function(image,imageHolder){
                if(image.data.source != undefined){
                    imageHolder = image.data.holder;
                    image = image.data.source;  
                };

                count --;
                if(settings.delay <= 0){
                    image.css('visibility','visible').animate({opacity:1}, settings.animSpeed, function(){settings.afterShow.call(this)});
                }
                if(count == 0){
                    imageHolder.removeData('count');
                    if(settings.delay <= 0){
                        settings.afterShowAll.call(this);
                    }else{
                        if(settings.gradualDelay){
                            images.each(function(i,e){
                                var image = $(this);
                                setTimeout(function(){
                                    image.css('visibility','visible').animate({opacity:1}, settings.animSpeed, function(){settings.afterShow.call(this)});
                                },settings.delay*(i+1));
                            });
                            setTimeout(function(){settings.afterShowAll.call(imageHolder[0])}, settings.delay*images.length+settings.animSpeed);
                        }else{
                            setTimeout(function(){
                                images.each(function(i,e){
                                    $(this).css('visibility','visible').animate({opacity:1}, settings.animSpeed, function(){settings.afterShow.call(this)});
                                });
                                setTimeout(function(){settings.afterShowAll.call(imageHolder[0])}, settings.animSpeed);
                            }, settings.delay);
                        }
                    }
                }
            };


            images.each(function(i){
                settings.beforeShow.call(this);

                image = $(this);

                if(this.complete==true){
                    showImage(image,imageHolder);
                }else{
                    image.bind('error load',{source:image,holder:imageHolder}, showImage);
                    if($.browser.opera){
                        image.trigger("load");//for hidden image
                    }
                }
            });
        });
    };


    //Default settings
    $.fn.preloader.defaults = {
        delay:1000,
        gradualDelay:true,
        imgSelector:'img',
        animSpeed:500,
        beforeShowAll: function(){},
        beforeShow: function(){},
        afterShow: function(){},
        afterShowAll: function(){}
    };
})(jQuery);
jQuery(文档).ready(函数(){
$('#导航ul.menu').supersubs({
最小宽度:15,
最大宽度:30,
超宽:1
}).superfish({hoverClass:'sfHover',speed:'slow',dropShadows:false,delay:0,animation:{height:'show'});
$('.upa[href$=“top”]')。单击(函数(){
$.scrollTo($('#top'),{speed:1200});
})
$(“#导航ul.menu>li>ul>li,#导航ul.menu>li>ul>li”)。悬停(函数(){//mouse in
$(this.stop().animate({paddingLeft:'5px'},300);
},函数(){//鼠标移出
$(this.stop().animate({paddingLeft:0},300);
});
$(“.socialtip”).tipTip();
jQuery(“.toggle_body”).hide();
jQuery(“h4.toggle”).toggle(函数(){
jQuery(this).addClass(“toggle_active”);
},函数(){
jQuery(this).removeClass(“toggle_active”);
});
jQuery(“h4.toggle”)。单击(函数(){
jQuery(this).next(“.toggle_body”).slideToggle();
});
$([rel^='prettypto'])。prettypto({animationSpeed:'slow',theme:'facebook',slideshow:5000});
var enable\u image\u hover=函数(图像){
if(image.is(“.portfolio”)){
if(jQuery.browser.msie&&parseInt(jQuery.browser.version,10)<7){}else{
if(jQuery.browser.msie&&parseInt(jQuery.browser.version,10)<9){
image.hover(函数(){
jQuery(“.image_overlay”,this).css(“可见性”、“可见”);
},函数(){
jQuery(“.image_overlay”,this).css(“可见性”、“隐藏”);
}).儿童('img')。在('')之后;
}否则{
image.hover(函数(){
jQuery(“.image\u overlay”,这个)。设置动画({
不透明度:“1”
}“快”);
},函数(){
jQuery(“.image\u overlay”,这个)。设置动画({
不透明度:“0”
}“快”);
}).children('img').after(jQuery('').css({opacity:'0',visibility:'visible'}));
}
}
}       
}
$('.portfolio').preload({
延误:200,
imgSelector:“.imgbg img”,
beforeShow:function(){
$(this).closest('.image_frame').addClass('preload');
},
afterShow:function(){
var image=jQuery(this).closest('.image_frame').removeClass('preload').children(“a”);
启用图像悬停(图像);
}
});
$('.post')。预加载程序({
延误:100,
imgSelector:“.postimage img”,
beforeShow:function(){
$(this).closest('.positmage').addClass('preload');
},
afterShow:function(){
var image=jQuery(this).closest('.positmage').removeClass('preload');
}
});
});
(函数($){
$.fn.preload=函数(选项){
var设置=$.extend({},$.fn.preload.defaults,options);
返回此值。每个(函数(){
设置.beforeShowAll.call(此);
var imageHolder=$(本);
var images=imageHolder.find(settings.imgSelector).css({opacity:0,visibility:hidden});
var count=images.length;
var showImage=函数(图像,图像支架){
if(image.data.source!=未定义){
imageHolder=image.data.holder;
image=image.data.source;
};
计数--;

如果(settings.delayJavaSript错误准确地告诉您问题所在-
TypeError:$不是函数
,因此脚本失败

在WordPress中,您需要使用
jQuery
,而不是
$
,因此对于您的代码替换

$('#navigation ul.menu')

类似地,在使用
$
的其他函数调用中替换

这是为什么?jQuery通常定义
$
函数,但为了防止与使用
$
的其他库发生冲突,它可以在模式下运行

从文件

WordPress附带的jQuery库设置为noConflict()模式(请参阅wp includes/js/jQuery/jQuery.js)。这是为了防止与WordPress可以链接的其他JavaScript库的兼容性问题


另请参见上的答案。

为什么文件混合使用了
$()
jQuery()
?选择一个并继续使用,听起来问题似乎是由接管
$
字符的其他内容引起的。您可以尝试使用
jQuery(document).ready(函数($){$((“doAnything”);});
。中也介绍了这一点。
$('#navigation ul.menu')
jQuery('#navigation ul.menu')