From 2bccd9060ec7b7334fe37120aa3f8b8e3d3e1f76 Mon Sep 17 00:00:00 2001 From: wrmswindmill Date: Mon, 1 Oct 2018 15:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0open=5Ftab=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A1=86=E6=9E=B6=EF=BC=8C=E6=9B=B4=E5=AE=B9=E6=98=93?= =?UTF-8?q?=E6=98=8E=E7=99=BD=E5=92=8C=E8=AF=BB=E6=87=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dump.rdb | Bin 578 -> 588 bytes static/js/source.js | 299 ++++++++++++++++++++++---------------------- 2 files changed, 150 insertions(+), 149 deletions(-) diff --git a/dump.rdb b/dump.rdb index 87c082a38e13b54c1addaffb98d32c0735d90b28..349c3c0d4fbf9b19721ae69d535130de769e2f09 100644 GIT binary patch delta 176 zcmX@aa)xDsq0QpM8>4@5loqF^=;o&89tya`&+v;UF+WYWpeQvlHz_Ce0K-3q-;4}A z%<0L=haDd{&10Fz#K169ftl;p#@tv&J2q!VmQPFvIulsg^cYz_GacBKz{<$NDc4=>UHMD}yKyO9Qbi5X%FxVgf6VFB8jmrUR3CndDXdm{|VtGau+yU=t8!KJc57 a<)0Dr0dppn1N#{M|M!`@K=GV*&;|ffS2vyj delta 166 zcmX@Za)@Puq0OfG8>4@5loqF^=;o&89{TZum*E#rVt$%#K~ZXAZc5Y`#n^-LGnOOeuG9TzxU}F^h O|6eC>;biV}CMyAw7c*P{ diff --git a/static/js/source.js b/static/js/source.js index c80bf36..52f1564 100644 --- a/static/js/source.js +++ b/static/js/source.js @@ -973,43 +973,68 @@ function url_deal(path,archor){ } } + +function deal_for_tab(project_id,normal_path,path_after){ + // 关闭其他标签页 + var tabcontent = document.getElementsByClassName("codereading"); + for (var i = 0; i < tabcontent.length; i++) { + tabcontent[i].style.display = "none"; + } + var tab_items = document.getElementsByClassName("tab_item"); + for (var i = 0; i < tab_items.length; i++) { + // debugger; + tab_items[i].className = tab_items[i].className.replace(" active", ""); + } + // 将当前标签页置为活跃 + document.getElementById("code_" + path_after).style.display = "block"; + document.getElementById("tab_" + path_after).style.display = "block"; + document.getElementById("tab_" + path_after).className += " active"; + // 如果当前的内容未加载,则加载当前的内容 + get_codereading_content(project_id,normal_path,path_after) +} + +function deal_for_right(project_id,normal_path,path_after){ + if(path_after in right_map){ + $("#right_panel").html(right_map[path_after]); + }else{ + $.ajax({ + cache: false, + type: "POST", + url: '/operations/right/', + data: { 'project_id': project_id, 'path': normal_path}, + dataType: 'json', + async: true, + beforeSend: function (xhr, settings) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + }, + success: function (data) { + if (data.status === 'success') { + right_map[path] = data.html_str; + $("#right_panel").html(right_map[path]); + } + else { + right_map[path] = "" + } + $("#right_panel").html(right_map[path_after]); + },error:function(jqXHR, textStatus, errorThrown){ + if(jqXHR.readyState===0&&jqXHR.status===0){ + alert('网络故障,提交失败!请联网后重新提交'); + } + } + }); + } +} // 打开一个已经存在的标签页 // 注意这个还得将对应的路径更改了 -function open_tab(path,archor) { +function open_tab(normal_path,archor,project_id) { try{ - // console.log(window.location.pathname); 端口号后面的路径 - path_input=path - path = path_predeal(path) - - $('#jstree').jstree("deselect_all", true); - $('#jstree').jstree("select_node", tree_nodes[path]); - setTimeout(function timer() { - var offsettop=$("#"+tree_nodes[path]).position().top; - $("#filelist-content").scrollTop(offsettop); - },500) - var tabcontent = document.getElementsByClassName("codereading"); - for (var i = 0; i < tabcontent.length; i++) { - tabcontent[i].style.display = "none"; - } - - var tab_items = document.getElementsByClassName("tab_item"); - for (var i = 0; i < tab_items.length; i++) { - // debugger; - tab_items[i].className = tab_items[i].className.replace(" active", ""); - } - - document.getElementById("code_" + path).style.display = "block"; - document.getElementById("tab_" + path).style.display = "block"; - document.getElementById("tab_" + path).className += " active"; - - url_deal(path_input,archor) - - document.getElementsByClassName("filename")[0].innerHTML = path_input; - - if((path in right_map)){ - $("#right_panel").html(right_map[path]); - } - + highlight_jstree_node(project_id,normal_path); + // console.log(window.location.pathname); 端口号后面的路径 + var path_after = path_predeal(normal_path) + deal_for_tab(project_id,normal_path,path_after) + url_deal(normal_path,archor) + document.getElementsByClassName("filename")[0].innerHTML = normal_path; + deal_for_right(project_id,normal_path,path_after) // if(!issue_map.has(path)){ // window.setTimeout(function () { $("#hotest_issue").html(issue_map[path]) }, 3000); // }else{ @@ -1143,10 +1168,66 @@ function get_path_link_and_archor(path){ return [path,null] } +function change_jstree_position(path_after){ + $('#jstree').jstree("deselect_all", true); + $('#jstree').jstree("select_node", tree_nodes[path_after]); + setTimeout(function timer() { + var offsettop=$("#"+tree_nodes[path_after]).position().top; + $("#filelist-content").scrollTop(offsettop); + },500) + // var offsettop=$("#"+tree_nodes[path_after]).position().top; + // $("#filelist-content").scrollTop(offsettop); +} + + +function get_codereading_content(project_id,normal_path,path_after){ + div_codereading = document.getElementById("code_"+path_after) + if(div_codereading.innerHTML==""){ + $.ajax({ + cache: false, + type: "POST", + url: '/operations/get_codereading_content/', + data: { 'project_id': project_id, 'path': normal_path }, + dataType: 'json', + async: true, + beforeSend: function (xhr, settings) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + }, + + success: function (data) { + if (data.status === 'success') { + // 获取code-reading的内容,并填充到对应的code-reading的Element + if(data.is_dir=="0"){ + var content = generate_codereading_content(data.lines,data.self_annos,data.fileid,data.annos_count,data.issues_count,data.questions_count,data.issues,data.language) + div_codereading.innerHTML = content; + hljs.configure({useBR: false}); + // hljs.highlightBlock(div_codereading) + $('#code_'+path_after+' pre code').each(function(i, block) { + hljs.highlightBlock(block); + }); + // .each(function(i, block) { + // hljs.highlightBlock(block); + // }); + }else{ + var content = data.html_str + div_codereading.innerHTML = content; + } + } + else { + div_codereading.innerHTML = ""; + } + },error:function(jqXHR, textStatus, errorThrown){ + if(jqXHR.readyState===0&&jqXHR.status===0){ + alert('网络故障,提交失败!请联网后重新提交'); + } + } + }); + } +} + function add_tab(project_id,path,filename) { // var tree_node = $("#jstree").jstree("get_selected"); - var path_before = path var returnValue = get_path_link_and_archor(path) // 正常应该得到的path为normal path @@ -1155,7 +1236,7 @@ function add_tab(project_id,path,filename) { path = path_predeal(normal_path) if (tabSet.has(path)) { - open_tab(normal_path,archor) + open_tab(normal_path,archor,project_id) } else { var tab_tag = document.getElementsByClassName("tab_head")[0]; //添加tab @@ -1178,7 +1259,7 @@ function add_tab(project_id,path,filename) { tag_a1.textContent = filename tag_a1.onclick = (function () { return function () { - open_tab(normal_path,null); + open_tab(normal_path,null,project_id); } })(); @@ -1205,84 +1286,7 @@ function add_tab(project_id,path,filename) { // div_codereading.style.overflowY="auto"; div_code.appendChild(div_codereading) - $.ajax({ - cache: false, - type: "POST", - url: '/operations/right/', - data: { 'project_id': project_id, 'path': normal_path}, - dataType: 'json', - async: true, - beforeSend: function (xhr, settings) { - xhr.setRequestHeader("X-CSRFToken", csrftoken); - }, - success: function (data) { - if (data.status === 'success') { - right_map[path] = data.html_str; - $("#right_panel").html(right_map[path]); - } - else { - right_map[path] = "" - } - },error:function(jqXHR, textStatus, errorThrown){ - if(jqXHR.readyState===0&&jqXHR.status===0){ - alert('网络故障,提交失败!请联网后重新提交'); - } - } - }); - - $.ajax({ - cache: false, - type: "POST", - url: '/operations/get_codereading_content/', - data: { 'project_id': project_id, 'path': normal_path }, - dataType: 'json', - async: true, - beforeSend: function (xhr, settings) { - xhr.setRequestHeader("X-CSRFToken", csrftoken); - }, - - success: function (data) { - if (data.status === 'success') { - // 获取code-reading的内容,并填充到对应的code-reading的Element - - if(data.is_dir=="0"){ - var content = generate_codereading_content(data.lines,data.self_annos,data.fileid,data.annos_count,data.issues_count,data.questions_count,data.issues,data.language) - div_codereading.innerHTML = content; - open_tab(normal_path,archor); - - hljs.configure({useBR: false}); - // hljs.highlightBlock(div_codereading) - $('#code_'+path+' pre code').each(function(i, block) { - hljs.highlightBlock(block); - }); - // .each(function(i, block) { - // hljs.highlightBlock(block); - // }); - }else{ - var content = data.html_str - div_codereading.innerHTML = content; - open_tab(normal_path,archor); - } - - // 如果包含# - // tmp_index = path_before.indexOf("#"); - // if(tmp_index != -1){ - // var hash = path_before.substring(tmp_index) - // } - // console.log(hash) - // location.hash=hash - } - else { - div_codereading.innerHTML = ""; - } - },error:function(jqXHR, textStatus, errorThrown){ - if(jqXHR.readyState===0&&jqXHR.status===0){ - alert('网络故障,提交失败!请联网后重新提交'); - } - } - }); - - open_tab(normal_path,archor); + open_tab(normal_path,archor,project_id); // 现在Hotest Question 模块先不用了 // // 填充hotest_question @@ -1306,42 +1310,39 @@ function add_tab(project_id,path,filename) { // } // }); - highlight_jstree_node(project_id,normal_path); - tabSet.add(path); } } -function highlight_jstree_node(project_id,path_after){ - path = path_predeal(path_after) - $.ajax({ - cache: false, - type: "POST", - url: '/operations/get_jstree_id/', - data: { 'project_id': project_id, 'path': path_after}, - dataType: 'json', - async: true, - beforeSend: function (xhr, settings) { - xhr.setRequestHeader("X-CSRFToken", csrftoken); - }, - success: function (data) { - if (data.status === 'success') { - var tree_node = data.jstree_id - tree_nodes[path]=tree_node - $('#jstree').jstree("deselect_all", true); - $('#jstree').jstree("select_node", tree_nodes[path]); - // location.href="#"+tree_node - setTimeout(function timer() { - var offsettop=$("#"+tree_nodes[path]).position().top; - $("#filelist-content").scrollTop(offsettop); - },500) +function highlight_jstree_node(project_id,normal_path){ + path_after = path_predeal(normal_path) + if(path_after in tree_nodes){ + change_jstree_position(path_after) + }else{ + $.ajax({ + cache: false, + type: "POST", + url: '/operations/get_jstree_id/', + data: { 'project_id': project_id, 'path': normal_path}, + dataType: 'json', + async: true, + beforeSend: function (xhr, settings) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + }, + success: function (data) { + if (data.status === 'success') { + var tree_node = data.jstree_id + tree_nodes[path_after]=tree_node + change_jstree_position(path_after) + } + },error:function(jqXHR, textStatus, errorThrown){ + if(jqXHR.readyState===0&&jqXHR.status===0){ + alert('网络故障,提交失败!请联网后重新提交'); + } } - },error:function(jqXHR, textStatus, errorThrown){ - if(jqXHR.readyState===0&&jqXHR.status===0){ - alert('网络故障,提交失败!请联网后重新提交'); - } - } - }); + }); + } + } // 这里也可以更改为item,传入this function close_tab(path) { @@ -1360,13 +1361,13 @@ function close_tab(path) { // 如果该标签页有上一个标签,将此标签的上一个标签页打开 if (previosuElement != undefined) { var path = previosuElement.id.substr(4); - open_tab(path,null) + open_tab(path,null,project_id) return; } // 如果该标签页有下一个兄弟标签,将此标签的下一个标签页打开 if (nextElement != undefined) { var path = nextElement.id.substr(4); - open_tab(path,null); + open_tab(path,null,project_id); return; } } @@ -2101,7 +2102,7 @@ function init_jstree(project_id,path,content){ $(".spinner").remove(); $("#jstree").jstree("open_node", $("#j1_1")); $("#jstree").css("visibility","visible"); - highlight_jstree_node(project_id,path) + // highlight_jstree_node(project_id,path) } $(function(){