mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-05-09 16:17:48 +08:00
实现项目内搜索
This commit is contained in:
parent
f7725c0a1f
commit
08c4d52116
BIN
static/images/loading.gif
Normal file
BIN
static/images/loading.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 771 B |
@ -88,15 +88,18 @@
|
|||||||
<form id="searchForm" action="{{urlfor "DocumentController.Search" ":key" .Model.Identify}}" method="post">
|
<form id="searchForm" action="{{urlfor "DocumentController.Search" ":key" .Model.Identify}}" method="post">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="search" placeholder="请输入搜索关键字" class="form-control" name="keyword">
|
<input type="search" placeholder="请输入搜索关键字" class="form-control" name="keyword">
|
||||||
<button type="submit" class="btn btn-default btn-search">
|
<button type="submit" class="btn btn-default btn-search" id="btnSearch">
|
||||||
<i class="fa fa-search"></i>
|
<i class="fa fa-search"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="search-result">
|
<div class="search-result">
|
||||||
<ul class="search-list">
|
<div class="search-empty">
|
||||||
<li data-id="256300"><span class="text">下载及安装</span></li>
|
<i class="fa fa-search-plus" aria-hidden="true"></i>
|
||||||
|
<b class="text">暂无相关搜索结果!</b>
|
||||||
|
</div>
|
||||||
|
<ul class="search-list" id="searchList">
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -230,6 +233,52 @@
|
|||||||
|
|
||||||
hljs.initLineNumbersOnLoad();
|
hljs.initLineNumbersOnLoad();
|
||||||
}
|
}
|
||||||
|
function loadDocument($url,$id) {
|
||||||
|
$.ajax({
|
||||||
|
url : $url,
|
||||||
|
type : "GET",
|
||||||
|
beforeSend :function (xhr) {
|
||||||
|
var body = events.data('body_' + $id);
|
||||||
|
var title = events.data('title_' + $id);
|
||||||
|
var doc_title = events.data('doc_title_' + $id);
|
||||||
|
|
||||||
|
if(body && title && doc_title){
|
||||||
|
|
||||||
|
$("#page-content").html(body);
|
||||||
|
$("title").text(title);
|
||||||
|
$("#article-title").text(doc_title);
|
||||||
|
|
||||||
|
events.trigger('article.open',$url,true);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
NProgress.start();
|
||||||
|
},
|
||||||
|
success : function (res) {
|
||||||
|
if(res.errcode === 0){
|
||||||
|
var body = res.data.body;
|
||||||
|
var doc_title = res.data.doc_title;
|
||||||
|
var title = res.data.title;
|
||||||
|
|
||||||
|
$("#page-content").html(body);
|
||||||
|
$("title").text(title);
|
||||||
|
$("#article-title").text(doc_title);
|
||||||
|
|
||||||
|
events.data('body_' + $id,body);
|
||||||
|
events.data('title_' + $id,title);
|
||||||
|
events.data('doc_title_' + $id,doc_title);
|
||||||
|
|
||||||
|
events.trigger('article.open',$url,false);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
layer.msg("加载失败");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
complete : function () {
|
||||||
|
NProgress.done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
window.isFullScreen = false;
|
window.isFullScreen = false;
|
||||||
@ -255,50 +304,8 @@
|
|||||||
if(url === window.location.href){
|
if(url === window.location.href){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$.ajax({
|
loadDocument(url,selected.node.id);
|
||||||
url : url,
|
|
||||||
type : "GET",
|
|
||||||
beforeSend :function (xhr) {
|
|
||||||
var body = events.data('body_' + selected.node.id);
|
|
||||||
var title = events.data('title_' + selected.node.id);
|
|
||||||
var doc_title = events.data('doc_title_' + selected.node.id);
|
|
||||||
|
|
||||||
if(body && title && doc_title){
|
|
||||||
|
|
||||||
$("#page-content").html(body);
|
|
||||||
$("title").text(title);
|
|
||||||
$("#article-title").text(doc_title);
|
|
||||||
|
|
||||||
events.trigger('article.open',url,true);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
NProgress.start();
|
|
||||||
},
|
|
||||||
success : function (res) {
|
|
||||||
if(res.errcode === 0){
|
|
||||||
var body = res.data.body;
|
|
||||||
var doc_title = res.data.doc_title;
|
|
||||||
var title = res.data.title;
|
|
||||||
|
|
||||||
$("#page-content").html(body);
|
|
||||||
$("title").text(title);
|
|
||||||
$("#article-title").text(doc_title);
|
|
||||||
|
|
||||||
events.data('body_' + selected.node.id,body);
|
|
||||||
events.data('title_' + selected.node.id,title);
|
|
||||||
events.data('doc_title_' + selected.node.id,doc_title);
|
|
||||||
|
|
||||||
events.trigger('article.open',url,false);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
layer.msg("加载失败");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
complete : function () {
|
|
||||||
NProgress.done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#slidebar").on("click",function () {
|
$("#slidebar").on("click",function () {
|
||||||
@ -339,16 +346,45 @@
|
|||||||
$(".m-manual").removeClass("manual-mode-view manual-mode-collect manual-mode-search").addClass("manual-mode-" + mode);
|
$(".m-manual").removeClass("manual-mode-view manual-mode-collect manual-mode-search").addClass("manual-mode-" + mode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目内搜索
|
||||||
|
*/
|
||||||
$("#searchForm").ajaxForm({
|
$("#searchForm").ajaxForm({
|
||||||
beforeSubmit : function () {
|
beforeSubmit : function () {
|
||||||
var keyword = $.trim($("#searchForm").find("input[name='keyword']").val());
|
var keyword = $.trim($("#searchForm").find("input[name='keyword']").val());
|
||||||
if(keyword === ""){
|
if(keyword === ""){
|
||||||
|
$(".search-empty").show();
|
||||||
|
$("#searchList").html("");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading");
|
||||||
},
|
},
|
||||||
success :function () {
|
success :function (res) {
|
||||||
|
var html = "";
|
||||||
|
if(res.errcode === 0){
|
||||||
|
for(var i in res.data){
|
||||||
|
var item = res.data[i];
|
||||||
|
html += '<li><a href="javascript:;" title="'+ item.doc_name +'" data-id="'+ item.doc_id+'"> '+ item.doc_name +' </a></li>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(html !== ""){
|
||||||
|
$(".search-empty").hide();
|
||||||
|
}else{
|
||||||
|
$(".search-empty").show();
|
||||||
|
}
|
||||||
|
$("#searchList").html(html);
|
||||||
|
},
|
||||||
|
complete : function () {
|
||||||
|
$("#btnSearch").removeAttr("disabled").find("i").removeClass("loading").addClass("fa-search");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#searchList").on("click","a",function () {
|
||||||
|
var id = $(this).attr("data-id");
|
||||||
|
var url = "{{urlfor "DocumentController.Read" ":key" .Model.Identify ":id" ""}}/" + id;
|
||||||
|
$(this).parent("li").siblings().find("a").removeClass("active");
|
||||||
|
$(this).addClass("active");
|
||||||
|
loadDocument(url,id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user