-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinimize.js
executable file
·108 lines (89 loc) · 3.25 KB
/
Minimize.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
/**
* The author disclaims copyright to this source code. In place of
* a legal notice, here is a blessing:
*
* May you do good and not evil.
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
*/
Ext.define('Ext.ux.plugin.minimize.Minimize', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.Minimize',
requires: ['Ext.ux.plugin.minimize.MinimizePool'],
init: function(window){
//TODO verificar se é window
window.minimizable = true;
window.minimized = false;
Ext.ux.plugin.minimize.MinimizePool._windows.add(window);
if(Ext.ux.plugin.minimize.MinimizePool.toggleMode == 'toggle'){
var title = window.minimizedTitle || window.title;
var buttonConfig = {
window: window,
text: title,
enableToggle: true,
pressed: true,
toggleHandler: this.toggleHandler
};
var button = this.addMinimizedButton(buttonConfig);
window.on('minimize', this.toggleMinimizeHandler, this, {button: button});
window.on('beforeclose', this.closeWindow, this, {button: button});
window.on('titlechange', this.changeTitle, this, {button: button});
}
else if(Ext.ux.plugin.minimize.MinimizePool.toggleMode == 'hide'){
window.on('minimize', this.hideMinimizeHandler, this);
window.on('beforeclose', this.closeWindow, this);
}
},
changeTitle: function(window, newTitle, oldTitle, opts){
if(!window.minimizedTitle){
var button = opts.button;
button.setText(newTitle);
}
},
addMinimizedButton: function(config){
var minimizePanel = Ext.ux.plugin.minimize.MinimizePool.minimizePanel,
pos = minimizePanel.items.length - 2;
for(var attrname in Ext.ux.plugin.minimize.MinimizePool.buttonConfig){
config[attrname] = Ext.ux.plugin.minimize.MinimizePool.buttonConfig[attrname];
}
var button = Ext.create('Ext.button.Button', config);
minimizePanel.insert(pos, button);
return button;
},
hideMinimizeHandler: function(window){
var title = window.minimizedTitle || window.title;
var buttonConfig = {
window: window,
text: title,
handler: this.showHandler
};
this.addMinimizedButton(buttonConfig);
window.minimized = true;
window.hide();
},
closeWindow: function(window, opts){
var button = opts.button;
if(button){
button.destroy();
}
Ext.ux.plugin.minimize.MinimizePool._windows.removeAtKey(window.id);
},
toggleMinimizeHandler: function(window, opts){
var button = opts.button;
button.toggle(false);
},
showHandler: function(){
this.window.minimized = false;
this.window.show();
this.destroy();
},
toggleHandler: function(button, state){
//TODO animation
this.window.minimized = !state;
if(state){
this.window.show();
} else {
this.window.hide();
}
}
});