Fixed resizing of widgets
Change-Id: I566a28acbaa01cbcbf3a0adc55c3de879e2e8434
diff --git a/dev/js/src/plugin/client.js b/dev/js/src/plugin/client.js
index 1c2af18..64f0bc4 100644
--- a/dev/js/src/plugin/client.js
+++ b/dev/js/src/plugin/client.js
@@ -44,7 +44,6 @@
_init : function () {
this.widgetID = window.name;
this.server = cs.getAttribute('data-server') || '*';
- this.resize();
return this;
},
@@ -72,19 +71,9 @@
* embedding KorAP
*/
resize : function () {
- var body = document.body;
-
- // 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
+ 'height' : document.documentElement.scrollHeight
});
}
};
@@ -92,7 +81,7 @@
// Create plugin on windows load
window.onload = function () {
window.KorAPlugin = window.KorAPlugin || obj.create();
+ window.KorAPlugin.resize();
};
})();
-
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index d26de27..9401de6 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -11,18 +11,23 @@
define(["plugin/widget", "util"], function (widgetClass) {
"use strict";
- // TODO:
- // This is a counter to limit acceptable incoming messages
- // to hundred. For every message, this will be decreased
- // (down to 0), for every second this will be increased
- // (up to 100).
- var maxMessages = 100;
- var limits = {};
-
// Contains all widgets to address with
// messages to them
var widgets = {};
+ // This is a counter to limit acceptable incoming messages
+ // to a certain amount. For every message, this counter will
+ // be decreased (down to 0), for every second this will be
+ // increased (up to 100).
+ // Once a widget surpasses the limit, it will be killed
+ // and called suspicious.
+ var maxMessages = 100;
+ var limits = {};
+
+ // TODO:
+ // It may be useful to establish a watcher that pings
+ // all widgets every second to see if it is still alive.
+
return {
/**
@@ -38,6 +43,10 @@
*/
_init : function () {
+ // TODO:
+ // It is better to establish the listener
+ // only in case there is a widget
+
var that = this;
window.addEventListener("message", function (e) {
that._receiveMsg(e);
@@ -55,7 +64,7 @@
},
/**
- * Open a new widget on a certain element
+ * Open a new widget as a child to a certain element
*/
addWidget : function (element, src) {
@@ -75,7 +84,9 @@
);
},
- // Receive a call from an embedded iframe
+ // Receive a call from an embedded iframe.
+ // The handling needs to be very careful,
+ // as this can easily become a security nightmare.
_receiveMsg : function (e) {
// Get event data
var d = e.data;
@@ -87,9 +98,6 @@
// e.origin is probably set and okay - CHECK!
- // TODO:
- // Deal with mad iframes
-
// Get origin ID
var id = d["originID"];
@@ -106,6 +114,9 @@
// Check for message limits
if (limits[id]-- < 0) {
+
+ // Kill widget
+ KorAP.log(0, 'Suspicious action from ' + widget.src);
widget.shutdown();
delete limits[id];
delete widgets[id];
@@ -114,7 +125,6 @@
// Resize the iframe
if (d.action === 'resize') {
-
widget.resize(d);
}
diff --git a/dev/js/src/plugin/widget.js b/dev/js/src/plugin/widget.js
index cb4a33d..7e56603 100644
--- a/dev/js/src/plugin/widget.js
+++ b/dev/js/src/plugin/widget.js
@@ -19,6 +19,7 @@
return Object.create(this)._init(src, id);
},
+ // Initialize widget
_init : function (src, id) {
this.src = src;
this.id = id;
@@ -39,6 +40,7 @@
i.setAttribute('frameborder', 0);
i.setAttribute('sandbox','allow-scripts');
i.classList.add('widget');
+ i.style.height = '0px';
i.setAttribute('name', this.id);
i.setAttribute('src', this.src);
this._element = i;
@@ -53,7 +55,6 @@
// Shutdown suspicious iframe
shutdown : function () {
- KorAP.log(0, 'Suspicious action from ' + this.src);
this._element.parentNode.removeChild(this._element);
}
}