2009-10-04 61 views
0

我需要帮助来定位我的代码中的冲突,下面是我的丑陋代码(我刚开始写我的Mootools和我认为很丑的方法)。该网站可以在这里看到http://tinyurl.com/y9xvm6b。我认为这是与这些行冲突Mootools帮助定位我丑陋的代码中的冲突

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

在我的代码。这2行是由我的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都不起作用我所有的自定义功能。按钮不起作用,滑块不起作用,还有缩略图查看器。

再次感谢。

回答

1

我与理查德在这 - 我会使用一个未压缩的版本,使用萤火虫和加载一些console.log()来确定问题的地方。

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

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

修复这些问题,然后重试。

+0

谢谢凯夫,我发现了这个问题。我正在使用mootools的幻灯片插件,我忘了将它与核心mootools合并,所以无论何时删除我自己的mootools,我的脚本都不起作用。 (男人,我很乱我的代码。) 感谢jslint.com,这是伟大的工具。 谢谢! – Pennf0lio 2009-10-05 08:47:00

+0

不要感谢我,感谢道格拉斯克罗克福德JSLint.com这是一个非常宝贵的工具。 – keif 2009-10-10 22:04:45

0

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

在开发过程中,使用mootools.js的未压缩版本可能是一个不错的主意,因此如果出现问题,您可以轻松找到源代码(D.prototype is undefined不是非常有用的错误消息)。然后在生产中使用压缩版本。

+0

感谢理查德, 我试图删除(模板/ pennfolio/js/mootools.js)但没有解决冲突。我知道用不同的版本加载相同的js库是不对的。我只是试图把它们都用于调试目的。 谢谢! – Pennf0lio 2009-10-04 19:50:13

+0

当你说“冲突”时,你看到了什么错误信息? – 2009-10-04 19:55:22

+0

'冲突'我的意思是问题。我的意思是当我删除(templates/pennfolio/js/mootools.js)时,它仍然无法正常工作。但是,当我停止我的CMS加载这2行, 它工作正常。 – Pennf0lio 2009-10-04 20:36:12