Skip to content

Commit cbae285

Browse files
committed
跳转到详情页面
1 parent 04c166e commit cbae285

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎template/js/index.js‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,30 @@
77
this.elm_info = $$('commands_info');
88
this.elm_result = $$('result');
99

10+
// 获取根路径
11+
this.root_path = (function(){
12+
var elm_path = $$('current_path');
13+
var url = window.location.origin+window.location.pathname;
14+
return elm_path?url.replace(elm_path.value,''):'';
15+
})();
16+
1017
this.query = ''; //
1118
this.page_size = 10; //每页显示10条
1219

1320
this.init()
21+
this.goToIndex()
1422
}
1523

1624
Commands.prototype = {
1725
$$:function(id){
1826
return document.getElementById(id)
1927
},
28+
goToIndex(){
29+
var elma = document.getElementsByTagName('A');
30+
for (var i = 0; i < elma.length; i++) {
31+
if(elma[i].pathname==='/') elma[i].href = this.root_path.replace(/\/$/,'')+'/';
32+
}
33+
},
2034
bindEvent:function(elm,type,handle){
2135
if (elm.addEventListener) {
2236
elm.addEventListener(type, handle, false);
@@ -38,9 +52,7 @@
3852
//获取URL上面的参数
3953
getQueryString:function(name) {
4054
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
41-
console.log("reg1:",reg);
4255
var r = decodeURIComponent(window.location.hash.replace(/^(\#\!|\#)/,'')).match(reg);
43-
console.log("reg2:",r);
4456
if (r != null) return unescape(r[2]); return null;
4557
},
4658
pushState:function(){
@@ -63,22 +75,18 @@
6375
des = json.d.replace(reg,'<i class="kw">'+"$1"+"</i>") || '';
6476
}
6577

66-
return this.simple('<a href="https://github.com/c$url$.html"><strong>$name$</strong> - $des$</a>',{
78+
return this.simple('<a href="'+this.root_path+'/c$url$.html"><strong>$name$</strong> - $des$</a>',{
6779
name:name,
6880
url:json.p,
6981
des:des
7082
})
7183

72-
},
73-
// 获取根路径
74-
getRootPath(){
75-
7684
},
7785
createListHTML:function(){
7886
var arr = this.commands,self = this,page_size = this.page_size,i=0;
7987
if(arr&&arr.length&&toString.call(arr).indexOf('Array')>-1){
8088
self.elm_result.innerHTML='';
81-
var relese = 0
89+
var relese = 0;
8290
for (; i < page_size; i++) {
8391
if(!arr[i]) break;
8492
var myLi = document.createElement("LI");
@@ -89,10 +97,10 @@
8997
myLi.innerHTML = self.createKeyworldsHTML(arr[i],self.query)
9098
self.elm_result.appendChild(myLi);
9199
}
92-
if(relese ===0){
93-
myLi.innerHTML = '<span>没有任何内容,请尝试输入其它字符!</span>';
94-
self.elm_result.innerHTML = myLi.outerHTML;
95-
}
100+
}
101+
if(relese ===0){
102+
myLi.innerHTML = '<span>没有任何内容,请尝试输入其它字符!</span>';
103+
self.elm_result.innerHTML = myLi.outerHTML;
96104
}
97105
}
98106
},

‎template/search.ejs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ul>
1212
<input type="text" class="query" id="query" autocomplete="off" placeholder="Linux 命令搜索"/>
1313
<div class="enter-input">
14-
<input type="hidden" name="current_path" value="<%=current_path%>">
14+
<input type="hidden" id="current_path" value="<%=current_path%>">
1515
<button id="search_btn">搜索</button>
1616
</div>
1717
</div>

0 commit comments

Comments
 (0)