-
Notifications
You must be signed in to change notification settings - Fork 3
/
panel.js
78 lines (67 loc) · 2.14 KB
/
panel.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
ext.panel = {
is_open: false,
last_container: null,
last_inject: null,
controller: null,
reset_height: function(container_el)
{
container_el || (container_el = ext.panel.last_container);
if(!container_el) return false;
// reset the window height.
container_el.getParent().setStyle('height', 1);
(function() {
container_el.getParent().setStyle('height', '');
}).delay(10, this);
},
open: function(container_el, controller, params, options)
{
params || (params = {});
options || (options = {});
ext.panel.last_container = container_el;
if(params.inject)
{
ext.panel.last_inject = params.inject;
}
if(options.width) container_el.setStyle('width', options.width);
ext.panel.reset_height(container_el);
var appclass = app[controller];
if(!appclass)
{
console.log('panel: error: class app.'+controller+' not found.');
return false;
}
ext.panel.controller = new appclass(params);
comm.bind('addon-controller-release', function() {
comm.unbind_context('panel:controller-release');
ext.panel.release();
}, 'panel:controller-release');
comm.bind('close', function() {
comm.unbind_context('panel_close');
// get the current window (async)
// TODO: make this window-specific somehow (note that all attempts
// to do this reaonably have failed. windows.getCurrent and
// windows.getLastFocused both return a window id that makes the
// popup search turn up empty).
var popup = chrome.extension.getViews({type: 'popup'})[0];
if(popup) popup.close();
}, 'panel:close');
},
release: function()
{
var controller = ext.panel.controller;
if(controller && controller.release) controller.release();
}
};
// listen dor connect/disconnect (lets us know when the panel opens/closes).
// note that the content in the panel (user panel/menu) must manually connect to
// the port we open here.
chrome.runtime.onConnect.addListener(function(port) {
if(port.name != 'panel') return;
comm.trigger('panel-open');
ext.panel.is_open = true;
port.onDisconnect.addListener(function() {
port.onDisconnect.removeListener(arguments.callee);
ext.panel.is_open = false;
comm.trigger('panel-close');
});
});