Skip to content

Instantly share code, notes, and snippets.

@odil-io
Created October 20, 2022 12:53
Show Gist options
  • Save odil-io/4e5f3142efef9050df709c1487505e52 to your computer and use it in GitHub Desktop.
Save odil-io/4e5f3142efef9050df709c1487505e52 to your computer and use it in GitHub Desktop.
Debugging: Log all Events
function _isEvent(prop) {
if (0 !== prop.indexOf('on')) {
return false;
}
return true;
}
function _getEvents(obj, hasOwnProperty = true) {
const result = [];
for (const prop in obj) {
if (!obj.hasOwnProperty(prop) && hasOwnProperty) {
continue;
}
if (_isEvent(prop)) {
// remove "on" at the beginning
result.push(prop.substr(2));
}
}
return result;
}
function getEvents(filter = '*', hasOwnProperty = true, noEmptyArrays = false, debug = false) {
const result = {};
const arr = Object.getOwnPropertyNames(window);
if ('*' === filter) {
filter = ''; // would always exist in any string possible
}
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
if (-1 === element.indexOf(filter)) {
continue;
}
let resultArray = [];
try {
const obj = window[element];
if (!obj || !obj['prototype']) {
continue;
}
proto = obj['prototype'];
resultArray = _getEvents(proto, hasOwnProperty);
} catch (err) {
if (debug) {
console.error(`failed to get events of %o`, element);
}
}
if (resultArray.length === 0 && noEmptyArrays) {
continue;
}
result[element] = resultArray;
}
if (-1 !== 'window'.indexOf(filter)) {
const resultArray = _getEvents(window, hasOwnProperty);
if (resultArray.length === 0 && noEmptyArrays) {
return result;
}
result['window'] = resultArray;
}
return result;
}
jQuery.each( getEvents(), function(){
if ( this.length > 0 ) {
jQuery.each( this, function(){
jQuery(document).on( String(this), function(event){
const array = [
'readystatechange',
'visibilitychange',
'pointerrawupdate',
'pointermove',
'pointerover',
'pointerenter',
'pointerout',
'pointerleave',
'mousemove',
'mouseout',
'mouseenter',
'mouseover',
'mouseleave'
]
if ( ! array.includes( event.type ) ) {
console.log( event.type );
}
});
} );
}
});
@odil-io
Copy link
Author

odil-io commented Oct 20, 2022

CAUTION: more than 60% of this is not my code. Please beware that my additions lie between line 79 and line 107.

Source: PerimeterX/map-events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment