2013-08-16 2 views
0

jquery에 익숙하지만, 그렇게 익숙하지 않다. 일부 jquery 객체 (CLButton)를 만드는 웹 페이지가 있습니다. 여기에 전체 js 코드 (http://contactplus.sos-pharmacie-de-garde.com/js/sos.js)가 있습니다. 다음은 사용자 정의 jquery CLButton 메소드가있는 코드의 일부입니다.커스텀 객체 메소드를 얻고 호출하기

// creates CLButton and shows some staff 
$("#next2").CLButton({ 
    'delay'  : 3000, 
    'formSubmit' : false, 
    'txtWait' : 'Chargement en cours ...' 
    }); 

이 코드는 버튼을 클릭 솜 직원을 next2 버튼 #에서 실행 여기에 내가 document.read에서

CLButton.prototype = { 
     constructor: CLButton, 
     ...        
     hideLoader: function(){ 
      var $loader = this.getLoader(); 
      var $bg = $loader.find(".bg"); 
      $loader.fadeOut(150, function(){ 
       $bg.css({'width':'252px','height':'auto'}); 
      }); 
     },      

..

다음 코드가있다. 나는 지금 hideLoader 방법 (위 참조)을 실행할 필요가 있다고 믿지만, 나는 어떻게 이해하지 못한다. 나는이 스크립트 내부 hideLoader 메소드를 호출하려고합니다

$("#next2").click(function(){ 
    ... //HOW TO CALL hideLoader here? 
} 

질문입니다 -이 어떻게 할 수 있나요? 개체가 click 외부에서 document.ready에 생성되었습니다. 그래서 어떻게 든이 객체에 액세스 한 다음 위에 정의 된 메서드를 호출해야합니다. 방법? 링크 된 코드에서

답변

0

는 :

onClick : function(e){ 
     e.preventDefault(); 
     this.disable(); 
     setTimeout($.proxy(this, '_callback', 'onClick', e), this.settings.delay); 
     return false; 
    }, 

    _callback: function(callback, e){ 
     this.settings[callback].call(this, e); 
     if (callback == 'onClick' && this.settings.formSubmit){ 
      this.canSubmitForm = true; 
      this.$form.submit(); 
     } 
    }, 

이것은 예를 들어, 옵션 등의 클릭 핸들러에 전달할 수 있음을 나타냅니다 보인다

$("#next2").CLButton({ 
    'callback' : function() { 
     // stuff to do onclick 
    }, 
    // other options here 
}); 

하지만 CLButton의 소스를 변경하려는 경우, 당신이 할 수있는 :

_callback: function(callback, e){ 
    this.hideLoader(); // add this call here 
    this.settings[callback].call(this, e); 
    if (callback == 'onClick' && this.settings.formSubmit){ 
     this.canSubmitForm = true; 
     this.$form.submit(); 
    } 
}, 
관련 문제