forked from klutzy/mine.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mswin.js
147 lines (137 loc) · 4.58 KB
/
jquery.mswin.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
146
147
(function($, undefined) {
$.widget( "mswin.window", {
_create: function() {
var _this = this;
this.taskbar = $( ".taskbar" ); // TODO: specify as an argument
this.element.resizable({
handles: "all",
alsoResize: this.element.find( ".window-content" ),
});
this.element.draggable({
handle: ".title",
start: function( event ) {
// XXX: should bring the window to front on mousedown, not just dragstart
_this.select();
},
});
this._on({
"click": function( event ) {
if ($( event.target ).is( ".title-button" )) {
return;
}
this.select();
},
"click .title-button.minimize": function( event ) {
this.element.hide();
this.unselect();
},
"click .title-button.maximize": function( event ) {
this.maximize();
},
"click .title-button.restore": function( event ) {
this.restore();
},
"click .title-button.close": function( event ) {
this.element.hide(); // XXX: should it be really closed or what
},
"dblclick .title": function( event ) {
if (this.element.hasClass( "maximized" )) {
this.restore();
}
else {
this.maximize();
}
},
});
$( window ).resize($.proxy(function() {
this.resize();
}, this));
if (this.element.hasClass( "maximized" )) {
this.maximize();
}
else {
this.restore();
}
this.task_element = $("<div class='task'></div>");
var tasks = this.taskbar.find(".tasks");
tasks.append(this.task_element);
var title_icon = this.element.find(".title-icon");
var title_icon_clone = title_icon.clone();
var p = 'background-image';
title_icon_clone.css(p, title_icon.css(p));
p = 'background-position';
title_icon_clone.css(p, title_icon.css(p));
this.task_element
.append(title_icon_clone)
.append($("<div class='title-wrapper'><span>" + this.element.find(".title").text() + "</span></div>"))
.on("click", $.proxy( this.taskClick, this ));
this.select();
},
maximize: function() {
// TODO: animation
this._offset = this.element.offset();
this._width = this.element.width();
this._height = this.element.height();
this.element
.draggable( "disable" )
.addClass( "maximized" )
.css({
left: "auto",
top: "0",
width: "100%",
height: "auto",
});
this.element.find( ".title-button.maximize" )
.removeClass( "maximize" )
.addClass( "restore" );
this.resize();
},
restore: function() {
// TODO: animation
this.element
.removeClass( "maximized" )
.draggable( "enable" )
.css({ bottom: "auto" })
.offset( this._offset )
.width( this._width )
.height( this._height );
this.element.find( ".title-button.restore" )
.removeClass( "restore" )
.addClass( "maximize" );
},
resize: function() {
if (this.element.hasClass( "maximized" )) {
this.element.css({
bottom: this.taskbar.height() + "px",
});
}
},
select: function() {
$( ":mswin-window .title-bar.ui-selected" ).removeClass( "ui-selected" );
this.element.find( ".title-bar" ).addClass( "ui-selected" );
if (!this.element.is( ":visible" )) {
this.element.show();
}
// taskbar
$( ":mswin-window" ).each( function() {
$( this ).data( "mswin-window" ).unselect();
});
this.task_element.addClass( "selected" );
// bring window to the front
this.element.css({ "z-index": 1000 }); // TODO: should be less than taskbar
},
unselect: function() {
this.task_element.removeClass( "selected" );
this.element.css({ "z-index": 0 });
},
taskClick: function() {
if (this.task_element.is( ".selected" )) {
this.unselect();
this.element.hide();
}
else {
this.select();
}
},
});
}(jQuery));