WordPress.org

Support

Support » How-To and Troubleshooting » Javascript conflicts and issues

Javascript conflicts and issues

  • So I had a theme working with a static inserting of the jquery library (jquery-1.1.3.1), but now that some of wordpress’s plugins want to use the jquery library, its pulling its own, more up to date version (1.3.2).

    These scripts no longer work on it, which is rather annoying. I’m a real javascript noob, it’s something I’ve never delved into personally, just used premade scripts.

    How can I make these compatible with the wordpress jquery? I really want these, since I’ve already configured the css and everything.

    Reset the form field on mouse click

    <script type="text/javascript">
                    $(function() {
                            swapValues = [];
                            $(".swap_value").each(function(i){
                                    swapValues[i] = $(this).val();
                                    $(this).focus(function(){
                                            if ($(this).val() == swapValues[i]) {
                                                    $(this).val("");
                                            }
                                    }).blur(function(){
                                            if ($.trim($(this).val()) == "") {
                                                    $(this).val(swapValues[i]);
                                            }
                                    });
                            });
                    });
            </script>

    Jquery Dropdown Menu

    <script type="text/javascript" >/**
    * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
    * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
    *
    * @param  f  onmouseover function || An object with configuration options
    * @param  g  onmouseout function  || Nothing (use configuration options object)
    * @author    Brian Cherne <brian@cherne.net>
    */
    (function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);</script>
    <script type="text/javascript" charset="utf-8">
    //<![CDATA[
            $(document).ready(function() {
    
              function addMega(){
                    $(this).addClass("hovering");
                    }
    
              function removeMega(){
                    $(this).removeClass("hovering");
                    }
    
            var megaConfig = {
                     interval: 100,
                     sensitivity: 10,
                     over: addMega,
                     timeout: 100,
                     out: removeMega
            };
    
            $("li.mega").hoverIntent(megaConfig)
    
            });
    
            //]]>
            </script>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Javascript conflicts and issues’ is closed to new replies.