metanohi-misc-subsites/old-projects/dsktp/script.js

589 lines
14 KiB
JavaScript

/*
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://sam.zoy.org/wtfpl/COPYING for more details.
*/
/*
This code is MESSY! It is UNCOMMENTED! It is JAVASCRIPT!
In short: It's not perfect. WTF.
*/
lw=true
selected=false
x=0
y=0
index=0
opts=true
ccl=null
cmi=null
cemd=null
menuh=30
lsp=0
ll=false
nom=0
dpc=0
mst=0
function mdown(num) {
c=0
for (i=0;i<windows.childNodes.length;i++) {
node=windows.childNodes[i]
if (node.nodeName=="DIV") {
if (c==num) {
node.id="select"
node.style.zIndex=index
if (node.lang=="g") {
node.lang=""
nom-=1
node.style.display="block"
}
}
else {
node.id=""
if (bnz[c]>bnz[num]) {
bnz[c]-=1
node.style.zIndex=bnz[c]
}
}
c+=1
}
}
bnz[num]=index
document.getElementById("select").id="selected"
offl=document.getElementById("selected").offsetLeft
offt=document.getElementById("selected").offsetTop
xcoor=x-offl
ycoor=y-offt
xm=xcoor
ym=ycoor
c=0
for (i=0;i<menuc.childNodes.length;i++) {
node=menuc.childNodes[i]
if (node.className=="entry") {
if (c==num) node.id="es"
else node.id=""
c+=1
}
}
document.getElementById("es").id="ese"
selected=true
}
function mup() {
selected=false
}
function movewindow(e) {
try {
x=e.pageX
y=e.pageY
}
catch(err) {
x=event.clientX+document.documentElement.scrollLeft
y=event.clientY+document.documentElement.scrollTop
}
if (document.getElementById("selected")) {
sd=document.getElementById("selected")
offl=sd.offsetLeft
offt=sd.offsetTop
xcoor=x-offl
ycoor=y-offt
}
getwh()
h-=menuh
if (selected && y>0 && x>0 && y<h && x<w) {
sd.style.left=x-xm+"px"
sd.style.top=y-ym+"px"
}
}
function getwh() {
if (self.innerHeight) {
w=self.innerWidth
h=self.innerHeight
}
else if (document.documentElement && document.documentElement.clientHeight) {
w=document.documentElement.clientWidth
h=document.documentElement.clientHeight
}
else if (document.body) {
w=document.body.clientWidth
h=document.body.clientHeight
}
}
function ccn() {
ccl=null
cmi=null
c=0
for (i=0;i<windows.childNodes.length;i++) {
node=windows.childNodes[i]
if (node.nodeName=="DIV") {
for (ii=0;ii<node.childNodes.length;ii++) {
nodeb=node.childNodes[ii]
if (nodeb.className=="closesh") nodeb.className="close"
else if (nodeb.className=="minimizesh") nodeb.className="minimize"
}
c+=1
}
}
for (i=0;i<menuc.childNodes.length;i++) {
node=menuc.childNodes[i]
if (node.className=="entryb") node.className="entry"
}
if (document.getElementById("eseb")) document.getElementById("eseb").id="ese"
}
function isnumeric(num) {
num=num*1+1
if (!num) return false
else return true
}
function closewindow(num) {
c=0
for (i=0;i<windows.childNodes.length;i++) {
node=windows.childNodes[i]
if (node.nodeName=="DIV") {
if (c==num) {
bnz.splice(c,1)
node.style.display="none"
node.className="remove"
}
else if (c>num) {
for (ii=0;ii<node.childNodes.length;ii++) {
nodeb=node.childNodes[ii]
if (nodeb.nodeName=="P") {
for (iii=0;iii<nodeb.childNodes.length;iii++) {
nodec=nodeb.childNodes[iii]
if (nodec.nodeName=="DIV") nodec.className=c-1
}
}
else if (nodeb.nodeName=="DIV" && isnumeric(nodeb.className)) nodeb.className=c-1
else if (nodeb.className=="close" || nodeb.className=="minimize") nodeb.lang=c-1
}
}
c+=1
}
}
index-=1
for (i=0;i<bnz.length;i++) {
if (bnz[i]==index-nom) bnh=i
}
for (i=0;i<windows.childNodes.length;i++) {
node=windows.childNodes[i]
if (node.className=="remove") windows.removeChild(node)
}
c=0
for (i=0;i<menuc.childNodes.length;i++) {
node=menuc.childNodes[i]
if (node.className=="entry") {
if (c==num) {
node.style.display="none"
node.id="eremove"
}
else if (c>num) {
node.lang=c-1
}
c+=1
}
}
menuc.removeChild(document.getElementById("eremove"))
if (index>nom) {
mdown(bnh)
mup()
}
checkscroll()
}
function istop(num) {
num=num*1
for (i=0;i<bnz.length;i++) {
if (bnz[i]==index-nom) bnh=i
}
if (num==bnh) return true
else return false
}
function openwindow(wheader,wcontent,wwidth,wheight,maxornot) {
if (opts) {
index+=1
entry=document.createElement("div")
entry.className="entry"
entry.innerHTML=wheader
entry.lang=index-1
entry.onmousedown=function(){if (this.id!="ese") {cemd=this.lang;this.className="entryc"} else {this.id="esec"}}
entry.onmouseup=function(){if (this.id!="esec") {cemd=null;this.className="entry"} else {this.id="ese"}}
entry.onmouseout=function(){if (this.id=="esec") {this.id="eseb"} else if (this.className=="entryc") this.className="entryb"}
entry.onclick=function(){if (this.id!="ese" && this.id!="eseb") {mdown(this.lang);mup()} else {minimizewindow(this.lang)}}
menuc.appendChild(entry)
nwdiv=document.createElement("div")
nwp=document.createElement("p")
nwpd=document.createElement("div")
nwpca=document.createElement("div")
nwpmina=document.createElement("div")
nwd=document.createElement("div")
nwd.className=index-1
nwd.onmousedown=function(){if (!istop(this.className)) {mdown(this.className);mup()}}
nwpd.className=index-1
nwpd.onmousedown=function(){mdown(this.className)}
nwpd.onmouseup=function(){mup()}
nwpca.className="close"
nwpca.lang=index-1
nwpmina.className="minimize"
nwpmina.lang=index-1
nwpca.onmousedown=function(){ccl=this.lang;mdown(this.lang);mup();this.className="closec"}
nwpca.onmouseup=function(){if (this.lang==ccl) {ccl=null;closewindow(this.lang)}}
nwpmina.onmousedown=function(){cmi=this.lang;mdown(this.lang);mup();this.className="minimizec"}
nwpmina.onmouseup=function(){if (this.lang==cmi) {cmi=null;minimizewindow(this.lang)}}
nwpca.onmouseout=function(){if (this.lang==ccl) this.className="closesh"; else this.className="close"}
nwpmina.onmouseout=function(){if (this.lang==cmi) this.className="minimizesh"; else this.className="minimize"}
nwdiv.appendChild(nwpca)
nwdiv.appendChild(nwpmina)
nwp.innerHTML=wheader
nwp.appendChild(nwpd)
nwd.innerHTML=wcontent
nwdiv.appendChild(nwp)
nwdiv.appendChild(nwd)
qwidth=wwidth
qheight=wheight
mon=maxornot
nwdiv.style.width=qwidth+"px"
if (mon) nwdiv.style.height=qheight-22+"px"
nwdiv.style.zIndex=index
windows.appendChild(nwdiv)
bnz[index-1]=index
mdown(index-1)
mup()
opts=false
setTimeout("openwindow()",1)
}
else if (nwdiv.scrollWidth==0 || nwdiv.scrollHeight==0) {
setTimeout("openwindow()",1)
}
else {
nwh=nwdiv.scrollHeight
if (nwdiv.scrollHeight>qheight || mon) {
if (mon) nwdiv.style.height=qheight+"px"
for (i=0;i<nwdiv.childNodes.length;i++) {
node=nwdiv.childNodes[i]
if (node.nodeName=="DIV" && isnumeric(node.className)) {
node.style.height=qheight-22+"px"
}
}
nwh=qheight
}
opts=true
getwh()
h-=menuh
nwdiv.style.top=(h-nwh)/2+"px"
nwdiv.style.left=(w-nwdiv.scrollWidth)/2+"px"
nwdiv.className="show"
checkscroll()
}
}
function minimizewindow(num) {
nom+=1
c=0
for (i=0;i<windows.childNodes.length;i++) {
node=windows.childNodes[i]
if (node.nodeName=="DIV") {
if (c==num) {
node.style.display="none"
bnz[c]=1
node.style.zIndex=1
node.lang="g"
}
else {
bnz[c]+=1
node.style.zIndex=bnz[c]
}
c+=1
}
}
c=0
for (i=0;i<menuc.childNodes.length;i++) {
node=menuc.childNodes[i]
if (node.className=="entry") {
if (c==num) {
node.id=""
}
c+=1
}
}
for (i=0;i<bnz.length;i++) {
if (bnz[i]==index) tnt=i
}
if (index>nom) {
mdown(tnt)
mup()
}
}
function godesktop() {
if (index>0) {
mdown(dpc)
mup()
minimizewindow(dpc)
dpc+=1
if (dpc<index) {
setTimeout("godesktop()",1)
}
else dpc=0
}
}
function cnellh() {
if (ll) {
listslided()
}
}
function listslided() {
if (lsp>0) {
lsp-=10
launchlist.style.height=lsp+"%"
llto=setTimeout("listslided()",1)
}
else {
launch.className=""
ll=false
}
}
function listslideu() {
if (lsp<80) {
lsp+=10
launchlist.style.height=lsp+"%"
llto=setTimeout("listslideu()",1)
}
else {
ll=true
}
}
function launchtlist() {
if (!ll) {
launch.className="click"
listslideu()
}
}
function checkscroll() {
msh=menuc.scrollHeight
if (msh>26) {
scrollmenu.className="v"
menuc.scrollTop=mst
}
else {
menuc.scrollTop=0
//mst=menuc.scrollTop
scrollmenu.className=""
}
}
function scrolltmenu(ud) {
msh=menuc.scrollHeight
if (ud) {
menuc.scrollTop+=26
}
else {
menuc.scrollTop-=26
}
mst=menuc.scrollTop
}
function load() {
if (lw) {
stylesheet=document.createElement("link")
stylesheet.rel="stylesheet"
stylesheet.type="text/css"
stylesheet.href="style.css"
head=document.getElementsByTagName("head")[0]
head.appendChild(stylesheet)
windows=document.createElement("div")
windows.id="windows"
windows.onmousedown=function(){cnellh()}
menu=document.createElement("div")
menuc=document.createElement("div")
menuc.id="menuc"
menu.id="menu"
menu.onmousedown=function(){cnellh()}
menu.appendChild(menuc)
launch=document.createElement("div")
launch.id="launch"
launch.onmousedown=function(){launchtlist()}
desktop=document.createElement("div")
desktop.id="desktop"
desktop.onmousedown=function(){this.className="click"}
desktop.onmouseup=function(){this.className=""}
desktop.onclick=function(){godesktop()}
scrollmenu=document.createElement("div")
scrollmenu.id="scrollmenu"
scrollup=document.createElement("div")
scrollup.id="scrollup"
scrollup.onmousedown=function(){this.className="click"}
scrollup.onmouseout=function(){this.className=""}
scrollup.onclick=function(){this.className="";scrolltmenu(false)}
scrolldown=document.createElement("div")
scrolldown.id="scrolldown"
scrolldown.onmousedown=function(){this.className="click"}
scrolldown.onmouseout=function(){this.className=""}
scrolldown.onclick=function(){this.className="";scrolltmenu(true)}
scrollmenu.appendChild(scrollup)
scrollmenu.appendChild(scrolldown)
menu.appendChild(launch)
menu.appendChild(desktop)
menu.appendChild(scrollmenu)
launchlist=document.createElement("div")
launchlistc=document.createElement("div")
launchlistcc=document.createElement("div")
launchlist.id="launchlist"
launchlistc.id="launchlistc"
launchlistcc.id="launchlistcc"
ghjkl="sdgtsdgh sh sdf sfdh sdf hdfh dfdfx hgf gfj gfj gfj gfj gfj gfj gfgfj gf gfj gf jg gf j g gfj dj jyfrdj uy dju ydjy jgf jfryj drj d fhjf5d 4df5j 1651j gf6j15dr6j156 1ty5j 6dfy1j 6df1j 56dy1j 56dy1j56 1d6j1 d5f6j1 df56j1 xhfx hf hfd hdf hxdf hdf sfgj fghjftr sjsfjfgjfgjfgj sdgsgsdfg sadfg asdg as gsd sdfag sadfg sagra ergrh adf"
welctxt="Welcome to dsktp! Browse through all the cool stuff in the \"Launch\" menu. If you're using Firefox or IE7, you shouldn't have any problems viewing this site. Safari hasn't been tested properly, but there seem to be no problems. Opera appears to have some issues with the \"Launch\" menu where the items aren't showing. Explore!"
programs=new Array()
program=new Array()
programimg=new Array()
programs[0]=new Array()
programs[0][0]="Program 1"
programs[0][1]="1st program"
programs[0][2]="Random content...<br />asga dhgs 8fd4 9 s fhas dhszf gzss sdg 5s s 5 dg5dfh adfh!"+ghjkl
programs[0][3]=200
programs[0][4]=150
programs[0][5]=false
programs[0][6]=null
programs[1]=new Array()
programs[1][0]="Program 2"
programs[1][1]="2nd program"
programs[1][2]="Random content...<br />asga dhgsdfdf 8df458 df dfh fhass gsd8 49 s489 dhdfh adfh!"
programs[1][3]=200
programs[1][4]=150
programs[1][5]=true
programs[1][6]=null
programs[2]=new Array()
programs[2][0]="Program 3"
programs[2][1]="3rd program"
programs[2][2]="Random content...<br />asdf hxdf hxdf dh dth th ga dhgsfgj dfhhas dh 5g4dfh adfh!"
programs[2][3]=100
programs[2][4]=300
programs[2][5]=false
programs[2][6]="qmark"
nop=programs.length
for (i=0;i<nop;i++) {
program[i]=document.createElement("div")
programimg[i]=document.createElement("div")
if (programs[i][6]) programimg[i].style.backgroundImage="url(icons/"+programs[i][6]+".png)"
program[i].innerHTML=programs[i][0]
program[i].lang=i
program[i].onclick=function(){listslided();openwindow(programs[this.lang][1],programs[this.lang][2],programs[this.lang][3],programs[this.lang][4],programs[this.lang][5])}
program[i].appendChild(programimg[i])
launchlistcc.appendChild(program[i])
}
launchlistc.appendChild(launchlistcc)
launchlist.appendChild(launchlistc)
document.body.appendChild(windows)
document.body.appendChild(menu)
bnz=new Array()
img=new Array()
img[0]=new Image()
img[0].src="img/closec.png"
img[1]=new Image()
img[1].src="img/closeh.png"
img[2]=new Image()
img[2].src="img/desktopc.png"
img[3]=new Image()
img[3].src="img/desktoph.png"
img[4]=new Image()
img[4].src="img/entryc.png"
img[5]=new Image()
img[5].src="img/entryh.png"
img[6]=new Image()
img[6].src="img/entrysel.png"
img[7]=new Image()
img[7].src="img/entryselc.png"
img[8]=new Image()
img[8].src="img/entryselh.png"
img[9]=new Image()
img[9].src="img/launchc.png"
img[10]=new Image()
img[10].src="img/launchh.png"
img[11]=new Image()
img[11].src="img/lleh.png"
img[12]=new Image()
img[12].src="img/minmizec.png"
img[13]=new Image()
img[13].src="img/minimizeh.png"
img[14]=new Image()
img[14].src="img/scrolldownc.png"
img[15]=new Image()
img[15].src="img/scrollupc.png"
img[16]=new Image()
img[16].src="img/top.png"
lw=false
setTimeout("load()",100)
}
else {
document.body.appendChild(launchlist)
openwindow("Welcome",welctxt,200,200)
rgh()
}
}
werty=0
sdfg=0
tnhjy=0
function rgh() {
if (tnhjy>0) {
if (sdfg==0) {
sdfg=1
if (werty<tnhjy) setTimeout("rgh()",50)
}
else {
openwindow("Hmm ..."+werty,"asdG SDHdfhDFAGH swahWRHAYU!",170)
werty+=1
sdfg=0
setTimeout("rgh()",50)
}
}
}
window.onload=load
window.onresize=checkscroll
document.onmousemove=movewindow
document.onmouseup=ccn