Split service component from widgets and introduce
host->plugin communication
Change-Id: I2377059dfc30c196a5b24d331fe60f0310694ba1
diff --git a/dev/js/src/plugin/client.js b/dev/js/src/plugin/client.js
index 4e6ec3c..8c73625 100644
--- a/dev/js/src/plugin/client.js
+++ b/dev/js/src/plugin/client.js
@@ -44,6 +44,10 @@
_init : function () {
this.widgetID = window.name;
this.server = cs.getAttribute('data-server') || '*';
+
+ // Establish the 'message' hook.
+ this._listener = this._receiveMsg.bind(this);
+ window.addEventListener("message", this._listener);
return this;
},
@@ -53,6 +57,24 @@
window.parent.postMessage(data, this.server);
},
+ // Receive a call from the embedded platform.
+ _receiveMsg : function (e) {
+ // Get event data
+ let d = e.data;
+
+ // If no data given - fail
+ // (probably check that it's an assoc array)
+ if (!d)
+ return;
+
+ // TODO:
+ // check e.origin and d["originID"]!!!
+ // probably against window.parent!
+
+ if (this.onMessage)
+ this.onMessage(d)
+ },
+
/**
* Send a log message to the embedding KorAP
*/
@@ -86,7 +108,15 @@
// Create plugin on windows load
window.onload = function () {
window.KorAPlugin = window.KorAPlugin || obj.create();
+
+ // TODO:
+ // Only do this in case of the client being opened
+ // as a widget!
window.KorAPlugin.resize();
+
+ if (window.pluginit)
+ window.pluginit(window.KorAPlugin);
};
+
})();