2013-06-01 9 views
1

기술 내가 jQuery를 1.9.1과 트위터 부트 스트랩을 사용하고

2.3.1

나는 현재 유입을 방지 트위터 부트 스트랩 선행 입력 플러그인의 버그에 직면하고있다

컨텍스트 자동 완성 드롭 다운이 열려있을 때 입력 [type = "text"]의 "&"문자 (앰퍼샌드는 키 코드 38을 반환하고, 위쪽 화살표는 키 코드 38)에서

입력 [type = "text"]에 첨부 된 모든 이벤트를 살펴보고 문제의 원인을 파악할 수 있기를 바랍니다.

문제

// bootstrap typeahead plugin 
// bootstrap.js:2126 
this.$element 
    .on('focus', $.proxy(this.focus, this)) 
    .on('blur',  $.proxy(this.blur, this)) 
    .on('keypress', $.proxy(this.keypress, this)) 
    .on('keyup', $.proxy(this.keyup, this)) 

// bootstrap.js:2171 
move: function (e) { 
    if (!this.shown) return 

    switch(e.keyCode) { 
    case 9: // tab 
    case 13: // enter 
    case 27: // escape 
     e.preventDefault() 
     break 

    case 38: // up arrow 
     e.preventDefault() 
     this.prev() 
     break 

    case 40: // down arrow 
     e.preventDefault() 
     this.next() 
     break 
    } 

    e.stopPropagation() 
} 

프록시 방법은 주어진 상황과 새로운 기능을 반환하기 때문에 디버깅 정말 어렵게 만든다.

내가 크롬에서 무엇을 발견 - 내가 jQuery를 발견 무엇 모든

// Get event listeners on element 
getEventListeners($('[name="searchTerm"]')[0]) 

// Get the keydown event to see what's going on 
getEventListeners($('[name="searchTerm"]')[0]).keydown[0].listener 

// Returns 
function (a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b} 

// <function scope> points back to the function above 
// ['<function scope>'] is an example 
getEventListeners($('[name="searchTerm"]')[0]).keydown[0].listener['<function scope>'] 

에서 나에게 도움이되지 않습니다 - 나 가벼운 부상을 입 도움?

// Get event listeners on element 
// $element.data('events') is no longer supported. version >= 1.8 
$._data($('[name="searchTerm"]')[0], 'events') 

// Get the keydown event to see what's going on 
$._data($('input.search-query.span2')[0], 'events').keydown[0].handler 

// Returns 
function(){return a.apply(c,f.concat(F.call(arguments)))} 

// <function scope> points to the correct function 
// ['<function scope>']['Closure']['a'] is an example 
$._data($('input.search-query.span2')[0], 'events').keydown[0].handler['<function scope>']['Closure']['a'] 

// Returns 
function (e) { this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]) this.move(e) } 

질문

  1. 은 자바 스크립트 함수의 밖으로 < 기능 범위 > 및 < 폐쇄 > 문맥을 취득 어쨌든이 있나요?
  2. jQuery를 사용하여 DOM 요소에서 $ .proxy 이벤트 리스너가 실행되는 것을 디버깅하는 더 쉬운 방법이 있습니까?
  3. 이러한 이벤트를 디버깅하는 더 좋은 방법이 있습니까?

고마워요!

+0

왜 bootstrap-typeahead 파일에 중단 점을 넣을 수 없으며 개발자 도구 모음을 사용하여 메서드 실행을 디버깅 할 수 없습니다. 내가 볼 수있는 것에서는 예전 소스는'focus'와'keydown'과 같은 메소드를 가질 것입니다. –

+0

'$ .proxy'로 디버깅하기가 어렵다는 것도 왜 이해가 안되는가? –

+0

@ArunPJohny 할 수는 있지만, 50 개가 넘는 js 파일이있는 사이트가 있고 자바 스크립트의 절반은 인라인입니다. 문제가 어디에 있는지 이미 알았 으면 거기에 중단 점을 넣을 수는 있지만 그렇지 않았습니다. 문제의 원인을 "발견"하고 싶었습니다. – chemoish

답변

1

jQuery Debugger Chrome extension에는 jQuery 이벤트 핸들러가 표시됩니다. Firefox 야간은 similar feature입니다.

+0

프록시 기능 코드가 아닌 jQuery.proxy의 코드 만 표시합니다. –

+0

@JohanFredrikVaren 아니요, jQuery 프록시 코드가 아닌 실제 이벤트 처리기를 보여줍니다. [screenshot] (http://i.imgur.com/SxLtgCg.png) – niutech

관련 문제