代码之家  ›  专栏  ›  技术社区  ›  Pennf0lio

帮助Mootools查找我的丑陋代码中的冲突

  •  0
  • Pennf0lio  · 技术社区  · 16 年前

    我需要帮助来定位代码中的冲突,下面是我难看的代码(我刚刚开始编写我的mootools,我认为我的方法很难看)。这里可以看到这个网站 http://tinyurl.com/y9xvm6b . 我认为这与这些路线相冲突

      <script type="text/javascript" src="/lotsforsaleroxascity/media/system/js/mootools.js"></script>
      <script type="text/javascript" src="/lotsforsaleroxascity/media/system/js/caption.js"></script>
    

    在我的代码中。这两行是由我的cms生成并使用它。

      // Global Functions
    
    window.addEvent('domready',function(){
    
    
    /* ------------------------------------------------------- Menu */
    
        var Logo = $('logo').getElements('a'),
            LogoPos = Logo.getStyle('backgroundPosition');
        Logo.addEvents({
            mouseenter: function(){
                this.fade(1);
            },
            mouseleave: function(){
                // Morphes back to the original style
                this.fade(0);
            }       
        });         
    
    
    /* ------------------------------------------------------- Tabs */
    
    
            var tabs = new MGFX.Tabs('#foliobotnav .nav','.t1',{
    
                autoplay: true,
    
                transitionDuration:500,
    
                slideInterval:6000,
    
                hover:true
    
            });
    
    
    
    
    
        var pages = new noobSlide({
    
            box: $('mcontent_hold'),
    
            items: $$('#mcontent_hold div'),
    
            size: 950,
    
            handles: $$('#logo a').extend($$('#topnav ul li.inpage a')),
    
            onWalk: function(currentItem,currentHandle){
    
                <!--$('info4').set('html',currentItem.getFirst().innerHTML);-->
    
                this.handles.removeClass('active');
    
                currentHandle.addClass('active');
    
            }
    
        });     
    
    
    
    /* ------------------------------------------------------- Websites */  
    
        var dropWEB = $$('#web div.left div.imgwrap')[0];
    
        $$('#web .right .imgwrap').each(function(item)
    
        {
    
            item.addEvent('click', function(e)
    
            {
    
                e = new Event(e).stop();
    
                dropWEB.removeEvents();
    
                dropWEB.empty()
    
                var a = item.clone();
    
                a.inject(dropWEB);
    
                dropWEB.style.height = "400px";
    
            });
    
    
    
        });
    
    /* ------------------------------------------------------- Websites End*/
    
    
    
    /* ------------------------------------------------------- Identity */  
    
        var dropID = $$('#artwork div.left div.imgwrap')[0];
    
        $$('#artwork .right .imgwrap').each(function(item)
    
        {
    
            item.addEvent('click', function(e)
    
            {
    
                e = new Event(e).stop();
    
                dropID.removeEvents();
    
                dropID.empty()
    
                var a = item.clone();
    
                a.inject(dropID);
    
                dropID.style.height = "400px";
    
            });
    
    
    
        });
    
    /* ------------------------------------------------------- Identity End*/           
    
    
    
    /* ------------------------------------------------------- Artworks */  
    
        var dropART = $$('#identity div.left div.imgwrap')[0];
    
        $$('#identity .right .imgwrap').each(function(item)
    
        {
    
            item.addEvent('click', function(e)
    
            {
    
                e = new Event(e).stop();
    
                dropART.removeEvents();
    
                dropART.empty()
    
                var a = item.clone();
    
                a.inject(dropART);
    
                dropART.style.height = "400px";
    
            });
    
    
    
        });
    
    /* ------------------------------------------------------- Artworks End*/   
    
    
    /* ------------------------------------------------------- Contact */
    
    $("form").submit(function(){
    
    // 'this' refers to the current submitted form
    var str = $(this).serialize();
    
       $.ajax({
       type: "POST",
       url: "contact.php",
       data: str,
       success: function(msg){
    
    $("#msg").ajaxComplete(function(event, request, settings){
    
    if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
    {
    result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
    $("#formwrap").hide();
    }
    else
    {
    result = msg;
    }
    
    $(this).html(result);
    
    });
    
    }
    
     });
    
    return false;
    
    });
    
    
    
    /* ------------------------------------------------------- Contact */
    
    
    
    });
    

    非常感谢。

    顺便说一句,我遇到的冲突是globals.js中的所有自定义函数都不是函数。按钮不起作用,滑块不起作用,缩略图查看器也不起作用。

    再次感谢。

    2 回复  |  直到 16 年前
        1
  •  1
  •   keif    16 年前

    在这一点上我和Richard是一致的——我会使用一个未压缩的版本,使用firebug并在几个控制台中加载。log()来确定问题所在。

    我建议您通过jslint.com运行代码-它显示了一些问题:

    1. 第52行:要注释掉JavaScript,请使用//NOT
    2. 第112行的问题字符27:缺少分号。
    3. 第146行的问题字符28:缺少分号。

    解决这些问题,然后再试一次。

        2
  •  0
  •   Richard Turner    16 年前

    您正在加载两个版本的mootools.js;这不是一个好的开始。你有 .../media/system/js/mootools.js .../templates/pennfolio/js/mootools.js .

    在开发过程中,使用mootools.js的未压缩版本可能是一个好主意,这样,如果出现问题,您可以轻松找到解决源代码问题的方法( D.prototype is undefined