aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/index.js
blob: 1058dc8f5dfc2ecf44160f15b5d0b6eb45224842 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'use strict'

var index = new function(){
    var that = this;
    var j_win;
    var j_menutag;
    var j_menu;
    var j_paneltag;
    var j_panel;
    var j_header;
    var j_alertbox;

    function active_header(){
        j_header.addClass('active');
    }
    function inactive_header(){
        if(j_win.scrollTop() > 8 && !j_header.hasClass('force')){
            j_header.removeClass('active');
        }
    }
    function active_menutag(){
        j_menutag.addClass('active');
    };
    function inactive_menutag(){
        if(j_win.scrollTop() > 8 && !j_menutag.hasClass('force') && !j_menu.hasClass('active')){
            j_menutag.removeClass('active');
        }
    };
    function active_paneltag(){
        j_paneltag.addClass('active');
    };
    function inactive_paneltag(){
        if(j_win.scrollTop() > 8 && !j_paneltag.hasClass('force') && !j_panel.hasClass('active')){
            j_paneltag.removeClass('active');
        }
    };
    function active_menu(){
        j_menu.addClass('active');
        active_menutag();
    };
    function inactive_menu(){
        j_menu.removeClass('active');
        inactive_menutag();
    };
    function active_panel(){
        j_panel.addClass('active');
        active_paneltag();
    };
    function inactive_panel(){
        j_panel.removeClass('active');
        inactive_paneltag();
    };
    
    that.ready = function(){
        j_win = $(window);
        j_menutag = $('#index_menutag');
        j_menu = $('#index_menu');
        j_paneltag = $('#index_paneltag');
        j_panel = $('#index_panel');
        j_header = $('#index_header');
        j_alertbox = $('#index_alert');

        function _change(){
            if(j_win.scrollTop() <= 8){
                active_header();
                active_menutag();
                active_paneltag();
            }else{
                inactive_header();
                inactive_menutag();
                inactive_paneltag();
            }
        }
        
        j_win.on('scroll',function(e){
            _change(); 
        });
        j_win.on('mouseover',function(e){
            var j_e;
            
            j_e = $(e.target);
            if(!j_e.is(j_menutag) && j_e.parents('#index_menutag').length == 0 &&
               !j_e.is(j_menu) && j_e.parents('#index_menu').length == 0){

                inactive_menu();
            }
        });
        j_win.on('click',function(e){
            var j_e;
            
            j_e = $(e.target);
            if(!j_e.is(j_paneltag) && j_e.parents('#index_paneltag').length == 0 &&
               !j_e.is(j_panel) && j_e.parents('#index_panel').length == 0){

                inactive_panel();
            }
        });

        j_menutag.find('div.menu').on('mouseover',function(e){
            active_menu();
        });
        j_paneltag.find('div.notice').on('click',function(e){
            if(j_panel.hasClass('active')){
                inactive_panel();
            }else{
                active_panel();
            }   
        });
        j_panel.find('div.notice').on('click',function(e){
            if(j_panel.hasClass('active')){
                inactive_panel();
            }
        });

        user.datachg_callback.add(function(type){
            var j_a;
            var j_li;

            j_a = j_header.find('li.nickname > a');
            j_a.text(user.nickname);
            j_a.attr('href','/toj/user:' + user.uid + '/main/');
            console.log(type);

            if(type == 'login'){
                j_header.find('li.login').hide();
                j_header.find('li.register').hide();
                j_header.find('li.nickname').show();
                j_header.find('li.logout').show();
                
                j_li = j_menu.find('div.menu li.profile');
                j_li.find('a').attr('href','/toj/user:' + user.uid + '/main/'); 
                j_li.show();
                j_menu.find('div.menu li.mail').show();
                j_menu.find('div.menu li.manage').show();
            }   
        });

        _change(); 
    };
    that.set_title = function(title){
        j_header.find('p.title').text(title); 
    };
    that.set_menu = function(tag){
        j_menutag.find('div.menu').text(tag); 
    };
    that.add_tabnav = function(text,link){
        var j_li = $('<li><a></a></li>');
        var j_a = j_li.find('a');
        
        j_a.text(text);
        j_a.attr('href',link);

        j_header.find('ul.tabnav').append(j_li);        

        j_li.active = function(){
            j_header.find('ul.tabnav > li.active').removeClass('active');
            j_li.addClass('active');
        };

        return j_li;
    };
    that.clear_tabnav = function(){
        j_header.find('ul.tabnav').empty();        
    };
    that.add_alert = function(type,title,content,autofade){
        var j_alert;

        j_alert = $('<div class="alert fade in"><button type="button" class="close" data-dismiss="alert">&times;</button><strong></strong>&nbsp<span></span></div>');

        j_alert.addClass(type);
        j_alert.find('strong').text(title);
        j_alert.find('span').text(content);

        if(autofade != false){
            setTimeout(function(){
                j_alert.alert('close');
            },5000);
        }

        j_alertbox.prepend(j_alert);
    };
};