2009-10-04 59 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