Skip to content

Commit

Permalink
improved feature detection with functional test in 'isEventSupported(…
Browse files Browse the repository at this point in the history
…)' method, touch capable device can now be distinguished, fixes a bug that produced false positives on Chrome 4/5, bumped release date (jdalton)
  • Loading branch information
Diego Perini committed Jul 20, 2010
1 parent 8825279 commit 471dcb2
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/nwevents.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author: Diego Perini <diego.perini at gmail com>
* Version: 1.2.4beta
* Created: 20051016
* Release: 20100314
* Release: 20100720
*
* License:
* http://javascript.nwbox.com/NWEvents/MIT-LICENSE
Expand Down Expand Up @@ -173,22 +173,47 @@

isEventSupported = W3C_MODEL ?
function(type, element) {
return true;

if (typeof supportedEvents[type] != 'undefined') {
return supportedEvents[type];
}

function handler(e) {
if (Object.prototype.toString.call(e) != '[object Event]') {
supportedEvents[type] = true;
}
element.removeEventListener(type, handler, true);
}

element || (element = testTarget);

supportedEvents[type] = false;

try {
element.addEventListener(type, handler, true);
dispatch(element, type, false);
} catch (e) { }

return supportedEvents[type];

} : MSIE_MODEL ?
function(type, element) {

if (typeof supportedEvents[type] != 'undefined') {
return supportedEvents[type];
}

element || (element = testTarget);

try {
(element || testTarget).fireEvent('on' + type);
element.fireEvent('on' + type);
supportedEvents[type] = true;
} catch (e) {
supportedEvents[type] = false;
}

return supportedEvents[type];

} :
function () { return false; },

Expand Down

0 comments on commit 471dcb2

Please sign in to comment.