Skip to content

Commit 62763d5

Browse files
committed
Merge pull request #4 from ghostbody/master
没做完啊啊啊啊啊呜呜呜呜呜
2 parents 5d98f77 + 0fb3700 commit 62763d5

17 files changed

+1060
-0
lines changed
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>环形按钮</title>
5+
<meta charset="utf-8">
6+
<link rel="stylesheet" type="text/css" href="../assert/index.css">
7+
<link rel="icon" sizes="196x196" href="../assert/favicon.png">
8+
<script type="text/javascript" src="../jquery.min.js"></script>
9+
<script type="text/javascript" src="index.js"></script>
10+
</head>
11+
<body>
12+
<div id="at-plus-container">
13+
<div id="bottom-positioner">
14+
<div id="button">
15+
<div id="info-bar">
16+
<div style="display:block" class="info">
17+
<ul>
18+
<li class="big"><span class="sum" disable=""></span></li>
19+
</ul>
20+
</div>
21+
</div>
22+
<div id="control-ring-container">
23+
<ul id="control-ring">
24+
<li class="mask button" state=""><span class="text">A</span><span class="unread"></span></li>
25+
<li class="history button" state=""><span class="text">B</span><span class="unread"></span></li>
26+
<li class="message button" state=""><span class="text">C</span><span class="unread"></span></li>
27+
<li class="setting button" state=""><span class="text">D</span><span class="unread"></span></li>
28+
<li class="sign button" state=""><span class="text">E</span><span class="unread"></span></li>
29+
</ul>
30+
</div>
31+
<div class="apb">
32+
<div class="icon"></div>
33+
</div>
34+
</div>
35+
</div>
36+
</div>
37+
</body>
38+
</html>

group3(afternoon)/13331314/ Lab 5 Start TOP /S1/index.js

