diff options
author | pzread <netfirewall@gmail.com> | 2013-06-16 03:00:34 +0800 |
---|---|---|
committer | pzread <netfirewall@gmail.com> | 2013-06-16 03:00:34 +0800 |
commit | ef9cd376c41e0992a3cbf7e4a2529d6338d68d7c (patch) | |
tree | 26b6ed96d90646f61afbb36556bbcdb74be4d810 | |
parent | e8ab9406d9c1e4c0091eea35bf78638e92ed014b (diff) | |
download | taiwan-online-judge-ef9cd376c41e0992a3cbf7e4a2529d6338d68d7c.tar.gz taiwan-online-judge-ef9cd376c41e0992a3cbf7e4a2529d6338d68d7c.tar.zst taiwan-online-judge-ef9cd376c41e0992a3cbf7e4a2529d6338d68d7c.zip |
Add web part. Add filter to imc.js
-rw-r--r-- | src/css/color.less | 16 | ||||
-rw-r--r-- | src/css/index.less | 120 | ||||
-rw-r--r-- | src/css/login.less | 12 | ||||
-rw-r--r-- | src/css/mixin.less | 18 | ||||
-rw-r--r-- | src/css/register.less | 12 | ||||
-rw-r--r-- | src/css/style.less | 1 | ||||
-rw-r--r-- | src/html/index.html | 110 | ||||
-rw-r--r-- | src/html/login.html | 22 | ||||
-rw-r--r-- | src/html/register.html | 17 | ||||
-rw-r--r-- | src/js/com.js | 482 | ||||
-rw-r--r-- | src/js/imc.js | 227 | ||||
-rw-r--r-- | src/js/index.js | 87 | ||||
-rw-r--r-- | src/js/user.js | 47 | ||||
-rwxr-xr-x | src/py/backend_server.py | 7 | ||||
-rwxr-xr-x | src/py/center_server.py | 5 | ||||
-rwxr-xr-x | src/py/imc/proxy.py | 66 | ||||
-rw-r--r-- | src/test/wstest.css | 81 | ||||
-rw-r--r-- | src/test/wstest.html | 97 | ||||
-rw-r--r-- | src/test/wstest.js | 178 |
19 files changed, 1131 insertions, 474 deletions
diff --git a/src/css/color.less b/src/css/color.less new file mode 100644 index 0000000..a5a2827 --- /dev/null +++ b/src/css/color.less @@ -0,0 +1,16 @@ +@white:#FFFFFF; +@gray:#BDC0BA; +@darkgray:#373C38; +@black:#000000; +@green:#1B813E; +@orange:#F75C2F; + +@NormalFontSize:16px; + +@SmallPad:6px; +@MediumPad:16px; +@LargePad:64px; +@ExtraPad:128px; + +@fast:200ms; +@slow:600ms; diff --git a/src/css/index.less b/src/css/index.less new file mode 100644 index 0000000..dfbfaf8 --- /dev/null +++ b/src/css/index.less @@ -0,0 +1,120 @@ +@import 'color.less'; +@import 'mixin.less'; + +body{ + overflow-y:scroll; +} + +#index_header{ + z-index:1; + position:relative; +} +.index_tag{ + height:32px; + line-height:32px; + opacity:0.2; + transition:opacity @fast; + + &.active,&:hover{ + height:41px; + line-height:41px; + opacity:1; + } + + div{ + height:100%; + font-size:@NormalFontSize; + color:@white; + font-weight:bold; + float:left; + cursor:pointer; + } +} +#index_menutag{ + .index_tag; + .pos_left(fixed,0px,0px,2); + + div.menu{ + width:80px; + padding-left:16px; + background-color:@darkgray; + text-align:left; + } +} +#index_paneltag{ + .index_tag; + .pos_right(fixed,0px,206px,2); + + div.notice{ + width:70px; + text-align:center; + } + div.notice_hl{ + background-color:@orange; + } +} + +#index_menu{ + width:0px; + background-color:@white; + .pos_left(fixed,0px,0px,1); + box-shadow:0px 0px 6px fade(@black,30%); + opacity:0; + transition:width 0ms linear @fast,opacity @fast; + + &.active{ + width:230px; + opacity:1; + transition:width @fast,opacity @fast; + } + + div.tagblock{ + width:100%; + height:41px; + box-shadow:0px 3px 2px -2px fade(@black,10%); + } + div.menu{ + li > a{ + height:48px; + padding-left:16px; + font-size:@NormalFontSize; + font-weight:bold; + line-height:48px; + } + } +} +#index_panel{ + width:0px; + background-color:@white; + .pos_right(fixed,0px,@SmallPad,1); + box-shadow:0px 0px 6px fade(@black,30%); + opacity:0; + transition:opacity @fast; + + &.active{ + width:270px; + opacity:1; + } + + div.tagblock{ + width:100%; + height:41px; + box-shadow:0px 3px 2px -2px fade(@black,10%); + } + div.notice{ + overflow-y:auto; + + li > a{ + height:64px; + padding-left:@SmallPad; + font-size:@NormalFontSize; + } + } +} +#index_page{ + padding-top:@MediumPad; + + div.page{ + + } +} diff --git a/src/css/login.less b/src/css/login.less new file mode 100644 index 0000000..a589939 --- /dev/null +++ b/src/css/login.less @@ -0,0 +1,12 @@ +@import 'color.less'; +@import 'mixin.less'; + +#index_page{ + div.info{ + margin-top:@ExtraPad; + text-align:right; + } + div.input{ + margin-top:@ExtraPad; + } +} diff --git a/src/css/mixin.less b/src/css/mixin.less new file mode 100644 index 0000000..371e368 --- /dev/null +++ b/src/css/mixin.less @@ -0,0 +1,18 @@ +.show{ + display:block; +} +.hide{ + display:none; +} +.pos_left(@position; @top; @left; @z-index:auto){ + position:@position; + top:@top; + left:@left; + z-index:@z-index; +} +.pos_right(@position; @top; @right; @z-index:auto){ + position:@position; + top:@top; + right:@right; + z-index:@z-index; +} diff --git a/src/css/register.less b/src/css/register.less new file mode 100644 index 0000000..a589939 --- /dev/null +++ b/src/css/register.less @@ -0,0 +1,12 @@ +@import 'color.less'; +@import 'mixin.less'; + +#index_page{ + div.info{ + margin-top:@ExtraPad; + text-align:right; + } + div.input{ + margin-top:@ExtraPad; + } +} diff --git a/src/css/style.less b/src/css/style.less new file mode 100644 index 0000000..7c0b4f8 --- /dev/null +++ b/src/css/style.less @@ -0,0 +1 @@ +@import "index.less"; diff --git a/src/html/index.html b/src/html/index.html new file mode 100644 index 0000000..7bcf19d --- /dev/null +++ b/src/html/index.html @@ -0,0 +1,110 @@ +<!DOCTYPE HTML> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> + +<link href="/bootstrap-toj/css/bootstrap.min.css" rel="stylesheet"> +<link href="/toj/css/style.css" rel="stylesheet" type="text/css"> + +<script src="/jquery-2.0.2.min.js"></script> +<script src="/bootstrap-toj/js/bootstrap.min.js"></script> +<script src="/toj/js/imc.js" type="text/javascript"></script> +<script src="/toj/js/com.js" type="text/javascript"></script> +<script src="/toj/js/index.js" type="text/javascript"></script> +<script src="/toj/js/user.js" type="text/javascript"></script> + +<script type="text/javascript"> + +$(document).ready(function(){ + var j_win = $(window); + + com.ready(); + index.ready(); + user.ready(); + + com.conn_backend(); + + j_win.on('resize',com.exheight); + j_win.on('popstat',function(e){ + if(location.href != com.url_curr){ + com.url_prev = com.url_curr; + com.url_curr = location.href; + com.url_chg(); + } + }); + + com.exheight(); + com.url_chg(); +}); +</script> +</head> +<body> + +<div id="index_header" class="navbar navbar-fixed-top navbar-inverse"> + <div class="navbar-inner"> + <div class="container"> + <p class="offset1 span2 navbar-text">TOJ Server Status</p> + <ul class="nav"> + <li class="active"><a href="#">Home</a></li> + <li><a href="#">Profile</a></li> + </ul> + </div> + <div style="position:absolute; top:0px; right:0px;"> + <ul class="nav"> + <li><a href="#">Cuvelia</a></li> + <li><a href="#">Logout</a></li> + </ul> + </div> + </div> +</div> + +<div id="index_menutag" class="active"> + <div class="menu">Status</div> +</div> +<div id="index_menu" exheight=true> + <div class="tagblock"></div> + <div class="menu"> + <ul class="nav nav-list"> + <li><a href="#">Home</a></li> + <li class="active"><a href="#">Status</a></li> + <li><a href="#">Mail</a></li> + </ul> + </div> +</div> + +<div id="index_paneltag" class="active"> + <div class="notice notice_hl">[5]</div> +</div> +<div id="index_panel" exheight=true> + <div class="tagblock"></div> + <div class="notice" exheight=true extop=41px> + <ul class="nav nav-list"> + <li><a href="#"> + <h5>Mail From Alice</h5> + Hey, don't challenge me! + </a></li> + <li><a href="#"> + <h5>Challenge Success</h5> + You get +50 points + </a></li> + <li><a href="#"> + <h5>Submit 573</h5> + Result:WA Score:37 + </a></li> + <li><a href="#"> + <h5>Submit 570</h5> + Result:WA Score:23 + </a></li> + <li><a href="#"> + <h5>Submit 565</h5> + Result:AC Score:100 + </a></li> + </ul> + </div> +</div> + +<div id="index_page" class="container"></div> + +</body> +</html> diff --git a/src/html/login.html b/src/html/login.html new file mode 100644 index 0000000..d05e5c5 --- /dev/null +++ b/src/html/login.html @@ -0,0 +1,22 @@ +<link href="/toj/css/login.css" rel="stylesheet"> + +<div class="row"> + <div class="modal hide fade"> + <div class="modal-header"> + <button class="btn">Files</button> + </div> + <div class="modal-body"> + </div> + </div> + + <div class="info span7"> + <h2>登入TOJ,開始你的解題</h2> + <p class="lead">沒有帳戶?   <a href="/toj/register/">註冊</a></p> + </div> + <div class="input span6"> + <h2>登入</h2> + <input type="text" placeholder="使用者名稱"><br> + <input type="text" placeholder="密碼"><br> + <button class="btn btn-primary login">登入</button> + </div> +</div> diff --git a/src/html/register.html b/src/html/register.html new file mode 100644 index 0000000..312d0d7 --- /dev/null +++ b/src/html/register.html @@ -0,0 +1,17 @@ +<link href="/toj/css/register.css" rel="stylesheet"> + +<div class="row"> + <div class="info span6"> + <h2>註冊TOJ,開始你的解題</h2> + <p class="lead">有帳戶?   <a href="/toj/login/">登入</a></p> + </div> + <div class="input offset1 span6"> + <h2>註冊</h2> + <input type="text" placeholder="使用者名稱"><br> + <input type="password" placeholder="密碼"><br> + <input type="password" placeholder="重復密碼"><br> + <input type="text" placeholder="昵稱"><br> + <input type="text" placeholder="信箱"><br> + <button class="btn btn-primary submit">註冊</button> + </div> +</div> diff --git a/src/js/com.js b/src/js/com.js new file mode 100644 index 0000000..d5f5be1 --- /dev/null +++ b/src/js/com.js @@ -0,0 +1,482 @@ +'use strict' + +var WebSocketConnection = function(link,ws){ + var that = this; + var reader = new FileReader; + + that.__super__(link); + + that.send_msg = function(data){ + ws.send(new Blob([data],{'type':'application/octet-stream'})) + }; + that.start_recv = function(recv_callback){ + ws.onmessage = function(e){ + reader.onload = function(e){ + recv_callback(that,e.target.result); + }; + reader.readAsText(e.data); + } + }; + + ws.onclose = function(e){ + console.log('close'); + that.close(); + }; +};__extend__(WebSocketConnection,imc.Connection); + +var vus = new function(){ + var that = this; + + that.node = function(name){ + var that = this; + that.name = name; + that.parent = null; + that.ref_count = 1; + that.child = new Object; + that.delay_child = new Object; + + that.url_chg = function(direct,url_upart,url_dpart){ + return 'cont'; + }; + that.get = function(){ + that.ref_count++; + }; + that.child_set = function(node){ + var delay_obj; + + node.parent = that; + that.child[node.name] = node; + + if(node.name in that.delay_child){ + delay_obj = that.delay_child[node.name]; + delete that.delay_child[node.name]; + delay_obj.defer.resolve(); + } + }; + that.child_delayset = function(name){ + that.delay_child[name] = { + 'defer':$.Deferred() + }; + }; + that.child_del = function(node){ + node.parent = null; + delete that.child[node.name]; + + }; + that.lookup = function(url,close_flag){ + var i; + var url_part; + var node_curr; + var node_prev; + + url_part = url.match(/\/toj\/(.*)/)[1].split('/'); + url_part.pop(); + node_prev = null; + node_curr = that; + for(i = 0;i < url_part.length;i++){ + node_prev = node_curr; + if((node_curr = node_curr.child[url_part[i]]) == undefined){ + if(close_flag == true){ + return node_prev; + }else{ + return null; + } + } + } + return node_curr; + } + }; +}; + +var com = new function(){ + var that = this; + var urlchg_reen = false; + var urlchg_hasnext = false; + var check_mbox_url = function(url){ + if(url.search(/toj\/m\/.*/) != -1){ +return true; + }else{ + return false; + } + } + + that.url_curr = null; + that.url_prev = null; + that.url_back = null; + that.url_pbox = null; + + that.link = null; + that.idendesc = null; + that.backend_link = null; + + that.ready = function(){ + var i; + var url; + var urlpart; + + that.vus_root = new vus.node(null); + that.vus_mbox = new vus.node('m'); + + that.vus_mbox.url_chg = function(direct,url_upart,url_dpart){ + if(direct == 'in'){ + index.mask_show(); + }else if(direct == 'out'){ + index.mask_hide(); + } + + return 'cont'; + }; + that.vus_root.child_set(that.vus_mbox); + + urlpart = location.href.split('?'); + if(urlpart[0].search(/\/$/) == -1){ + url = urlpart[0] + '/'; + if(urlpart.length > 1){ + url = url + '?'; + for(i = 1;i < urlpart.length;i++){ + url = url + urlpart[i]; + } + } + window.history.replaceState(null,document.title,url); + } + + $(document).on('click','a',function(e){ + that.url_push($(this).attr('href')); + return false; + }); + }; + + that.url_push = function(url){ + if(url == location.href){ + return; + } + + that.url_prev = location.href; + that.url_back = that.url_prev; + window.history.pushState(null,document.title,url); + that.url_chg(); + }; + that.url_push_back = function(block_regexp){ + if(that.url_back == null || that.url_back.search(block_regexp) != -1){ + that.url_push('/toj/home/'); + }else{ + that.url_push(that.url_back); + } + }; + that.url_update = function(url){ + if(url == location.href){ + return; + } + + that.url_prev = location.href; + window.history.replaceState(null,document.title,url); + that.url_chg(); + }; + that.url_pull_pbox = function(){ + that.url_update(that.url_pbox); + //window.history.back(); + // + }; + that.url_chg = function(){ + var i; + var ret; + var part; + var stop_flag; + + var url_old; + var url_new; + var url_cpart; + var param_cpart; + var url_ppart; + var param_ppart; + var is_mbox_old; + var is_mbox_new; + + var part; + var node_name; + var node_param; + var url_upart; + var url_dpart; + var node_curr; + var node_parent; + var node_bottom; + + var _chg_out = function(url_ppart,param_ppart,url_cpart){ + var i; + var len; + + var node_name; + var url_upart; + var url_dpart; + var node_curr; + var node_parent; + var node_bottom; + + len = Math.min(url_ppart.length,url_cpart.length); + node_bottom = that.vus_root; + node_curr = node_bottom; + for(i = 0;i < len;i++){ + if(url_ppart[i] != url_cpart[i]){ + break; + } + + node_name = url_ppart[i]; + if((node_curr = node_curr.child[node_name]) == undefined){ + break; + } + node_bottom = node_curr; + } + if(node_curr != undefined){ + for(;i < url_ppart.length;i++){ + node_name = url_ppart[i]; + if(node_curr.child[node_name] == undefined){ + break; + } + node_curr = node_curr.child[node_name]; + } + + i--; + url_upart = url_ppart.slice(0); + url_dpart = new Array; + while(node_curr && node_curr != node_bottom){ + node_parent = node_curr.parent; + node_curr.url_chg('out',url_upart,url_dpart,param_ppart[i]); + + url_dpart = url_dpart.splice(0,0,url_upart.pop()); + node_curr = node_parent; + i--; + } + } + + return node_bottom; + }; + var _chg_in = function(url_cpart,param_cpart,idx,node_curr,url_upart,url_dpart){ + var node_name; + var node_param; + var node_parent; + var delay_obj; + + for(;idx < url_cpart.length;idx++){ + node_parent = node_curr; + + node_name = url_cpart[idx]; + node_param = param_cpart[idx]; + + if((node_curr = node_parent.child[node_name]) == undefined){ + if((delay_obj = node_parent.delay_child[node_name]) == undefined){ + that.url_update('/toj/none/'); + }else{ + delay_obj.url_curr = url_new; + delay_obj.defer.done(function(){ + if(url_new == delay_obj.url_curr){ + _chg_in(url_cpart,param_cpart,idx,node_parent,url_upart,url_dpart); + } + }); + } + break; + } + url_upart.push(url_dpart.shift()); + + ret = node_curr.url_chg('in',url_upart,url_dpart,node_param); + if(ret == 'stop'){ + break; + } + } + }; + + that.url_curr = location.href; + console.log(that.url_curr); + + if(urlchg_reen == true){ + urlchg_hasnext = true; + return; + }else{ + urlchg_reen = true; + urlchg_hasnext = true; + } + + while(urlchg_hasnext){ + urlchg_hasnext = false; + + url_old = that.url_prev; + url_new = that.url_curr; + + url_cpart = url_new.match(/toj\/(.*)/)[1].split('/'); + url_cpart.pop(); + if(url_cpart.length == 0){ + that.url_update('/toj/home/'); + continue; + } + + param_cpart = new Array; + for(i = 0;i < url_cpart.length;i++){ + part = url_cpart[i].split(':'); + url_cpart[i] = part[0]; + if(part.length > 1){ + part.splice(0,1); + param_cpart.push(part); + }else{ + param_cpart.push(null); + } + } + + if(url_old == null){ + is_mbox_old = false; + }else{ + is_mbox_old = check_mbox_url(url_old); + } + is_mbox_new = check_mbox_url(url_new); + + if(url_old == null || (is_mbox_old == false && is_mbox_new == true)){ + node_bottom = that.vus_root; + }else if(that.url_pbox != null && is_mbox_old == true && is_mbox_new == false){ + url_ppart = that.url_pbox.match(/toj\/(.*)/)[1].split('/'); + url_ppart.pop(); + + param_ppart = new Array; + for(i = 0;i < url_ppart.length;i++){ + part = url_ppart[i].split(':'); + url_ppart[i] = part[0]; + if(part.length > 1){ + part.splice(0,1); + param_ppart.push(part); + }else{ + param_ppart.push(null); + } + } + + node_bottom = _chg_out(url_ppart,param_ppart,url_cpart); + }else{ + url_ppart = url_old.match(/toj\/(.*)/)[1].split('/'); + url_ppart.pop(); + + param_ppart = new Array; + for(i = 0;i < url_ppart.length;i++){ + part = url_ppart[i].split(':'); + url_ppart[i] = part[0]; + if(part.length > 1){ + part.splice(0,1); + param_ppart.push(part); + }else{ + param_ppart.push(null); + } + } + + node_bottom = _chg_out(url_ppart,param_ppart,url_cpart); + } + + if(url_new != that.url_pbox){ + i = 0; + node_curr = that.vus_root; + url_upart = new Array; + url_dpart = url_cpart.slice(0); + stop_flag = false; + while(node_curr != node_bottom){ + node_name = url_cpart[i]; + node_param = param_cpart[i]; + + if((node_curr = node_curr.child[node_name]) == undefined){ + break; + } + url_upart.push(url_dpart.shift()); + ret = node_curr.url_chg('same',url_upart,url_dpart,node_param); + if(ret == 'stop'){ + stop_flag = true; + break; + } + i++; + } + if(stop_flag == false){ + _chg_in(url_cpart,param_cpart,i,node_curr,url_upart,url_dpart); + } + } + + if(that.url_pbox != null && is_mbox_old == true && is_mbox_new == false){ + url_ppart = url_old.match(/toj\/(.*)/)[1].split('/'); + url_ppart.pop(); + _chg_out(url_ppart,param_ppart,url_cpart); + } + + if(is_mbox_new == false){ + if(that.url_pbox == null){ + $('#index_mask').removeClass('index_mask_nopbox'); + $('#index_mask').addClass('index_mask'); + } + that.url_pbox = url_new; + } + } + + urlchg_reen = false; + }; + + that.loadpage = function(htmlurl,callback){ + var j_index_page = $('#index_page'); + var defer = $.Deferred(); + + j_index_page.empty(); + j_index_page.load(htmlurl,function(data,stat,xhr){ + defer.resolve(); + }); + + return defer.promise(); + }; + that.exheight = function(){ + var i; + var es = $('[exheight="true"]'); + var j_e; + var winheight = $(window).innerHeight(); + var extop; + + for(i = 0;i < es.length;i++){ + j_e = $(es[i]); + + if((extop = j_e.attr('extop')) == undefined){ + extop = j_e.css('top'); + } + extop = extop.match('(.*)px')[1]; + j_e.height(winheight - extop); + } + } + + that.conn_backend = function(){ + $.post('http://toj.tfcis.org:83/conn',{},function(res){ + var reto; + var iden; + var ws; + + if(res[0] != 'E'){ + reto = JSON.parse(res) + + that.link = reto.client_link; + that.idendesc = reto.client_idendesc; + that.backend_link = reto.backend_link; + + ws = new WebSocket('ws://' + reto.ip + ':' + reto.port + '/conn'); + ws.onopen = function(){ + var i; + var conn; + + console.log('open'); + + ws.send(JSON.stringify({ + 'client_link':that.link + })); + + conn = new WebSocketConnection(reto.backend_link,ws); + + new imc.Auth(); + new imc.Proxy(that.link,imc.Auth.instance,function(link,callback){ + callback(conn); + }); + imc.Proxy.instance.add_conn(conn); + + imc.Auth.change_current_iden(that.idendesc) + }; + }else{ + setTimeout(conn_backend,5000); + } + }); + } +}; + + diff --git a/src/js/imc.js b/src/js/imc.js index 8e444a1..8970ccf 100644 --- a/src/js/imc.js +++ b/src/js/imc.js @@ -1,14 +1,18 @@ +'use strict' + var __extend__ = function(child,parent){ child.prototype.__super__ = parent; }; var imc = new function(){ - this.Connection = function(linkid){ + var that = this; + + that.Connection = function(link){ var that = this; - that.link_linkidmap = {}; + that.link_linkmap = {}; that.close_callback = []; - that.linkid = linkid; + that.link = link; that.send_msg = function(data){}; that.start_recv = function(recv_callback){}; @@ -22,68 +26,116 @@ var imc = new function(){ }; }; - this.Proxy = function(linkid,auth,connect_linkid){ + that.Proxy = function(self_link,auth,conn_link){ var MSGTYPE_CALL = 'call'; var MSGTYPE_RET = 'ret'; var that = this; var caller_retid_count = 0; - var conn_linkidmap = {}; + var conn_linkmap = {}; var conn_retidmap = {}; - var call_pathmap = {}; + var callpath_root = {'child':{},'name':{},'filt':[]}; - var route_call = function(caller_retid,timeout,idendesc,dst,func_name,param,callback){ + var walk_path = function(path,create){ var i; + var parts; var part; - var dst_linkid; + var cnode; + var nnode; + + parts = path.split('/'); + parts.pop(); + cnode = callpath_root; + for(i = 0;i < parts.length;i++){ + part = parts[i]; + if(part in cnode.child){ + cnode = cnode.child[part]; + }else{ + break; + } + } + + if(create == true){ + for(;i < parts.length;i++){ + part = parts[i]; + nnode = {'child':{},'name':{},'filt':[]}; + cnode.child[part] = nnode; + cnode = nnode; + } + }else if(i < parts.length){ + return undefined; + } + + return cnode; + }; + + var route_call = function(caller_link,caller_retid,idendesc,dst,func_name,timeout,callback,param){ + var i; + var j; + var part; + var dst_link; var dst_path; - var caller_linkid; + var caller_link; + var cnode; + var dpart; var func; - var _add_wait_caller = function(conn_linkid){ - conn_retidmap[conn_linkid][caller_retid] = { + var _add_wait_caller = function(conn_link){ + conn_retidmap[conn_link][caller_retid] = { 'timeout':timeout, 'callback':callback } }; part = dst.split('/'); - dst_linkid = part[2]; - dst_path = part.slice(3).join('/'); + dst_link = part.slice(0,3).join('/') + '/' + dst_path = part.slice(3,-1); + + if(dst_link == self_link){ + cnode = callpath_root; + dpart = dst_path.slice(0); + for(i = 0;i < cnode.filt.length;i++){ + cnode.filt[i](dpart,func_name); + } - iden = auth.get_iden(idendesc); + for(i = 0;i < dst_path.length;i++){ + if((cnode = cnode.child[dst_path[i]]) == undefined){ + cnode = null; + break; + } - caller_linkid = iden.linkid - if(caller_retid.split('/')[0] != caller_linkid){ - return false; - } + dpart.shift(); + for(j = 0;j < cnode.filt.length;j++){ + cnode.filt[j](dpart,func_name); + } + } - if(dst_linkid == linkid){ - if((func = call_pathmap[dst_path + func_name]) != undefined){ - _add_wait_caller(linkid); + if(cnode != null && (func = cnode.name[func_name]) != undefined){ + _add_wait_caller(self_link); - func(iden,param,function(data){ - if(linkid in conn_retidmap && caller_retid in conn_retidmap[linkid]){ - delete conn_retidmap[linkid][caller_retid]; + func.apply(undefined,[function(data){ + if(self_link in conn_retidmap && caller_retid in conn_retidmap[self_link]){ + delete conn_retidmap[self_link][caller_retid]; callback({'stat':true,'data':data}); } - }); + }].concat(param)); }else{ callback({'stat':false,'data':'Enoexist'}); } }else{ - that.request_conn(dst_linkid,function(conn){ - if(caller_linkid == linkid){ - _add_wait_caller(conn.linkid); + that.request_conn(dst_link,function(conn){ + if(caller_link == self_link){ + _add_wait_caller(conn.link); } - send_msg_call(conn,caller_retid,timeout,idendesc,dst,func_name,param); + send_msg_call(conn,caller_link,caller_retid,idendesc,dst,func_name,timeout,param); }); } }; var recv_dispatch = function(conn,data){ - msgo = JSON.parse(data); + var msgo = JSON.parse(data); + if(msgo.type == MSGTYPE_CALL){ recv_msg_call(conn,msgo); }else if(msgo.type == MSGTYPE_RET){ @@ -91,20 +143,22 @@ var imc = new function(){ } }; - var send_msg_call = function(conn,caller_retid,timeout,idendesc,dst,func_name,param){ - msg = { + var send_msg_call = function(conn,caller_link,caller_retid,idendesc,dst,func_name,timeout,param){ + var msg = { 'type':MSGTYPE_CALL, + 'caller_link':caller_link, 'caller_retid':caller_retid, - 'timeout':timeout, 'idendesc':idendesc, 'dst':dst, 'func_name':func_name, + 'timeout':timeout, 'param':param }; conn.send_msg(JSON.stringify(msg)); }; var recv_msg_call = function(conn,msg){ + var caller_link = msg.caller_link var caller_retid = msg.caller_retid; var timeout = msg.timeout; var idendesc = msg.idendesc; @@ -112,20 +166,17 @@ var imc = new function(){ var func_name = msg.func_name; var param = msg.param; - route_call(caller_retid,timeout,idendesc,dst,func_name,param,function(result){ + route_call(caller_link,caller_retid,idendesc,dst,func_name,timeout,function(result){ that.request_conn(caller_retid,function(conn){ - var iden; - - iden = auth.get_iden(idendesc); - send_msg_ret(conn,iden.linkid,caller_retid,result); + send_msg_ret(conn,caller_link,caller_retid,result); }); - }); + },param); }; - var send_msg_ret = function(conn,caller_linkid,caller_retid,result){ - msg = { + var send_msg_ret = function(conn,caller_link,caller_retid,result){ + var msg = { 'type':MSGTYPE_RET, - 'caller_linkid':caller_linkid, + 'caller_link':caller_link, 'caller_retid':caller_retid, 'result':result }; @@ -133,70 +184,88 @@ var imc = new function(){ conn.send_msg(JSON.stringify(msg)); }; var recv_msg_ret = function(conn,msg){ - var caller_linkid = msg['caller_linkid']; + var caller_link = msg['caller_link']; var caller_retid = msg['caller_retid']; var result = msg['result']; + var wait; - if(caller_linkid == linkid){ - if(conn.linkid in conn_retidmap && caller_retid in conn_retidmap[conn.linkid]){ - wait = conn_retidmap[conn.linkid][caller_retid]; - delete conn_retidmap[conn.linkid][caller_retid]; + if(caller_link == self_link){ + if(conn.link in conn_retidmap && caller_retid in conn_retidmap[conn.link]){ + wait = conn_retidmap[conn.link][caller_retid]; + delete conn_retidmap[conn.link][caller_retid]; wait.callback(result); } }else{ - request_conn(caller_linkid,function(conn){ - send_msg_ret(conn,caller_linkid,caller_retid,result); + request_conn(caller_link,function(conn){ + send_msg_ret(conn,caller_link,caller_retid,result); }); } }; that.add_conn = function(conn){ - conn_linkidmap[conn.linkid] = conn; - conn_retidmap[conn.linkid] = {}; + conn_linkmap[conn.link] = conn; + conn_retidmap[conn.link] = {}; conn.start_recv(recv_dispatch); }; - that.link_conn = function(linkid,conn){ - conn.link_linkidmap[linkid] = true; - conn_linkidmap[linkid] = conn; + that.link_conn = function(link,conn){ + conn.link_linkmap[link] = true; + conn_linkmap[link] = conn; }; - that.unlink_conn = function(linkid){ - conn = conn_linkidmap[linkid]; - delete conn_linkidmap[linkid]; - delete conn.link_linkidmap[linkid]; + that.unlink_conn = function(link){ + conn = conn_linkmap[link]; + delete conn_linkmap[link]; + delete conn.link_linkmap[link]; }; that.del_conn = function(conn){ - delete conn_linkidmap[conn.linkid]; + delete conn_linkmap[conn.link]; }; - that.request_conn = function(linkid,callback){ + that.request_conn = function(link,callback){ + var conn = conn_linkmap[link]; var _conn_cb = function(conn){ - if(conn != null && conn.linkid != linkid){ - that.link_conn(linkid,conn); + if(conn != null && conn.link != link){ + that.link_conn(link,conn); } callback(conn); }; - conn = conn_linkidmap[linkid]; if(conn != undefined){ _conn_cb(conn); }else{ - connect_linkid(linkid,_conn_cb); + conn_link(link,_conn_cb); } }; - that.call = function(idendesc,timeout,dst,func_name,param,callback){ - caller_retid = linkid + '/' + caller_retid_count; + that.call = function(dst,func_name,timeout,callback){ + var i; + var params = new Array() + var caller_retid; + + for(i = 4;i < arguments.length;i++){ + params.push(arguments[i]); + } + + caller_retid = self_link + '/' + caller_retid_count; caller_retid_count += 1; - route_call(caller_retid,timeout,idendesc,dst,func_name,param,callback); + route_call(self_link,caller_retid,imc.Auth.get_current_idendesc(),dst,func_name,timeout,callback,params); }; that.register_call = function(path,func_name,func){ - call_pathmap[path + func_name] = func; + var cnode; + + cnode = walk_path(path,true); + cnode.name[func_name] = func; + }; + that.register_filter = function(path,func){ + var cnode; + + cnode = walk_path(path,true); + cnode.filt.push(func); }; - conn_retidmap[linkid] = {}; + conn_retidmap[self_link] = {}; imc.Proxy.instance = that; }; @@ -207,14 +276,20 @@ var imc = new function(){ that.get_iden = function(idendesc){ return JSON.parse(JSON.parse(idendesc)[0]); }; + + imc.Auth.change_current_iden = function(idendesc){ + var iden = imc.Auth.instance.get_iden(idendesc); + + imc.Auth.current_idendata = [iden,idendesc]; + }; + imc.Auth.get_current_iden = function(){ + return imc.Auth.current_idendata[0]; + }; + imc.Auth.get_current_idendesc = function(){ + return imc.Auth.current_idendata[1]; + }; + imc.Auth.current_idendata = null; imc.Auth.instance = that; }; }; - -function imc_call(idendesc,dst,func_name,param,callback){ - imc.Proxy.instance.call(idendesc,10000,dst,func_name,param,callback); -} -function imc_register_call(path,func_name,func){ - imc.Proxy.instance.register_call(path,func_name,func); -} diff --git a/src/js/index.js b/src/js/index.js new file mode 100644 index 0000000..e255c87 --- /dev/null +++ b/src/js/index.js @@ -0,0 +1,87 @@ +'use strict' + +var index = new function(){ + var that = this; + var active_menutag = function(){ + $('#index_menutag').addClass('active'); + }; + var inactive_menutag = function(){ + if($(window).scrollTop() > 8 && !$('#index_menu').hasClass('active')){ + $('#index_menutag').removeClass('active'); + } + }; + var active_paneltag = function(){ + $('#index_paneltag').addClass('active'); + }; + var inactive_paneltag = function(){ + if($(window).scrollTop() > 8 && !$('#index_panel').hasClass('active')){ + $('#index_paneltag').removeClass('active'); + } + }; + var active_menu = function(){ + $('#index_menu').addClass('active'); + active_menutag(); + }; + var inactive_menu = function(){ + $('#index_menu').removeClass('active'); + inactive_menutag(); + }; + var active_panel = function(){ + $('#index_panel').addClass('active'); + active_paneltag(); + }; + var inactive_panel = function(){ + $('#index_panel').removeClass('active'); + inactive_paneltag(); + }; + + that.ready = function(){ + var j_win = $(window); + var j_menutag = $('#index_menutag'); + var j_menu = $('#index_menu'); + var j_paneltag = $('#index_paneltag'); + var j_panel = $('#index_panel'); + + j_win.on('scroll',function(e){ + if($(window).scrollTop() <= 8){ + active_menutag(); + active_paneltag(); + }else{ + inactive_menutag(); + inactive_paneltag(); + } + }); + 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($('#index_panel').hasClass('active')){ + inactive_panel(); + }else{ + active_panel(); + } + }); + + }; +}; diff --git a/src/js/user.js b/src/js/user.js new file mode 100644 index 0000000..d76d855 --- /dev/null +++ b/src/js/user.js @@ -0,0 +1,47 @@ +var user = new function(){ + var that = this; + var j_index_page; + + that.ready = function(){ + var login_node = new vus.node('login'); + var register_node = new vus.node('register'); + + j_index_page = $('#index_page'); + + login_node.url_chg = function(direct,url_upart,url_dpart,param){ + if(direct == 'in'){ + com.loadpage('/toj/html/login.html').done(function(){ + j_index_page.find('button.submit').on('click',function(e){ + console.log('test'); + }); + }); + } + + return 'cont' + } + com.vus_root.child_set(login_node); + + register_node.url_chg = function(direct,url_upart,url_dpart,param){ + if(direct == 'in'){ + com.loadpage('/toj/html/register.html').done(function(){ + j_index_page.find('button.submit').on('click',function(e){ + console.log('test'); + + imc.Proxy.instance.register_filter('test/',function(dpart,func_name){ + console.log(dpart); + console.log(func_name); + }); + imc.Proxy.instance.register_call('test/route/','80s',function(callback,a,b){ + console.log(b); + callback('ret'); + }); + imc.Proxy.instance.call(com.backend_link + 'test/','get_client_list',1000,function(result){ + console.log(result); + },1,2); + }); + }); + } + } + com.vus_root.child_set(register_node); + }; +}; diff --git a/src/py/backend_server.py b/src/py/backend_server.py index e965bd3..5412dee 100755 --- a/src/py/backend_server.py +++ b/src/py/backend_server.py @@ -115,8 +115,8 @@ class BackendWorker(tornado.tcpserver.TCPServer): #imc_register_call('','test_dsta',self._test_dsta) #$time.sleep(1) - if self._link == '/backend/2/': - self._test_call(None) + #if self._link == '/backend/2/': + # self._test_call(None) sock_ip,sock_port = self.sock_addr netio.send_pack(stream,bytes(json.dumps({ @@ -241,6 +241,9 @@ class BackendWorker(tornado.tcpserver.TCPServer): @imc.async.caller def _test_get_client_list(self,talk,talk2): + stat,ret = Proxy.instance.call(TOJAuth.get_current_iden()['link'] + 'test/route/','80s',1000,'attation','mega') + print(ret) + return list(self._client_linkmap.items()) @imc.async.caller diff --git a/src/py/center_server.py b/src/py/center_server.py index a8037a7..1f67c9d 100755 --- a/src/py/center_server.py +++ b/src/py/center_server.py @@ -126,7 +126,7 @@ class CenterServer(tornado.tcpserver.TCPServer): backend = self._backend_workerlist[random.randrange(size)] ws_ip,ws_port = backend.ws_addr - return (idendesc,backend.link,ws_ip,ws_port) + return (link,idendesc,backend.link,ws_ip,ws_port) def _create_link(self,linkclass): linkid = uuid.uuid1() @@ -215,8 +215,9 @@ class WebConnHandler(tornado.web.RequestHandler): self.write('Eno_backend') else: - client_idendesc,backend_link,ip,port = data + client_link,client_idendesc,backend_link,ip,port = data self.write(json.dumps({ + 'client_link':client_link, 'client_idendesc':client_idendesc, 'backend_link':backend_link, 'ip':ip, diff --git a/src/py/imc/proxy.py b/src/py/imc/proxy.py index e21b171..6b95674 100755 --- a/src/py/imc/proxy.py +++ b/src/py/imc/proxy.py @@ -146,47 +146,11 @@ class Proxy: return None def register_call(self,path,func_name,func): - parts = path.split('/')[:-1] - child,name,filt = self._callpath_root - i = 0 - size = len(parts) - while i < size: - try: - child,name,filt = child[parts[i]] - i += 1 - - except KeyError: - while i < size: - part = parts[i] - node = ({},{},[]) - child[part] = node - child,name,filt = node - i += 1 - - break - + child,name,filt = self._walk_path(path,True) name[func_name] = func def register_filter(self,path,func): - parts = path.split('/')[:-1] - child,name,filt = self._callpath_root - i = 0 - size = len(parts) - while i < size: - try: - child,name,filt = child[parts[i]] - i += 1 - - except KeyError: - while i < size: - part = parts[i] - node = ({},{},[]) - child[part] = node - child,name,filt = node - i += 1 - - break - + child,name,filt = self._walk_path(path,True) filt.append(func) def call(self,dst,func_name,timeout,*args): @@ -265,6 +229,32 @@ class Proxy: with Auth.change_current_iden(self._idendesc,self._auth): self.call(info['src_link'] + 'imc/','reject_sendfile',65536,filekey) + def _walk_path(self,path,create = False): + parts = path.split('/')[:-1] + child,name,filt = self._callpath_root + i = 0 + size = len(parts) + while i < size: + try: + child,name,filt = child[parts[i]] + i += 1 + + except KeyError: + if create == False: + raise + + else: + while i < size: + part = parts[i] + node = ({},{},[]) + child[part] = node + child,name,filt = node + i += 1 + + break + + return (child,name,filt) + def _route_call(self,in_conn,caller_link,caller_retid,idendesc,dst,func_name,timeout,param): def __add_wait_caller(conn_link): callback = tornado.stack_context.wrap(lambda result : self._ret_call(caller_link,caller_retid,result)) diff --git a/src/test/wstest.css b/src/test/wstest.css deleted file mode 100644 index 39b9fad..0000000 --- a/src/test/wstest.css +++ /dev/null @@ -1,81 +0,0 @@ -body{ - overflow-y:scroll; -} - -div.head ul.right_navbar{ - margin-right:0px; - position:absolute; - top:0px; - left:auto; - right:0px; -} -div.head ul.right_navbar div.notice{ - height:100%; - padding:5px 0px 5px 0px; -} -div.head ul.right_navbar div.notice > div.box{ - width:30px; - padding:5px 0px 5px 0px; - background-color:#656765; - font-size:16px; - font-weight:bold; - text-align:center; - cursor:pointer; -} -div.head ul.right_navbar div:hover.notice > div.box{ - color:white; -} -div.head ul.right_navbar div.notice_h > div.box{ - background:#86C166; - color:white; -} -div.head ul.right_navbar div.menu{ - width:80px; - padding:10px 0px 10px 0px; - text-align:center; - cursor:pointer; -} - -div.panel_container{ - width:0px; - position:absolute; - top:40px; - right:0px; - border-left:#DDD 1px solid; - overflow:hidden; - - transition:width 200ms; -} -div.panel_container_a{ - width:240px; -} -div.panel_container > div.menu_container{ - width:240px; - display:none; -} -div.panel_container > div.menu_container > ul.menu > li > a{ - height:60px; - font-weight:bold; - line-height:60px; -} - -div.panel_container > div.notice_container{ - width:240px; - display:none; -} -div.panel_container > div.notice_container > ul.notice > li > a > div{ - height:60px; - color:black; -} - -div.modal{ - width:978px; - margin-left:-489px; -} - -div.panel_box{ - width:322px; - position:absolute; - top:0px; - right:0px; -} diff --git a/src/test/wstest.html b/src/test/wstest.html deleted file mode 100644 index a17a0dc..0000000 --- a/src/test/wstest.html +++ /dev/null @@ -1,97 +0,0 @@ -<!DOCTYPE HTML> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1.0"> - -<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"> -<link href="/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet"> - -<link href="/wstest.css" rel="stylesheet"> - -<script src="/jquery-2.0.0.min.js"></script> -<script src="/bootstrap/js/bootstrap.min.js"></script> -<script type="text/javascript" src="/imc.js"></script> -<script type="text/javascript" src="/wstest.js"></script> - -<script type="text/javascript"> - -$(document).ready(function(){ - conn_backend(); - - index.init(); -}); - -</script> -</head> -<body> - -<div id="index_head" class="navbar navbar-inverse navbar-fixed-top head"> - <div class="navbar-inner"> - <div class="container"> - <a class="brand span2" href="#">Taiwan OJ</a> - <ul class="nav bar"> - <li class="active"><a href="#">Profile</a></li> - <li><a href="#">Edit Profile</a></li> - </ul> - <p class="navbar-text span3 title">Taiwan Online Judge Test Page</p> - </div> - - <ul id="index_head_rightnavbar" class="nav bar right_navbar"> - <li><a id="index_head_nickname" href="#">Elisha</a></li> - <li><div id="index_head_notice" class="notice notice_h"><div class="box">2</div></div></li> - <li><div id="index_head_menu" class="menu"><i class="icon-chevron-left icon-white"></i></div></li> - </ul> - </div> -</div> - -<div id="index_panel" class="panel_container"> - <div class="menu_container"> - <ul id="index_panel_menu" class="nav nav-list menu"> - <li><a href="#"><i class="icon-home"></i> Home</a></li> - <li class="active"><a href="#"><i class="icon-exclamation-sign"></i> Test</a></li> - <li><a href="#"><i class="icon-th-large"></i> Square</a></li> - <ul class="nav nav-list sq_list"> - <li class="nav-header">Coming</li> - <li><a href="#">Test1</a></li> - <li><a href="#">Test2</a></li> - <li class="nav-header">Running</li> - <li><a href="#">Normal Test</a></li> - <li class="nav-header">Ended</li> - <li><a href="#">End Test</a></li> - </ul> - - <li style="margin-top:30px;"><a href="#"><i class="icon-circle-arrow-left"></i> Logout</a></li> - </ul> - </div> - - <div class="notice_container"> - <ul id="index_panel_menu" class="nav nav-list notice"> - <li><a href="#"><div><h5>Problem:573</h5>Wrong Answer</div></a></li> - <li><a href="#"><div><h5>Problem:573</h5>Runtime Error</div></a></li> - </ul> - </div> -</div> - -<div class="container" style="padding:60px 0px 32px 0px;"> - <div class="row"> - <div class="span2 slide"> - - </div> - <div class="span10 main"> - <button class="btn btn-primary" onclick="$('div.test_modal').modal('show');">Test Dialog</button> - <div class="modal hide fade test_modal" tabindex="-1" role="dialog" aria-hidden="true"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> - <h3>Test Dialog</h3> - </div> - <div class="modal-body"> - Hello, my name is Elisha. - </div> - </div> - </div> - </div> -</div> - -</body> -</html> diff --git a/src/test/wstest.js b/src/test/wstest.js deleted file mode 100644 index 54cead6..0000000 --- a/src/test/wstest.js +++ /dev/null @@ -1,178 +0,0 @@ -'use strict' - -var count = 0; -var last = 0; -var data = new ArrayBuffer(1024); - -var linkid = null; -var idendesc = null; - -function test_display(iden,param,callback){ - imc_call(idendesc,'/center/1/','test_dst','',function(result){ - console.log(result); - }); -} - -var WebSocketConnection = function(linkid,ws){ - var that = this; - var reader = new FileReader; - - that.__super__(linkid); - - that.send_msg = function(data){ - ws.send(new Blob([data],{'type':'application/octet-stream'})) - }; - that.start_recv = function(recv_callback){ - ws.onmessage = function(e){ - reader.onload = function(e){ - recv_callback(that,e.target.result); - }; - reader.readAsText(e.data); - } - }; - - ws.onclose = function(e){ - console.log('close'); - that.close(); - - setTimeout(conn_backend,5000); - }; -};__extend__(WebSocketConnection,imc.Connection); - -function conn_backend(ip,port){ - $.post('http://toj.tfcis.org:83/conn',{},function(res){ - var reto; - var iden; - var linkid; - var ws; - - if(res[0] != 'E'){ - reto = JSON.parse(res) - idendesc = reto.client_idendesc; - iden = JSON.parse(JSON.parse(idendesc)[0]); - linkid = iden.linkid; - - ws = new WebSocket('ws://' + reto.ip + ':' + reto.port + '/conn'); - ws.onopen = function(){ - var i; - var conn; - - console.log('open'); - - console.log(linkid); - ws.send(JSON.stringify({ - 'client_linkid':linkid - })); - - conn = new WebSocketConnection(reto.backend_linkid,ws); - - new imc.Auth(); - new imc.Proxy(linkid,imc.Auth.instance,function(linkid,callback){ - callback(conn); - }); - imc.Proxy.instance.add_conn(conn); - - imc_register_call('','test_display',test_display); - - - test_display(idendesc,'',function(result){ - console.log(result); - }); - }; - }else{ - setTimeout(conn_backend,5000); - } - }); -} - -function perf(){ - $('#speed').text((count - last) + '/s'); - last = count; - setTimeout(perf,1000); -} - -var index = new function(){ - this.init = function(){ - var j_navbar = $('#index_head ul.right_navbar'); - var j_navbar_menu = $('#index_head_menu'); - var j_navbar_notice = $('#index_head_notice'); - var j_panel = $('#index_panel'); - var j_panel_menu = $('#index_panel_menu'); - var j_panel_notice = $('#index_panel_notice'); - - var _in_area = function(target,id){ - return target.id == id || $(target).parents('#' + id).length > 0; - }; - var _show_panel = function(){ - var j_i; - - if(!j_panel.hasClass('panel_container_a')){ - j_i = j_navbar_menu.find('i'); - j_i.removeClass('icon-chevron-left'); - j_i.addClass('icon-chevron-down'); - - j_panel.addClass('panel_container_a'); - } - }; - var _hide_panel = function(){ - var j_i; - - if(j_panel.hasClass('panel_container_a')){ - j_i = j_navbar_menu.find('i'); - j_i.removeClass('icon-chevron-down'); - j_i.addClass('icon-chevron-left'); - - j_panel.removeClass('panel_container_a'); - } - }; - var _show_menu = function(){ - _hide_notice(); - j_panel.find('div.menu_container').show(); - _show_panel(); - }; - var _hide_menu = function(){ - j_panel.find('div.menu_container').hide(); - }; - var _show_notice = function(){ - _hide_menu(); - j_panel.find('div.notice_container').show(); - _show_panel(); - }; - var _hide_notice = function(){ - j_panel.find('div.notice_container').hide(); - }; - - $(window).on('resize',function(e){ - j_panel.css('min-height',($(window).height() - 40 + 'px')); - }); - j_panel.css('min-height',($(window).height() - 40 + 'px')); - - $(window).on('mouseover',function(e){ - var target = e.target; - - console.log(e.target); - if(target == null || - _in_area(target,'index_panel') || - (target.parentNode.id == 'index_head' && $(target).hasClass('navbar-inner'))){ - return; - } - - if(_in_area(target,'index_head_menu')){ - if(!j_panel.hasClass('panel_container_a')){ - _show_menu(); - } - }else{ - if(!_in_area(target,'index_head_rightnavbar')){ - _hide_panel(); - } - } - }); - - j_navbar_menu.on('click',function(e){ - _show_menu(); - }); - j_navbar_notice.on('click',function(e){ - _show_notice(); - }); - }; -}; |