1 | (function(){
|
2 | function stringifyEvent(event) {
|
3 | var obj = {};
|
4 | for (var key in event) {
|
5 | obj[key] = event[key];
|
6 | }
|
7 | return JSON.stringify(obj, function(key, value){
|
8 | if(value instanceof Node){
|
9 | var nodeRep = value.tagName;
|
10 | if (nodeRep) {
|
11 | nodeRep = nodeRep.toLowerCase();
|
12 | if(value.id){
|
13 | nodeRep += "#" + value.id;
|
14 | }
|
15 | if(value.classList && value.classList.length){
|
16 | nodeRep += "." + value.classList.toString().replace(" ", ".")
|
17 | }
|
18 | return nodeRep;
|
19 | } else {
|
20 | return "Node"
|
21 | }
|
22 | }
|
23 | if (value instanceof Window) return 'Window';
|
24 | return value;
|
25 | });
|
26 | }
|
27 |
|
28 | htmx.defineExtension('event-header', {
|
29 | onEvent: function (name, evt) {
|
30 | if (name === "htmx:configRequest") {
|
31 | if (evt.detail.triggeringEvent) {
|
32 | evt.detail.headers['Triggering-Event'] = stringifyEvent(evt.detail.triggeringEvent);
|
33 | }
|
34 | }
|
35 | }
|
36 | });
|
37 | })();
|