Skip to content

Commit 8fadf7e

Browse files
committed
add events.
1 parent a2555b9 commit 8fadf7e

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/js/#events.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,44 @@ window.Widgets.Events = {};
33
//define your function
44
(function($, ns) {
55

6+
ns.compileEventData = (payload, eventName, action, componentId, config) => {
7+
return {
8+
type: eventName,
9+
payload: payload,
10+
action: action,
11+
componentId: componentId,
12+
config: config
13+
};
14+
};
15+
16+
ns.windowListener = function() {
17+
console.group("windowListener on " + window.location);
18+
window.addEventListener("message", function(event) {
19+
console.groupCollapsed('widget windowListener on ' + window.location);
20+
var eventData = event.data;
21+
var sourceWindow = event.source;
22+
var sourceOrigin = event.origin;
23+
24+
console.log('eventData', eventData, 'sourceWindow', sourceWindow, 'sourceOrigin', sourceOrigin);
25+
26+
var sourceData = eventData;
27+
if (typeof sourceData === 'string') {
28+
sourceData = JSON.parse( sourceData );
29+
}
30+
31+
if (!sourceData) {
32+
console.log('no sourceData');
33+
console.groupEnd();
34+
return;
35+
}
36+
37+
console.groupEnd();
38+
});
39+
console
40+
}
41+
642
ns.raiseEvent = function(eventName, data) {
7-
console.group("raiseEvent");
43+
console.group("raiseEvent on " + window.location);
844
let event = new CustomEvent(eventName, {
945
detail: data,
1046
});

src/js/panel.filter.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//define context menu functions
33
window.Widgets.Panel.Filter = {};
44

5-
;(function ($, ns, d3, panelUtilsNs, document, window) {
5+
;(function ($, ns, d3, panelUtilsNs, eventNs, document, window) {
66

77
ns.selectorComponent = '#filter_panel';
88

@@ -54,7 +54,27 @@ window.Widgets.Panel.Filter = {};
5454
panelUtilsNs.theme = ns.options.dark_theme
5555
}
5656

57+
//init event buttons
58+
const $event_buttons = $component.find('#toggle_options');
59+
$event_buttons.find('#base').on('click', function (d) {
60+
61+
62+
const id = $(this).attr('id');
63+
const payload = {
64+
action: 'click',
65+
id: id,
66+
type: 'button'
67+
}
68+
const topic = "form-identity-toggle-item"
69+
const eventName = "form-identity-toggle-item";
70+
const config = "section_base_required";
71+
const action = "BUTTON_CLICK";
72+
const data = eventNs.compileEventData(payload, eventName, action, id, config);
73+
74+
eventNs.raiseEvent(eventName, data);
75+
});
76+
5777
console.groupEnd();
5878
}
5979

60-
})(window.jQuery, window.Widgets.Panel.Filter, window.d3, window.Widgets.Panel.Utils, document, window)
80+
})(window.jQuery, window.Widgets.Panel.Filter, window.d3, window.Widgets.Panel.Utils, window.Widgets.Events, document, window)

0 commit comments

Comments
 (0)