-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjquery.jqDesktop.js
200 lines (188 loc) · 8.75 KB
/
jquery.jqDesktop.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
JQDesktop
=========
JQDesktop jQuery plugin
Copyright (C) 2013 ilyes kooli
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>
*/
(function($){
$.jqDesktop = {version:'1.0'};
var jqDesktopMethods = {
/**
* jqDesktop initialisation
*/
_init: function(options){
/*
* If jqDesktop is called for the first time, append css to document header
*/
if($('head#desktopcss').length==0){
var css = '\
.jqdesktop-window-titlebar-buttons button{width:24px;height:22px;}\n\
.jqdesktop-taskbar-container{cursor:default;margin-right:2px;max-width:250px;}\n\
.jqdesktop-taskbar-container,.jqdesktop-taskbar-icon,.jqdesktop-taskbar-label{float:left}\n\
.jqdesktop-taskbar-label{padding-left: 8px;padding-right: 4px;padding-top: 5px;}\n\
.jqdesktop-icon-container{position: relative;padding: 10px;padding-top: 10px;float:left;}\n\
.jqdesktop-icon-shadow{width:100%; height:100%;border-radius: 8px 8px 8px 8px;padding:4px;}\n\
.jqdesktop-icon{margin-top: -105%;cursor: default;width:100%;height:100%;padding:2px;}\n\
.jqdesktop-icon-image{width:100%;margin-left: 0%;}\n\
.jqdesktop-icon-label{margin-top: 5px;text-align: center;background: none;border: none;width:120%;margin-left: -10%; color:#FFF;}\n\
.jqdesktop-icon-selected{border: #ffffff solid thin;}\n\
';
$('head').append('<style type="text/css">'+css+'</style>');
}
var settings = $.extend({}, $.jqDesktop.defaults, options);
return this.each(function(){
var $this = $(this);
if ($this.data('jqDesktopDesktop')) return; //If plugin is alread initiated abort
var taskBar = $('<div class="jqdesktop-taskbar north ui-widget-content" style="height:'+settings.taskBarHeight+'px">taskbar</div>').jqTaskBar({desktop:$this});
taskBar.sortable({
revert: true
});
var content = $('<div class="jqdesktop-content center ui-widget-content"></div>').css(settings.contentCss);
var statusBar = $('<div class="jqdesktop-statusbar south ui-widget-content" style="height:'+settings.statusBarHeight+'px">statusbar</div>');
$this.html('').append(taskBar).append(content).append(statusBar);
var data = {
taskBar:taskBar,
content:content,
statusBar:statusBar,
settings:settings,
_windows:[]
}
$this.data('jqDesktopDesktop', data);
$this.addClass('ui-widget-content');
$this.jqLayout();
});
},
addWindow: function(jqWindow){
if (!jqWindow) throw 'jqDesktop.addWindow() requires valid jqWindow instance';
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
if (!Window.data('jqDesktopWindow')) throw 'jqDesktop.addWindow() requires valid jqWindow instance';
var data = $this.data('jqDesktopDesktop');
if ($.inArray(Window, data._windows)>-1) return;
data._windows.push(Window);
$(data.content).append(Window);
var windowSettings = Window.data('jqDesktopWindow').settings;
if (windowSettings.showInTaskBar){
data.taskBar.jqTaskBar('addWindow', Window);
}
$.extend(true,Window.data('jqDesktopWindow'),{desktop:$this});
$this.jqDesktop('activateWindow', Window);
$(data.content).append($.jqIcon({window:Window, label:windowSettings.title, icon:windowSettings.icon, width:data.settings.iconWidth,height:data.settings.iconHeight}));
Window.trigger('windowAdded');
});
});
},
activateWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('activateWindow', Window);
});
});
},
minimizeWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('minimizeWindow', Window);
});
});
},
unminimizeWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('unminimizeWindow', Window);
});
});
},
maximizeWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('maximizeWindow', Window);
});
});
},
restoreWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('restoreWindow', Window);
});
});
},
closeWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('closeWindow', Window);
});
});
},
hideWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('hideWindow', Window);
});
});
},
disposeWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('disposeWindow', Window);
});
});
},
showWindow: function(jqWindow){
this.each(function(){
var $this = $(this);
jqWindow.each(function(){
var Window = $(this);
$this.data('jqDesktopDesktop').taskBar.jqTaskBar('showWindow', Window);
});
});
}
};
/**
* jqDesktop plugin entry point
*/
$.fn.jqDesktop = function(method){
if (jqDesktopMethods[method]){//call a method
return jqDesktopMethods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else {
return jqDesktopMethods._init.apply( this, arguments );
}
}
$.jqDesktop.defaults = {
//Dimensions:
taskBarHeight:30,
statusBarHeight:30,
//
showTaskBar:true,
contentCss:{},
iconWidth:100,
iconHeight:100
}
})(jQuery);