-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
145 lines (123 loc) · 5.48 KB
/
script.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
/*################################################################################
##################################################################################
########## ###########
########## ###########
########## Windows Template by ###########
########## https://html5-templates.com/ ###########
########## ###########
########## All rights reserved. ###########
########## ###########
##################################################################################
################################################################################*/
var i = 0,
minimizedWidth = new Array,
minimizedHeight = new Array,
windowTopPos = new Array,
windowLeftPos = new Array,
panel,
id;
function adjustFullScreenSize() {
$(".fullSizeWindow .wincontent").css("width", (window.innerWidth - 32));
$(".fullSizeWindow .wincontent").css("height", (window.innerHeight - 98));
}
function makeWindowActive(thisid) {
$(".window").each(function() {
$(this).css('z-index', $(this).css('z-index') - 1);
});
$("#window" + thisid).css('z-index',1000);
$(".window").removeClass("activeWindow");
$("#window" + thisid).addClass("activeWindow");
$(".taskbarPanel").removeClass('activeTab');
$("#minimPanel" + thisid).addClass("activeTab");
}
function minimizeWindow(id){
windowTopPos[id] = $("#window" + id).css("top");
windowLeftPos[id] = $("#window" + id).css("left");
$("#window" + id).animate({
top: 800,
left: 0
}, 200, function() { //animation complete
$("#window" + id).addClass('minimizedWindow');
$("#minimPanel" + id).addClass('minimizedTab');
$("#minimPanel" + id).removeClass('activeTab');
});
}
function openWindow(id) {
if ($('#window' + id).hasClass("minimizedWindow")) {
openMinimized(id);
} else {
makeWindowActive(id);
$("#window" + id).removeClass("closed");
$("#minimPanel" + id).removeClass("closed");
}
}
function closeWindwow(id) {
$("#window" + id).addClass("closed");
$("#minimPanel" + id).addClass("closed");
}
function openMinimized(id) {
$('#window' + id).removeClass("minimizedWindow");
$('#minimPanel' + id).removeClass("minimizedTab");
makeWindowActive(id);
$('#window' + id).animate({
top: windowTopPos[id],
left: windowLeftPos[id]
}, 200, function() {
});
}
$(document).ready(function(){
$(".window").each(function() { // window template
$(this).css('z-index',1000)
$(this).attr('data-id', i);
minimizedWidth[i] = $(this).width();
minimizedHeight[i] = $(this).height();
windowTopPos[i] = $(this).css("top");
windowLeftPos[i] = $(this).css("left");
$("#taskbar").append('<div class="taskbarPanel" id="minimPanel' + i + '" data-id="' + i + '">' + $(this).attr("data-title") + '</div>');
if ($(this).hasClass("closed")) { $("#minimPanel" + i).addClass('closed'); }
$(this).attr('id', 'window' + (i++));
$(this).wrapInner('<div class="wincontent"></div>');
$(this).prepend('<div class="windowHeader"><strong>' + $(this).attr("data-title") + '</strong><span title="Minimize" class="winminimize"><span></span></span><span title="Maximize" class="winmaximize"><span></span><span></span></span><span title="Close" class="winclose">x</span></div>');
});
$("#minimPanel" + (i-1)).addClass('activeTab');
$("#window" + (i-1)).addClass('activeWindow');
$( ".wincontent" ).resizable(); // resizable
$( ".window" ).draggable({ cancel: ".wincontent" }); // draggable
$(".window").mousedown(function(){ // active window on top (z-index 1000)
makeWindowActive($(this).attr("data-id"));
});
$(".winclose").click(function(){ // close window
closeWindwow($(this).parent().parent().attr("data-id"));
});
$(".winminimize").click(function(){ // minimize window
minimizeWindow($(this).parent().parent().attr("data-id"));
});
$(".taskbarPanel").click(function(){ // taskbar click
id = $(this).attr("data-id");
if ($(this).hasClass("activeTab")) { // minimize if active
minimizeWindow($(this).attr("data-id"));
} else {
if ($(this).hasClass("minimizedTab")) { // open if minimized
openMinimized(id);
} else { // activate if inactive
makeWindowActive(id);
}
}
});
$(".openWindow").click(function(){ // open closed window
openWindow($(this).attr("data-id"));
});
$(".winmaximize").click(function(){
if ($(this).parent().parent().hasClass('fullSizeWindow')) { // minimize
$(this).parent().parent().removeClass('fullSizeWindow');
$(this).parent().parent().children(".wincontent").height(minimizedHeight[$(this).parent().parent().attr("data-id")]);
$(this).parent().parent().children(".wincontent").width(minimizedWidth[$(this).parent().parent().attr("data-id")]);
} else { // maximize
$(this).parent().parent().addClass('fullSizeWindow');
minimizedHeight[$(this).parent().parent().attr('data-id')] = $(this).parent().parent().children(".wincontent").height();
minimizedWidth[$(this).parent().parent().attr('data-id')] = $(this).parent().parent().children(".wincontent").width();
adjustFullScreenSize();
}
});
adjustFullScreenSize();
});