pepebe
9/14/2012 - 11:46 AM

Find the event handler blocking events (event.preventDefault())

Find the event handler blocking events (event.preventDefault())

// Scenario: Some event handler is blocking events (event.preventDefault()) that shouldn't be blocked, i.e. because it binds to document instead of a more specific element

// 1) Place this before all other JavaScript
var originalPreventDefault = Event.prototype.preventDefault;

Event.prototype.preventDefault = function () {
  // Lookup specific event you're expecting, i.e. pressing space
  if (this instanceof KeyboardEvent && this.keyCode === 32) {
    // This will log an error with full stack trace
    make_error_to_see_stacktrace   
  }

  originalPreventDefault.apply(this, arguments);
};

// 2) Do what's required to trigger the event, i.e. press some key combination

// 3) Look for error stacktrace in console, i.e
//
// Uncaught ReferenceError: make_error_to_see_stacktrace is not defined :22286/#2012.01.01:25
//   Event.preventDefault :22286/#2012.01.01:25
//   f.Event.preventDefault jquery-1.7.2.min.js:3
//   $.jstree.plugin.__init.$.bind.$.proxy.data.contextmenu   ...  jquery.jstree.js:3681
//   ...

// 4) jstree is obviously handling the event, which it shouldn't!

// 5) Surprise, surprise
//
//    jquery.jstree.js:

$(document) // <- This should be the container element, not the entire document
  // ...
  .bind("keydown", "space"), function (e) {
    // ...
    e.preventDefault();  // 3681
  });