2010-02-24 4 views
0

현재 Valums JQuery File Upload 플러그인을 사용하고 있습니다. 플러그인은 사용하기가 매우 편리하지만 코드가 어떻게 보이는지 좋아하지 않습니다. 그것은 document.ready 같은 내부 점유하기 때문에 :JQuery Ajax 플러그인 파일 업로드 코드

$(document).ready(function() { 
    var button = $('#button1'), interval; 

    new AjaxUpload(button, { 
     action: 'http://test.com/user/uploadfile', 
     name: 'myfile', 
     onSubmit : function(file, ext){ 
      // change button text, when user selects file   
      button.text('Uploading'); 

      // If you want to allow uploading only 1 file at time, 
      // you can disable upload button 
      this.disable(); 

      // Uploding -> Uploading. -> Uploading... 
      interval = window.setInterval(function(){ 
       var text = button.text(); 
       if (text.length < 13){ 
        button.text(text + '.');      
       } else { 
        button.text('Uploading');    
       } 
      }, 200); 
     }, 
     onComplete: function(file, response){ 
      button.text('Upload Finished'); 

      window.clearInterval(interval); 

      // enable upload button 
      //this.enable(); 

      alert(response);    
     } 
    }); 
}); 

내 질문에 코드가 더 단순화 될 수있다? 내가 코드를 가질 수 있도록 더 많거나 적은 모습처럼 : 사전에

$(document).ready(function() { 
    var button = $('#button1'), interval; 

    new AjaxUpload(button, {#leads to another function}#); 
}); 

감사

답변

0

당신은 자바 스크립트에 처음이신가요? Javascript & jQuery에 대한 나의 첫 경험은 흥미 롭습니다. 왜냐하면 처음에는 코드를 보았던 방식을 좋아하지 않았기 때문입니다. 문제는 당신이 정말로 그것에 익숙해 져야하고 그것이 이유 때문에 모든 것이 있다는 것을 이해해야한다는 것입니다. 이런 일을 할 수있는 커스텀 플러그인을 작성하면 결국에는 어딘가에 숨겨진 코드가 남아있게됩니다. 99 %의 고객이 실제로 신경 쓰지 않기 때문에 = 좋아하는 코드 중첩 체계를 선택하십시오.