mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-06 05:43:51 +00:00
feat(eventcatcher): provide access to event properties as JSON
This commit is contained in:
parent
a8a8867506
commit
f13f684f16
@ -23,49 +23,6 @@ Inherit from the base widget class
|
|||||||
*/
|
*/
|
||||||
EventWidget.prototype = new Widget();
|
EventWidget.prototype = new Widget();
|
||||||
|
|
||||||
|
|
||||||
function getEventPropertiesJSON(event) {
|
|
||||||
var seen = new Set();
|
|
||||||
|
|
||||||
function isDOMElement(value) {
|
|
||||||
return value instanceof Node || value instanceof Window;
|
|
||||||
}
|
|
||||||
|
|
||||||
function safeCopy(obj) {
|
|
||||||
//skip ciruclar references
|
|
||||||
if(seen.has(obj)) {
|
|
||||||
return "[Circular reference]";
|
|
||||||
}
|
|
||||||
//skip functions
|
|
||||||
if(typeof obj !== "object" || obj === null) {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
//skip DOM elements
|
|
||||||
if(isDOMElement(obj)) {
|
|
||||||
return "[DOM Element]";
|
|
||||||
}
|
|
||||||
//copy each element of the array
|
|
||||||
if(Array.isArray(obj)) {
|
|
||||||
return obj.map(safeCopy);
|
|
||||||
}
|
|
||||||
|
|
||||||
seen.add(obj);
|
|
||||||
var copy = {}, key;
|
|
||||||
for(key in obj) {
|
|
||||||
try{
|
|
||||||
copy[key] = safeCopy(obj[key]);
|
|
||||||
} catch(e) {
|
|
||||||
copy[key] = "[Unserializable]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = safeCopy(event);
|
|
||||||
seen.clear();
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Render this widget into the DOM
|
Render this widget into the DOM
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user