-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderer.js
145 lines (116 loc) · 3.35 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const $ = require('jquery')
window.$ = $
const GoldenLayout = require('golden-layout');
var myLayout = new GoldenLayout({
content: [{
type: 'row',
content: [{
type: 'component',
componentName: 'test-component'
}, {
type: 'component',
componentName: 'test-component'
}, {
type: 'component',
componentName: 'test-component'
}, {
type: 'component',
componentName: 'test-component'
}]
}]
});
myLayout.on('stackCreated', function (stack) {
stack
.header
.controlsContainer
.find('.lm_close') //get the close icon
.off('click') //unbind the current click handler
.click(function () {
//add your own
if (confirm('really close this?')) {
stack.remove();
}
});
});
myLayout.on('tabCreated', function (tab) {
tab
.closeElement
.off('click') //unbind the current click handler
.click(function () {
//add your own
if (confirm('really close this?')) {
tab.contentItem.remove();
}
});
});
function updatePosition(lmElement, webview) {
const element = $(lmElement);
let css = element.offset();
css['width'] = lmElement.width();
css['height'] = lmElement.height();
const isVisible = lmElement.is(":visible");
if (isVisible) {
$(webview).show();
} else {
$(webview).hide();
}
// css['display'] = ;
// const isVisible = element.parentNode.style.display != 'none';
// css['display'] = element.parent().style;
console.log(`Updating webview "${webview.attr('id')}": display: ${isVisible}, width:${css.width}, height:${css.height}, top:${css.top}, left:${css.left}`);
$(webview).css(css);
}
let counter = 0;
const colors = ['red', 'green', 'blue', 'pink', 'yellow', 'white', 'gray'];
myLayout.registerComponent('test-component', function (container) {
let webview_id = counter++;
let webview = null;
let element = $(container.getElement());
const containerId = `container-${webview_id}`;
element.attr('id', containerId)
container.on('open', function () {
container.getElement().html('<div>Loading...</div>');
webview = $('<webview src="./webview.html" nodeintegration ' +
'disablewebsecurity autosize></webview>');
webview.attr("id", "webview-" + webview_id);
webview.css({
"position": "absolute",
"background": colors[webview_id % colors.length]
});
$(".lm_root").append(webview);
updatePosition(element, webview);
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
console.log("Mutation detected: ", mutation, mutation.target.getAttribute('id'));
updatePosition(element, webview);
});
});
var config = { attributes: true, attributeFilter: ['style'] };
const elementNode = document.getElementById(containerId);
observer.observe(elementNode.parentNode, config);
webview.show();
});
// container.on('hide', function () {
// if (webview !== null) {
// console.log(`hide fired for "${webview.attr('id')}"`);
// // webview.hide();
// }
// });
// container.on('show', function () {
// if (webview !== null) {
// console.log(`show fired for "${webview.attr('id')}"`);
// // updatePosition(element, webview);
// // webview.show();
// }
// });
// container.on('resize', function () {
// if (webview !== null) {
// updatePosition(element, webview);
// }
// });
// container.on('close', function () {
// alert('close');
// });
});
myLayout.init();
console.log("GL initialized");