aboutsummaryrefslogtreecommitdiffstats
path: root/toj/jcs/notice.js
blob: 64e93ef6e4bcabab834f8d411755692b24e3bf93 (plain) (blame)
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
var notice = {
    j_ajax:null,
    enid:null,

    init:function(){
        $('body').on('click',function(e){
            var j_notice;

            if(e.target == null || ($(e.target).parents('a.item').length == 0 && $(e.target).parents('#notice_list').length > 0)){
                return;
            }

            j_notice = $('#index_head_notice');
            if(e.target.id == 'index_head_notice' && !j_notice.hasClass('notice_s')){
                j_notice.addClass('notice_s');
                $('#notice_list_box').stop().animate({width:256},'slow','easeOutExpo');
                $('#notice_list').css('opacity','1').stop().animate({right:0},'slow','easeOutExpo');
                $('#notice_list a.item').stop().animate({left:0},'slow','easeOutQuart');
            }else{
                j_notice.removeClass('notice_s');
                $('#notice_list').stop().animate({opacity:0},'fast','easeOutQuad',
                    function(){
                        $('#notice_list_box').css('width','0px');
                        $('#notice_list').css('right','-256px');
                        $('#notice_list a.item').css('left','50%');
                    }
                );
            }
        });
        $('#index_head_notice').on('click',function(e){
            var j_list;

            j_list = $('#notice_list');
            if(j_list.css('opacity') == 0){
                j_list.empty();
                notice.enid = null;
                notice.updatenew(); 
            }
        }).on('mousedown',function(e){
            return false;
        });

        notice.refresh();
    },
    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_head = j_item.find('div.head');
        j_content = j_item.find('div.content');

        switch(noticeo.type){
            case 'result':
                j_a.attr('href','/toj/stat/allsub/' + noticeo.subid + '/');
                j_head.text('Submit ' + noticeo.subid);
                j_content.html('ProID ' + noticeo.proid + ' 結果: ' + RESULTMAP[noticeo.result] + '<br>' + noticeo.runtime+ 'ms / ' + noticeo.memory + 'KB');
                break;
        }

        return j_item;
    },
    updatenew:function(){
        var j_list;

        if(notice.j_ajax != null){
            notice.j_ajax.abort();
        }

        j_list = $('#notice_list');
        notice.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 = notice.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(notice.enid == null){
                        if(reto.length == 0){
                            notice.enid = 2147483647;
                        }else{
                            notice.enid = reto[0].nid;
                        }
                        notice.updateprev(); 
                    }
                }

                notice.j_ajax = null;
            }
        );
    },
    updateprev:function(){
        var j_list;

        j_list = $('#notice_list');
        $.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':notice.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 = notice.listnew(noticeo);
                        j_list.append(j_item);
                        j_item.find('a.item').stop().animate({left:0},'slow','easeOutQuart');
                    }

                    notice.enid = 0;
                }
            }
        );
    },
    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').css('opacity') == 1){
                            notice.updatenew();
                        }else{
                            j_notice.addClass('notice_h');
                            j_notice.text('[' + count + ']');
                        }
                    }
                    
                    setTimeout(notice.refresh,1000);
                }
            }
        );
    }
};