blob: f14a7f7bec4b4215192511dd08004871cda3b770 [file] [log] [blame]
Akron479994e2018-07-02 13:21:44 +02001/**
2 * The plugin system is based
3 * on registered widgets (iframes) from foreign services.
4 * The client component is loaded independently
5 * in a plugin and communicates with the embedding
6 * KorAP service.
7 *
8 * @author Nils Diewald
9 */
10
11(function () {
12 "use strict";
13
14 var obj = {
15
16 /**
17 * Create new plugin
18 */
19 create : function () {
20 return Object.create(this)._init();
21 },
22
23 /*
24 * Initialize plugin
25 */
26 _init : function () {
27 console.log('Init');
28 this.resize();
29 return this;
30 },
31
32 // Send a message
33 _sendMsg : function (data) {
34
35 // TODO: This should send a correct origin
36 window.parent.postMessage(data, '*');
37 },
38
39 /**
40 * Send a log message to the embedding KorAP
41 */
42 log : function (code, msg) {
43 this._sendMsg({
44 action : 'log',
45 code : code,
46 msg : msg
47 });
48 },
49
50 /**
51 * Send a resize command to the
52 * embedding KorAP
53 */
54 resize : function () {
55 var body = document.body;
56
57 console.log('Resize');
58
59 // recognize margin of first element
60 // (don't know why in FF)
61 var cs = getComputedStyle(body.children[0]);
62
63 var offsetHeight = parseInt(body.offsetHeight) +
64 parseInt(cs.getPropertyValue("margin-top")) +
65 parseInt(cs.getPropertyValue("margin-bottom"));
66
67 this._sendMsg({
68 'action' : 'resize',
69 'height' : offsetHeight
70 });
71 }
72 };
73
74 // Create plugin on windows load
75 window.onload = function () {
76 window.KorAPlugin = window.KorAPlugin || obj.create();
77 };
78})();
79
80