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
|
var notice = new function(){
var that = this;
var j_ajax = null;
var enid = null;
var listnew = function(noticeo){
j_item = $('<li class="item"><a class="item"><div class="head"></div><div class="content"></div></a></li>')
j_a = j_item.find('a.item');
j_a.on('click',function(e){
that.hide();
});
j_head = j_item.find('div.head');
j_content = j_item.find('div.content');
switch(noticeo.type){
case 'result':
j_a.attr('href','/toj/m/sub/' + noticeo.subid + '/res/');
if(noticeo.rejudge_flag == false){
j_head.text('Submit ' + noticeo.subid);
}else{
j_head.text('Rejudge ' + noticeo.subid);
}
j_content.html('ProID ' + noticeo.proid + ' 結果: ' + RESULTMAP[noticeo.result] + ' 分數: ' + noticeo.score + '<br>' +
noticeo.runtime+ 'ms / ' + noticeo.memory + 'KB');
break;
}
return j_item;
};
var updatenew = function(){
var j_list;
if(j_ajax != null){
j_ajax.abort();
}
j_list = $('#notice_list');
j_ajax = $.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':0,'count':10})},
function(res){
var i;
var reto;
var noticeo;
var j_item;
var j_a;
if(res[0] != 'E'){
reto = JSON.parse(res);
for(i = 0;i < reto.length;i++){
noticeo = JSON.parse(reto[i].txt);
j_item = listnew(noticeo);
j_list.prepend(j_item);
j_a = j_item.find('a.item');
j_a.addClass('item_h');
j_a.stop().animate({left:0},'slow','easeOutQuart');
}
if(enid == null){
if(reto.length == 0){
enid = 2147483647;
}else{
enid = reto[0].nid;
}
updateprev();
}
}
j_ajax = null;
}
);
};
var updateprev = function(){
var j_list;
j_list = $('#notice_list');
$.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':enid,'count':10})},
function(res){
var i;
var reto;
var noticeo;
var j_item;
if(res[0] != 'E'){
reto = JSON.parse(res);
for(i = reto.length - 1;i >= 0;i--){
noticeo = JSON.parse(reto[i].txt);
j_item = listnew(noticeo);
j_list.append(j_item);
j_item.find('a.item').stop().animate({left:0},'slow','easeOutQuart');
}
enid = 0;
}
}
);
};
var refresh = function(){
$.post('/toj/php/notice.php',{'action':'count','data':JSON.stringify({})},
function(res){
var count;
var j_notice;
if(res[0] != 'E'){
count = JSON.parse(res);
j_notice = $('#index_head_notice');
if(count == 0){
j_notice.removeClass('notice_h');
j_notice.text('[' + count + ']');
}else{
if($('#notice_list_box').css('opacity') == 1){
updatenew();
}else{
j_notice.addClass('notice_h');
j_notice.text('[' + count + ']');
}
}
setTimeout(refresh,2000);
}
}
);
};
that.init = function(){
$(window).on('click',function(e){
var j_notice;
if(e.target == null || ($(e.target).parents('a.item').length == 0 && $(e.target).parents('#notice_list_box').length > 0)){
return;
}
j_notice = $('#index_head_notice');
if(e.target.id == 'index_head_notice' && !j_notice.hasClass('notice_s')){
that.show();
}else if(j_notice.hasClass('notice_s')){
that.hide();
}
});
$('#index_head_notice').on('click',function(e){
var j_list;
j_list = $('#notice_list');
if($('#notice_list_box').css('opacity') == 0){
j_list.empty();
enid = null;
updatenew();
}
}).on('mousedown',function(e){
return false;
});
refresh();
};
that.show = function(){
index.page_scroll_lock();
$('#index_head_notice').addClass('notice_s');
$('#notice_list_box').stop().css('opacity','1').animate({width:322},'slow','easeOutExpo');
$('#notice_list a.item').stop().animate({left:0},'slow','easeOutQuart');
};
that.hide = function(){
$('#index_head_notice').removeClass('notice_s');
$('#notice_list_box').stop().animate({opacity:0},'fast','easeOutQuad',
function(){
$('#notice_list_box').css('width','0px');
$('#notice_list a.item').css('left','50%');
index.page_scroll_unlock();
}
);
};
};
|