Initial approach to a widget based plugin system

Change-Id: I8ad07c817248a0d205ec9eb66f0dc579fbcd7160
diff --git a/dev/js/src/plugin/client.js b/dev/js/src/plugin/client.js
new file mode 100644
index 0000000..f14a7f7
--- /dev/null
+++ b/dev/js/src/plugin/client.js
@@ -0,0 +1,80 @@
+/**
+ * The plugin system is based
+ * on registered widgets (iframes) from foreign services.
+ * The client component is loaded independently
+ * in a plugin and communicates with the embedding
+ * KorAP service.
+ *
+ * @author Nils Diewald
+ */
+
+(function () {
+  "use strict";
+
+  var obj = {
+
+    /**
+     * Create new plugin
+     */
+    create : function () {
+      return Object.create(this)._init();
+    },
+
+    /*
+     * Initialize plugin
+     */
+    _init : function () {
+      console.log('Init');
+      this.resize();
+      return this;
+    },
+
+    // Send a message
+    _sendMsg : function (data) {
+
+      // TODO: This should send a correct origin
+      window.parent.postMessage(data, '*');
+    },
+
+    /**
+     * Send a log message to the embedding KorAP
+     */
+    log : function (code, msg) {
+      this._sendMsg({
+        action : 'log',
+        code : code,
+        msg : msg
+      });
+    },
+
+    /**
+     * Send a resize command to the
+     * embedding KorAP
+     */
+    resize : function () {
+      var body = document.body;
+
+      console.log('Resize');
+
+      // recognize margin of first element
+      // (don't know why in FF)
+      var cs = getComputedStyle(body.children[0]);
+
+      var offsetHeight = parseInt(body.offsetHeight) +
+          parseInt(cs.getPropertyValue("margin-top")) +
+          parseInt(cs.getPropertyValue("margin-bottom"));
+
+      this._sendMsg({
+        'action' : 'resize',
+        'height' : offsetHeight
+      });
+    }
+  };
+
+  // Create plugin on windows load
+  window.onload = function () {
+    window.KorAPlugin = window.KorAPlugin || obj.create();
+  };
+})();
+
+