Skip to content

Commit

Permalink
add events.
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone committed Jul 24, 2024
1 parent a2555b9 commit 8fadf7e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src/js/#events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,44 @@ window.Widgets.Events = {};
//define your function
(function($, ns) {

ns.compileEventData = (payload, eventName, action, componentId, config) => {
return {
type: eventName,
payload: payload,
action: action,
componentId: componentId,
config: config
};
};

ns.windowListener = function() {
console.group("windowListener on " + window.location);
window.addEventListener("message", function(event) {
console.groupCollapsed('widget windowListener on ' + window.location);
var eventData = event.data;
var sourceWindow = event.source;
var sourceOrigin = event.origin;

console.log('eventData', eventData, 'sourceWindow', sourceWindow, 'sourceOrigin', sourceOrigin);

var sourceData = eventData;
if (typeof sourceData === 'string') {
sourceData = JSON.parse( sourceData );
}

if (!sourceData) {
console.log('no sourceData');
console.groupEnd();
return;
}

console.groupEnd();
});
console
}

ns.raiseEvent = function(eventName, data) {
console.group("raiseEvent");
console.group("raiseEvent on " + window.location);
let event = new CustomEvent(eventName, {
detail: data,
});
Expand Down
24 changes: 22 additions & 2 deletions src/js/panel.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//define context menu functions
window.Widgets.Panel.Filter = {};

;(function ($, ns, d3, panelUtilsNs, document, window) {
;(function ($, ns, d3, panelUtilsNs, eventNs, document, window) {

ns.selectorComponent = '#filter_panel';

Expand Down Expand Up @@ -54,7 +54,27 @@ window.Widgets.Panel.Filter = {};
panelUtilsNs.theme = ns.options.dark_theme
}

//init event buttons
const $event_buttons = $component.find('#toggle_options');
$event_buttons.find('#base').on('click', function (d) {


const id = $(this).attr('id');
const payload = {
action: 'click',
id: id,
type: 'button'
}
const topic = "form-identity-toggle-item"
const eventName = "form-identity-toggle-item";
const config = "section_base_required";
const action = "BUTTON_CLICK";
const data = eventNs.compileEventData(payload, eventName, action, id, config);

eventNs.raiseEvent(eventName, data);
});

console.groupEnd();
}

})(window.jQuery, window.Widgets.Panel.Filter, window.d3, window.Widgets.Panel.Utils, document, window)
})(window.jQuery, window.Widgets.Panel.Filter, window.d3, window.Widgets.Panel.Utils, window.Widgets.Events, document, window)

0 comments on commit 8fadf7e

Please sign in to comment.