diff --git a/src/js/#events.js b/src/js/#events.js index 3ee4b85..16142a4 100644 --- a/src/js/#events.js +++ b/src/js/#events.js @@ -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, }); diff --git a/src/js/panel.filter.js b/src/js/panel.filter.js index 7d740d7..09b0549 100644 --- a/src/js/panel.filter.js +++ b/src/js/panel.filter.js @@ -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'; @@ -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) \ No newline at end of file +})(window.jQuery, window.Widgets.Panel.Filter, window.d3, window.Widgets.Panel.Utils, window.Widgets.Events, document, window) \ No newline at end of file