+83
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
$ ->
2+
buttons = $ '#control-ring li'
3+
bubble = $ '#info-bar'
4+
5+
buttons.click !->
6+
click-on-a-button @
7+
8+
bubble.click !->
9+
click-on-the-bubble bubble
10+
11+
click-on-a-button = (the-button) !->
12+
disable = $ the-button .attr "state"
13+
if disable isnt "disable" and disable isnt "clicked"
14+
display-the-red-badge the-button
15+
disable-all-other-buttons the-button
16+
get-number-from-the-server the-button
17+
$ the-button .attr "state" "clicked"
18+
19+
display-the-red-badge = (the-button) !->
20+
badge = $ the-button .children '.unread'
21+
badge .css 'display','block' .html '...'
22+
23+
disable-all-other-buttons = (the-button) !->
24+
buttons = $ '#control-ring li'
25+
for button in buttons when button isnt the-button
26+
clicked = $ button .attr "state"
27+
if clicked isnt "clicked"
28+
$ button .attr "state" "disable"
29+
$ button .css "background-color" "#7E7E7E"
30+
31+
get-number-from-the-server = (the-button) ->
32+
do
33+
data <-! $.get '/'
34+
$ the-button .children '.unread' .html data
35+
enable-other-buttons the-button
36+
$ the-button .css "background-color" "#7E7E7E"
37+
38+
enable-other-buttons = (the-button) !->
39+
buttons = $ '#control-ring li'
40+
for button in buttons when button isnt the-button
41+
clicked = $ button .attr "state"
42+
if clicked isnt "clicked"
43+
$ button .attr "state" ""
44+
$ button .css "background-color" "#192E89"
45+
46+
click-on-the-bubble = (bubble) !->
47+
sum-area = $ 'sum'
48+
sum = 0
49+
for button in buttons
50+
if $ button .html is "" or $ button .html is "..."
51+
return
52+
sum += parseInt($ button .children '.unread' .html!)
53+
sum-area .html = sum
54+
55+
56+
57+
58+
initial-atplus = !->
59+
if @mouse-outof-atplus!
60+
@reset-everything!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>环形按钮</title>
5+
<meta charset="utf-8">
6+
<link rel="stylesheet" type="text/css" href="../assert/index.css">
7+
<link rel="icon" sizes="196x196" href="../assert/favicon.png">
8+
<script type="text/javascript" src="index.js"></script>
9+
</head>
10+
<body>
11+
<div id="at-plus-container">
12+
<div id="bottom-positioner">
13+
<div id="button">
14+
<div id="info-bar">
15+
<div style="display:block" class="info">
16+
<ul>
17+
<li class="big"><span class="sum" disable=""></span></li>
18+
</ul>
19+
</div>
20+
</div>
21+
<div id="control-ring-container">
22+
<ul id="control-ring">
23+
<li class="mask button" disable=""><span class="text">A</span><span class="unread"></span></li>
24+
<li class="history button" disable=""><span class="text">B</span><span class="unread"></span></li>
25+
<li class="message button" disable=""><span class="text">C</span><span class="unread"></span></li>
26+
<li class="setting button" disable=""><span class="text">D</span><span class="unread"></span></li>
27+
<li class="sign button" disable=""><span class="text">E</span><span class="unread"></span></li>
28+
</ul>
29+
</div>
30+
<div class="apb">
31+
<div class="icon"></div>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
</body>
37+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// const vars
2+
var MAX_RINGS = 5;
3+
4+
// use a function to get all ring buttons
5+
function getRingButtons() {
6+
return document.getElementsByClassName("button");
7+
}
8+
9+
// main
10+
window.onload = function() {
11+
// initialize the data and style of the whole Ring
12+
Initialization();
13+
var icon = document.getElementsByClassName("apb");
14+
15+
var ringButtons = getRingButtons();
16+
/*
17+
// use clouser for the event onclick for each ring elements
18+
for (var i = 0; i < ringButton.length; i++) {
19+
ringButton[i].onclick = function(i) {
20+
return function() {
21+
// send a requeset to server to get a random number
22+
ServerRequest(ringButton[i].childNodes[1]);
23+
}
24+
}(i);
25+
}
26+
*/
27+
28+
// set a event for the big ring(to sum up all the numbers)
29+
var BigRing = document.getElementById("info-bar");
30+
BigRing.onclick = function() {
31+
// to sum up all the numbers
32+
BigRingCount();
33+
}
34+
35+
icon[0].onclick = function() {
36+
ServerRequest(ringButtons, 0);
37+
}
38+
39+
icon[0].onmouseover = function() {
40+
// for each time the mouse leave the @+, do an initialization
41+
Initialization();
42+
}
43+
}
44+
45+
// initial function, reset all the numbers of the ring and the sum of the big ring
46+
function Initialization() {
47+
ringButton = getRingButtons();
48+
// refers to the big ring
49+
var BigRing = document.getElementById("info-bar");
50+
// refers to the big ring's content
51+
var BigRingContent = document.getElementsByClassName("sum");
52+
BigRingContent[0].innerHTML = "";
53+
54+
for(var i = 0; i < ringButton.length; i++) {
55+
// no red circle beside the ring element
56+
ringButton[i].childNodes[1].style.display = "none";
57+
// the red circle is empty
58+
ringButton[i].childNodes[1].innerHTML = "";
59+
// all ring elements are available to click
60+
ringButton[i].setAttribute("disable", "");
61+
// the background color is reset
62+
ringButton[i].style.backgroundColor = "#1C499E";
63+
}
64+
}
65+
66+
67+
// this function is for handling Server Requests
68+
function ServerRequest(RequestButtons, i) {
69+
theButton = RequestButtons[i].childNodes[1];
70+
var XMLhttp = new XMLHttpRequest();
71+
72+
DisableRingButtons();
73+
74+
theButton.style.display = "block";
75+
RequestButtons[i].style.backgroundColor = "#1C499E";
76+
theButton.innerHTML = "...";
77+
78+
XMLhttp.open("GET","http://localhost:3000/",true);
79+
XMLhttp.send(null);
80+
81+
// callback function for ajax
82+
XMLhttp.onreadystatechange = function() {
83+
if ( XMLhttp.readyState == 4 && XMLhttp.status == 200) {
84+
// get result
85+
var result = XMLhttp.responseText;
86+
// write result
87+
theButton.innerHTML = result;
88+
ActivateRingButtons();
89+
RequestButtons[i].style.backgroundColor = "#999FD3";
90+
// disable thr current button forever
91+
RequestButtons[i].setAttribute("disable", "Disable2")
92+
93+
// robot will continously call it again
94+
if (i < MAX_RINGS-1) {
95+
ServerRequest(RequestButtons, i+1);
96+
} else {
97+
BigRingCount();
98+
}
99+
}
100+
}
101+
102+
}
103+
104+
// disable ring Buttons
105+
function DisableRingButtons() {
106+
var ringButton = getRingButtons();
107+
108+
for (var i = 0; i < ringButton.length; i++) {
109+
if (ringButton[i].getAttribute("disable") != "Disable2") {
110+
ringButton[i].setAttribute("disable", "Disable");
111+
}
112+
ringButton[i].style.backgroundColor = "#999FD3";
113+
}
114+
}
115+
116+
// Activate ring buttons
117+
function ActivateRingButtons() {
118+
var ringButton = getRingButtons();
119+
120+
for (var i = 0; i < ringButton.length; i++) {
121+
if (ringButton[i].getAttribute("disable") != "Disable2") {
122+
ringButton[i].setAttribute("disable", "");
123+
ringButton[i].style.backgroundColor = "#1C499E";
124+
}
125+
}
126+
}
127+
128+
// count the numbers of all ring elements
129+
function BigRingCount() {
130+
var BigRing = document.getElementsByClassName("sum");
131+
var sum = 0;
132+
var ringButtons = getRingButtons();
133+
134+
for (var i = 0; i < ringButtons.length; i++) {
135+
if(ringButtons[i].childNodes[1].innerHTML == "")
136+
return;
137+
sum += parseInt(ringButtons[i].childNodes[1].innerHTML);
138+
}
139+
140+
BigRing[0].innerHTML = sum;
141+
}

0 commit comments

Comments
 (0)