-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.js
96 lines (90 loc) · 2.73 KB
/
home.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
$(function(){
var remoteSections = { reading:1,resume:1};
var sections = [];
var requestSection = window.location.hash.replace(/_/,"");
var currentIdx = 0;
$("div.section").each(function(){
if("#"+this.id == requestSection){
currentIdx = sections.length;
}
sections[sections.length] = this.id;
});
var currentSection;
var selectBtn = function(btn){
$("#"+btn+"-btn .btnbg").attr("src", "img/buttonselected.png")
$("#"+btn+"-btn").animate({width:160});
};
var deselectBtn = function(btn){
$("#"+btn+"-btn .btnbg").attr("src", "img/buttonnormal.png")
$("#"+btn+"-btn").animate({width:128});
};
var clickHandler = function(name){
return function(){
if(currentSection && currentSection != name){
deselectBtn(currentSection);
}
if(remoteSections[name]){
if(currentSection)
$("#"+currentSection).fadeOut(200);
$.get(name+".html",
function(data){
$("#"+name).html(data).fadeIn(200);
},
function(){alert("Failed to fetch section "+name);});
} else {
if(currentSection)
$("#"+currentSection).fadeOut(200, function(){ $("#"+name).fadeIn(200); });
else
$("#"+name).fadeIn(200);
}
selectBtn(name);
currentSection = name;
window.location.hash = "_"+name;
}
}
var inHandler = function(name){
return function(){
if(currentSection != name){
$("#"+name+"-btn .btnbg").attr("src", "img/buttonhover.png");
}
}
}
var outHandler = function(name){
return function(){
if(currentSection != name){
$("#"+name+"-btn .btnbg").attr("src", "img/buttonnormal.png");
}
}
}
for(var i=0;i<sections.length;++i){
var btn = sections[i];
var btnId = "#"+btn+"-btn";
$(btnId).click(clickHandler(btn)).mouseenter(inHandler(btn)).mouseleave(outHandler(btn));
if(i == currentIdx)
$(btnId).click();
}
// var homebg = Raphael("homebg", 400, 400);
// homebg.circle(0, 0, 50).attr({"stroke":"#bbf", "stroke-width":2});
// Initial placement for love items
var center = { x: 329, y: 80 };
var r = {x:240, y:60 };
var yfactor = r.y / (1.0 * r.x);
var loveItems = $(".love-item");
var nLoveItems = loveItems.length;
var angleStep = 360 / nLoveItems;
var initAngle = 0;
var lx = 100 / 2.0, ly = 40 / 2.0;
var updateFn = function(){
var angle = initAngle;
loveItems.each(function(){
var x = center.x - Math.sin(Math.PI * angle / 180) * r.x - lx;
var y = center.y + yfactor * ( Math.cos(Math.PI * angle / 180) * r.x ) - ly;
angle += angleStep;
$(this).css({top: y + "px", left: x + "px" });
});
initAngle += .2;
initAngle = (initAngle+360) % 360; // watch out, I think this converts to int first
setTimeout(updateFn, 400);
};
updateFn();
});