优化数据浏览页面中的js代码

This commit is contained in:
Li Jianxuan 2013-04-10 09:44:56 +00:00
parent c0f86e6012
commit 56e5dcc0cc
4 changed files with 267 additions and 645 deletions

View File

@ -116,7 +116,7 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="active"><a href="#related" data-toggle="tab" id="related_t">相关数据</a></li> <li class="active"><a href="#related" data-toggle="tab" id="related_t">相关数据</a></li>
<li><a href="#literature" data-toggle="tab" id="literature_t">相关文献</a></li> <li><a href="#literature" data-toggle="tab" id="literature_t">相关文献</a></li>
<li><a href="#gsearch" data-toggle="tab">相关搜索</a></li> <li><a href="#gsearch" data-toggle="tab" id="gsearch_t">相关搜索</a></li>
<li><a href="#service" data-toggle="tab">服务记录</a></li> <li><a href="#service" data-toggle="tab">服务记录</a></li>
<li><a href="#recommend" data-toggle="tab" id="recommend_t">给我推荐</a></li> <li><a href="#recommend" data-toggle="tab" id="recommend_t">给我推荐</a></li>
</ul> </ul>
@ -132,8 +132,7 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
<li><a href="javascript:;" class="scholar">Google学术搜索</a></li> <li><a href="javascript:;" class="scholar">Google学术搜索</a></li>
<li><a href="javascript:;" class="cnkiSearch">CNKI学术搜索</a></li> <li><a href="javascript:;" class="cnkiSearch">CNKI学术搜索</a></li>
</ul> </ul>
<ul id="searchlist" class="unstyled span6 well well-small"> <ul id="searchlist" class="unstyled span6 well well-small"></ul>
</ul>
</div> </div>
<div id="service" class="tab-pane"> <div id="service" class="tab-pane">
<?php if ($this->downhistory) : ?> <?php if ($this->downhistory) : ?>
@ -247,6 +246,7 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
if($v['keytype'] == "category"){ $title = "类别"; if($v['keytype'] == "category"){ $title = "类别";
}else if($v['keytype'] == "discipline"){$title = "学科"; }else if($v['keytype'] == "discipline"){$title = "学科";
}else if($v['keytype'] == "place"){$title = "地点"; }else if($v['keytype'] == "place"){$title = "地点";
}else if($v['keytype'] == "temporal"){$title = "时间";
}else if($v['keytype'] == "theme"){ $title = "主题"; }else if($v['keytype'] == "theme"){ $title = "主题";
} }
$keys[$title][] = $v['keyword']; $keys[$title][] = $v['keyword'];
@ -401,20 +401,9 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
</div> </div>
</div> </div>
</div> </div>
<script src="/js/metadata-view.js"></script>
<div id="todownload" style="display:none;">
<div id="formcontent"></div>
</div>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){$(".colorbox").colorbox({photo:"true"});}); ajaxpage(0);
//ajax comment
function ajaxpage(page){$.ajax({type:"GET",url:"/data/comment/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#allcomments').html(html);},
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />加载中');}});};ajaxpage(0);
function postcomment(){ $.ajax({'type':"POST",'url':"/data/postcomment",'data':$('#postcommentform').serialize(),
'success':function(html){$('#postcomment').html('提交');setTimeout("$('#postcomment').removeAttr('disabled');",3000);$('#returninfo').html(html);},
'beforeSend':function(){$('#postcomment').attr('disabled','disabled');$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...'); }});}
$('#literature_t').click(function(){literature(1);}); $('#literature_t').click(function(){literature(1);});
//ajax literature //ajax literature
function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');}, function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
@ -430,10 +419,6 @@ $('#recommend_t').click(function(){recommend(0);});
function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ul>'+html+'</ul>');}, function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ul>'+html+'</ul>');},
beforeSend:function(){$('#recommend').html('<img src="/images/loading.gif" />加载中');}});} beforeSend:function(){$('#recommend').html('<img src="/images/loading.gif" />加载中');}});}
//ajax comment
ajaxpage(0);
function ajaxpage(page){ function ajaxpage(page){
var url = "/data/comment/uuid/<?= $md->uuid; ?>"; var url = "/data/comment/uuid/<?= $md->uuid; ?>";
data='page='+page; data='page='+page;
@ -445,225 +430,18 @@ function ajaxpage(page){
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');} beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');}
}); });
}; };
function postcomment(){
var url="/data/postcomment";
var date = $('#postcommentform').serialize();
$.ajax({
'type':"POST",
'url':url,
'data':date,
'success':function(html){
$('#postcomment').html('提交');
setTimeout("$('#postcomment').removeAttr('disabled');",3000);
$('#returninfo').html(html);
ajaxpage(0);
},
'beforeSend':function(){
$('#postcomment').attr('disabled','disabled');
$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...');
}
});
}
$('#gsearch_t').click(function(){
function getFileList(){ if($('#searchlist').children('li').length<1)
html ='<div id="window-outter">'
+ '<div id="window-inner">'
+ '<div id="window-content-container">'
+ '<div id="window-loading">加载中...</div>'
+ '<ol id="file-list">'
+ '</ol>'
+ '</div>'
+ '</div>'
+'</div>';
$.colorbox({width:"80%",height:"80%",html:html});
$.getJSON("/service/filelist/uuid/<?php echo $md->uuid;?>", function(data) {
var items = [];
if(data.length>0)
{ {
$.each(data, function(key, val) { googleSearch('<?php echo $ev;?>');
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="li_' + val['id'] + '">' + val['filename'] + '</li>');
} }
}); });
}else{
items.push('<li>暂无数据</li>');
}
$('#file-list').html(items.join(''));
})
.complete(function() {
$('#window-loading').hide();
});
}
function getSubFileList(uuid,id,depth){
if($("#div_"+id).length>0)
{
$('#span_'+id).html('+');
$("#div_"+id).remove();
return false;
}
$('<div/>', {
'style':'overflow:auto;',
'id': 'div_'+id,
"html": '<li><img src="/images/loading.gif" />加载中</li>'
}).appendTo('#li_'+id);
url="/service/subfilelist/uuid/"+uuid+"/subpath/"+id+"/depth/"+depth;
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="' + key + '">' + val['filename'] + '</li>');
}
});
$("#div_"+id).html(items.join(''));
}).complete(function(){
if($("#div_"+id)){
$('#span_'+id).html('-');
}
});
}
$('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');}); $('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');});
$('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');}); $('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');});
$('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');}); $('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');});
$('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');}); $('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');});
function googleSearch(keyword){
$.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.responseData.results, function(key, val) {
var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="'+obj.responseData.cursor.moreResultsUrl+'" target="_blank">查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function scholarSearch(keyword){
$.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword,
success:function(html){
//$('#searchlist').html(html);return false;
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = val['title']
+'<p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function bingSearch(keyword){
$.ajax({type:"POST",url:"/service/bingsearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.SearchResponse.Web.Total==0)
{$('#searchlist').html("No results!");return false;}
$.each(obj.SearchResponse.Web.Results, function(key, val) {
var html = '<p><a href="' +val['Url']+'">'+val['Title']+'<a/></p><p><span>'
+val['DisplayUrl'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['Description']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="http://cn.bing.com/search?q=<?php echo urlencode($ev); ?>&go=&qs=n&sk=&form=QBLH" target="_blank">查看更多搜索结果(约'+obj.SearchResponse.Web.Total+'条)</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function cnkiSearch(keyword){
$.ajax({type:"POST",url:"/service/cnkisearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'</a></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function dataVersion()
{
$.ajax({
'type':"POST",
'url':'/data/getversion',
'data':'ac=list&uuid=<?php echo $md->uuid; ?>',
'success':onDataVersionLoad,
'timeout': 30000,
'error': function(){Alert('处理中出现错误,请刷新页面后重试');return false;}
});
}
function onDataVersionLoad(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{Alert(data.error);return false;}
if(typeof(data.list)!='undefined')
{
var html = "";
for(v in data.list)
{
html+='<li><p>'+data.list[v].changelog+'</p><p>'+data.list[v].ts_created+' by '+data.list[v].username+'</p></li>';
}
$.colorbox({'innerWidth':'50%','innerHeight':'80%','html':'<div class="datalist"><ul>'+html+'</ul></div>'});
}
}
else{
Alert('出现错误,请稍后再试');return false;
}
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4 style="font-size:16px;font-weight:bold;">'+html+'</h4>'});
}
var map = null; var map = null;
var mapElementID = null; var mapElementID = null;
var bounds = null; var bounds = null;
@ -713,6 +491,7 @@ function setRectangle(east,west,south,north){
$(function() { $(function() {
google.maps.event.addDomListener(window, 'load', initialize); google.maps.event.addDomListener(window, 'load', initialize);
$(".colorbox").colorbox({photo:"true"});
}); });
</script> </script>
<?php else: ?> <?php else: ?>

View File

@ -404,49 +404,9 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
</div> </div>
</div> </div>
</div> </div>
<script src="/js/metadata-view.js"></script>
<div id="window-outter" style="display:none;">
<div id="window-inner">
<div id="window-content-container">
<div id="window-loading">加载中...</div>
<ol id="file-list">
</ol>
</div>
</div>
</div>
<div id="todownload" style="display:none;">
<div id="formcontent"></div>
</div>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
ajaxpage(0);
$(document).ready(function(){$(".colorbox").colorbox({photo:"true"});});
//ajax download
function todownload(ft)
{
if(ft!=0){$.colorbox({width:"80%",height:"80%",html:$('#todownload').html()});}
var url = "/data/todownload/uuid/<?php echo $md->uuid;?>/ft/"+ft;
if($('#todownloadform')) var date = $('#todownloadform').serialize();
$.ajax({
type:"GET",
url:url,
data:date,
success:function(html){
$('#formcontent').html(html);
},
beforeSend:function(){
$('#formcontent').html('<img src="/images/11887177066.gif" />');
}
});
}
//ajax comment
function ajaxpage(page){$.ajax({type:"GET",url:"/data/comment/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#allcomments').html(html);},
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />加载中');}});};ajaxpage(0);
function postcomment(){ $.ajax({'type':"POST",'url':"/data/postcomment",'data':$('#postcommentform').serialize(),
'success':function(html){$('#postcomment').html('提交');setTimeout("$('#postcomment').removeAttr('disabled');",3000);$('#returninfo').html(html);},
'beforeSend':function(){$('#postcomment').attr('disabled','disabled');$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...'); }});}
$('#literature_t').click(function(){literature(1);}); $('#literature_t').click(function(){literature(1);});
//ajax literature //ajax literature
function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');}, function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
@ -462,157 +422,29 @@ $('#recommend_t').click(function(){recommend(0);});
function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ul>'+html+'</ul>');}, function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ul>'+html+'</ul>');},
beforeSend:function(){$('#recommend').html('<img src="/images/loading.gif" />加载中');}});} beforeSend:function(){$('#recommend').html('<img src="/images/loading.gif" />加载中');}});}
function getFileList(){ function ajaxpage(page){
$.colorbox({width:"80%",height:"80%",html:$('#window-outter').html()}); var url = "/data/comment/uuid/<?= $md->uuid; ?>";
$.getJSON("/service/filelist/uuid/<?php echo $md->uuid;?>", function(data) { data='page='+page;
var items = []; $.ajax({
if(data.length>0) type:"GET",
{ url:url,
$.each(data, function(key, val) { data:data,
if(val['filename'].match(/\/$/)) success:function(html){$('#allcomments').html(html);},
{ beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');}
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="li_' + val['id'] + '">' + val['filename'] + '</li>');
}
}); });
}else{ };
items.push('<li>暂无数据</li>');
}
$('#file-list').html(items.join(''));
})
.complete(function() {$('#window-loading').hide();});
}
function getSubFileList(uuid,id,depth){
if($("#div_"+id).length>0)
{
$('#span_'+id).html('+');
$("#div_"+id).remove();
return false;
}
$('<div/>', {
'style':'',
'id': 'div_'+id,
"html": '<li><img src="/images/loading.gif" />加载中</li>'
}).appendTo('#li_'+id);
url="/service/subfilelist/uuid/"+uuid+"/subpath/"+id+"/depth/"+depth;
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="' + key + '">' + val['filename'] + '</li>');
}
});
$("#div_"+id).html(items.join(''));
}).complete(function(){
if($("#div_"+id)){
$('#span_'+id).html('-');
}
});
}
$('#gsearch_t').click(function(){
if($('#searchlist').children('li').length<1)
{
googleSearch('<?php echo $ev;?>');
}
});
$('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');}); $('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');});
$('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');}); $('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');});
$('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');}); $('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');});
$('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');}); $('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');});
function googleSearch(keyword){
$.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.responseData.results, function(key, val) {
var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="'+obj.responseData.cursor.moreResultsUrl+'" target="_blank">查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function scholarSearch(keyword){
$.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword,
success:function(html){
//$('#searchlist').html(html);return false;
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = val['title']
+'<p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function bingSearch(keyword){
$.ajax({type:"POST",url:"/service/bingsearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.SearchResponse.Web.Total==0)
{$('#searchlist').html("No results!");return false;}
$.each(obj.SearchResponse.Web.Results, function(key, val) {
var html = '<p><a href="' +val['Url']+'">'+val['Title']+'<a/></p><p><span>'
+val['DisplayUrl'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['Description']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="http://cn.bing.com/search?q=<?php echo urlencode($ev); ?>&go=&qs=n&sk=&form=QBLH" target="_blank">查看更多搜索结果(约'+obj.SearchResponse.Web.Total+'条)</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function cnkiSearch(keyword){
$.ajax({type:"POST",url:"/service/cnkisearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'</a></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
var map = null; var map = null;
var mapElementID = null; var mapElementID = null;
var bounds = null; var bounds = null;
@ -662,6 +494,7 @@ function setRectangle(east,west,south,north){
$(function() { $(function() {
google.maps.event.addDomListener(window, 'load', initialize); google.maps.event.addDomListener(window, 'load', initialize);
$(".colorbox").colorbox({photo:"true"});
}); });
</script> </script>
<?php else: ?> <?php else: ?>

View File

@ -379,7 +379,7 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
<li>元数据更新时间:<?php print date('Y-m-d',strtotime($md->ts_created)); ?> <a href="/service/xml/uuid/<?php echo $md->uuid;?>"><img src="/images/xml.gif" alt="查看XML源文件"></a><a href="/service/doc/uuid/<?php echo $md->uuid; ?>"><img src="/images/doc-icon.png" alt="Word doc格式"></a></li> <li>元数据更新时间:<?php print date('Y-m-d',strtotime($md->ts_created)); ?> <a href="/service/xml/uuid/<?php echo $md->uuid;?>"><img src="/images/xml.gif" alt="查看XML源文件"></a><a href="/service/doc/uuid/<?php echo $md->uuid; ?>"><img src="/images/doc-icon.png" alt="Word doc格式"></a></li>
<!--<li><a href="/data/detail/id/<?php echo $md->id;?>">详细元数据</a></li>--> <!--<li><a href="/data/detail/id/<?php echo $md->id;?>">详细元数据</a></li>-->
<?php if($this->version->c>0):?> <?php if($this->version->c>0):?>
<li id="dataversion">版本历史:<a href="javascript:void(0);" onclick="dataVersion()" title=""><?= $this->version->c ?><img src="/images/list_extensions.gif" style="vertical-align:middle" /></a></li> <li id="dataversion">版本历史:<a href="javascript:void(0);" onclick="dataVersion('<?php echo $md->uuid; ?>')" title=""><?= $this->version->c ?><img src="/images/list_extensions.gif" style="vertical-align:middle" /></a></li>
<?php endif;?> <?php endif;?>
</ul> </ul>
</div> </div>
@ -403,30 +403,9 @@ if ($md->title_en) echo '<br />'.$this->escape($md->title_en);?>
</div> </div>
</div> </div>
</div> </div>
<script src="/js/metadata-view.js"></script>
<div id="window-outter" style="display:none;">
<div id="window-inner">
<div id="window-content-container">
<div id="window-loading">加载中...</div>
<ol id="file-list">
</ol>
</div>
</div>
</div>
<div id="todownload" style="display:none;">
<div id="formcontent"></div>
</div>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){$(".colorbox").colorbox({photo:"true"});}); ajaxpage(0);
//ajax comment
function ajaxpage(page){$.ajax({type:"GET",url:"/data/comment/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#allcomments').html(html);},
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />加载中');}});};ajaxpage(0);
function postcomment(){ $.ajax({'type':"POST",'url':"/data/postcomment",'data':$('#postcommentform').serialize(),
'success':function(html){$('#postcomment').html('提交');setTimeout("$('#postcomment').removeAttr('disabled');",3000);$('#returninfo').html(html);},
'beforeSend':function(){$('#postcomment').attr('disabled','disabled');$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...'); }});}
$('#literature_t').click(function(){literature(1);}); $('#literature_t').click(function(){literature(1);});
//ajax literature //ajax literature
function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');}, function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('<ol start="'+ ((page-1)*10+1) +'">'+html+'</ol>');},
@ -442,10 +421,6 @@ $('#recommend_t').click(function(){recommend(0);});
function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ul>'+html+'</ul>');}, function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/<?= $md->uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('<ul>'+html+'</ul>');},
beforeSend:function(){$('#recommend').html('<img src="/images/loading.gif" />加载中');}});} beforeSend:function(){$('#recommend').html('<img src="/images/loading.gif" />加载中');}});}
//ajax comment
ajaxpage(0);
function ajaxpage(page){ function ajaxpage(page){
var url = "/data/comment/uuid/<?= $md->uuid; ?>"; var url = "/data/comment/uuid/<?= $md->uuid; ?>";
data='page='+page; data='page='+page;
@ -457,214 +432,18 @@ function ajaxpage(page){
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');} beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');}
}); });
}; };
function postcomment(){
var url="/data/postcomment";
var date = $('#postcommentform').serialize();
$.ajax({
'type':"POST",
'url':url,
'data':date,
'success':function(html){
$('#postcomment').html('提交');
setTimeout("$('#postcomment').removeAttr('disabled');",3000);
$('#returninfo').html(html);
ajaxpage(0);
},
'beforeSend':function(){
$('#postcomment').attr('disabled','disabled');
$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...');
}
});
}
$('#gsearch_t').click(function(){
function getFileList(){ if($('#searchlist').children('li').length<1)
$.colorbox({width:"80%",height:"80%",html:$('#window-outter').html()});
$.getJSON("/service/filelist/uuid/<?php echo $md->uuid;?>", function(data) {
var items = [];
if(data.length>0)
{ {
$.each(data, function(key, val) { googleSearch('<?php echo $ev;?>');
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="li_' + val['id'] + '">' + val['filename'] + '</li>');
} }
}); });
}else{
items.push('<li>暂无数据</li>');
}
$('#file-list').html(items.join(''));
})
.complete(function() {$('#window-loading').hide();});
}
function getSubFileList(uuid,id,depth){
if($("#div_"+id).length>0)
{
$('#span_'+id).html('+');
$("#div_"+id).remove();
return false;
}
$('<div/>', {
'style':'overflow:auto;',
'id': 'div_'+id,
"html": '<li><img src="/images/loading.gif" />加载中</li>'
}).appendTo('#li_'+id);
url="/service/subfilelist/uuid/"+uuid+"/subpath/"+id+"/depth/"+depth;
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="' + key + '">' + val['filename'] + '</li>');
}
});
$("#div_"+id).html(items.join(''));
}).complete(function(){
if($("#div_"+id)){
$('#span_'+id).html('-');
}
});
}
$('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');}); $('.googlesearch').click(function(){googleSearch('<?php echo $ev;?>');});
$('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');}); $('.bingsearch').click(function(){bingSearch('<?php echo $ev;?>');});
$('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');}); $('.cnkiSearch').click(function(){cnkiSearch('<?php echo $ev;?>');});
$('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');}); $('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');});
function googleSearch(keyword){
$.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.responseData.results, function(key, val) {
var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="'+obj.responseData.cursor.moreResultsUrl+'" target="_blank">查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function scholarSearch(keyword){
$.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword,
success:function(html){
//$('#searchlist').html(html);return false;
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = val['title']
+'<p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function bingSearch(keyword){
$.ajax({type:"POST",url:"/service/bingsearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.SearchResponse.Web.Total==0)
{$('#searchlist').html("No results!");return false;}
$.each(obj.SearchResponse.Web.Results, function(key, val) {
var html = '<p><a href="' +val['Url']+'">'+val['Title']+'<a/></p><p><span>'
+val['DisplayUrl'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['Description']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="http://cn.bing.com/search?q=<?php echo urlencode($ev); ?>&go=&qs=n&sk=&form=QBLH" target="_blank">查看更多搜索结果(约'+obj.SearchResponse.Web.Total+'条)</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function cnkiSearch(keyword){
$.ajax({type:"POST",url:"/service/cnkisearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'</a></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
});
}
function dataVersion()
{
$.ajax({
'type':"POST",
'url':'/data/getversion',
'data':'ac=list&uuid=<?php echo $md->uuid; ?>',
'success':onDataVersionLoad,
'timeout': 30000,
'error': function(){Alert('处理中出现错误,请刷新页面后重试');return false;}
});
}
function onDataVersionLoad(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{Alert(data.error);return false;}
if(typeof(data.list)!='undefined')
{
var html = "";
for(v in data.list)
{
html+='<li><p>'+data.list[v].changelog+'</p><p>'+data.list[v].ts_created+' by '+data.list[v].username+'</p></li>';
}
$.colorbox({'innerWidth':'50%','innerHeight':'80%','html':'<div class="datalist"><ul>'+html+'</ul></div>'});
}
}
else{
Alert('出现错误,请稍后再试');return false;
}
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4 style="font-size:16px;font-weight:bold;">'+html+'</h4>'});
}
var map = null; var map = null;
var mapElementID = null; var mapElementID = null;
var bounds = null; var bounds = null;
@ -714,6 +493,7 @@ function setRectangle(east,west,south,north){
$(function() { $(function() {
google.maps.event.addDomListener(window, 'load', initialize); google.maps.event.addDomListener(window, 'load', initialize);
$(".colorbox").colorbox({photo:"true"});
}); });
</script> </script>
<?php else: ?> <?php else: ?>

230
htdocs/js/metadata-view.js Normal file
View File

@ -0,0 +1,230 @@
function postcomment(){
var url="/data/postcomment";
var date = $('#postcommentform').serialize();
$.ajax({
'type':"POST",
'url':url,
'data':date,
'success':function(html){
$('#postcomment').html('提交');
setTimeout("$('#postcomment').removeAttr('disabled');",3000);
$('#returninfo').html(html);
ajaxpage(0);
},
'beforeSend':function(){
$('#postcomment').attr('disabled','disabled');
$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...');
}
});
}
function getFileList(){
html ='<div id="window-outter">'
+ '<div id="window-inner">'
+ '<div id="window-content-container">'
+ '<div id="window-loading">加载中...</div>'
+ '<ol id="file-list">'
+ '</ol>'
+ '</div>'
+ '</div>'
+'</div>';
$.colorbox({width:"80%",height:"80%",html:html});
$.getJSON("/service/filelist/uuid/<?php echo $md->uuid;?>", function(data) {
var items = [];
if(data.length>0)
{
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="li_' + val['id'] + '">' + val['filename'] + '</li>');
}
});
}else{
items.push('<li>暂无数据</li>');
}
$('#file-list').html(items.join(''));
})
.complete(function() {
$('#window-loading').hide();
});
}
function getSubFileList(uuid,id,depth){
if($("#div_"+id).length>0)
{
$('#span_'+id).html('+');
$("#div_"+id).remove();
return false;
}
$('<div/>', {
'style':'overflow:auto;',
'id': 'div_'+id,
"html": '<li><img src="/images/loading.gif" />加载中</li>'
}).appendTo('#li_'+id);
url="/service/subfilelist/uuid/"+uuid+"/subpath/"+id+"/depth/"+depth;
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="' + key + '">' + val['filename'] + '</li>');
}
});
$("#div_"+id).html(items.join(''));
}).complete(function(){
if($("#div_"+id)){
$('#span_'+id).html('-');
}
});
}
function googleSearch(keyword){
$.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.responseData.results, function(key, val) {
var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="'+obj.responseData.cursor.moreResultsUrl+'" target="_blank">查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)</a></div>');
$('#searchlist').html(items.join(''));
searchFinish();
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');},
error:function(){$('#searchlist').html('');Alert('检索中发现错误,请稍后重试或直接访问');}
});
}
function scholarSearch(keyword){
$.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword,
success:function(html){
//$('#searchlist').html(html);return false;
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = val['title']
+'<p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
searchFinish();
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');},
error:function(){$('#searchlist').html('');Alert('检索中发现错误,请稍后重试或直接访问');}
});
}
function bingSearch(keyword){
$.ajax({type:"POST",url:"/service/bingsearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if($.isArray(obj.SearchResponse.Web))
{
if(obj.SearchResponse.Web.Total==0)
{
$('#searchlist').html("No results!");
return false;
}
$.each(obj.SearchResponse.Web.Results, function(key, val) {
var html = '<p><a href="' +val['Url']+'">'+val['Title']+'<a/></p><p><span>'
+val['DisplayUrl'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['Description']
+'</p>';
items.push('<li>' + html + '</li>');
});
items.push('<li class="more"><a href="http://cn.bing.com/search?q='+encodeURIComponent(keyword)+
'&go=&qs=n&sk=&form=QBLH" target="_blank">查看更多搜索结果(约'+obj.SearchResponse.Web.Total+'条)</a></div>');
}else{
Alert('暂无搜索结果');$('#searchlist').html('');
}
$('#searchlist').html(items.join(''));
searchFinish();
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');},
error:function(){$('#searchlist').html('');Alert('检索中发现错误,请稍后重试或直接访问');}
});
}
function cnkiSearch(keyword){
$.ajax({type:"POST",url:"/service/cnkisearch",data:'q='+keyword,
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}else{
$.each(obj.result, function(key, val) {
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'</a></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
searchFinish()
},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');},
error:function(){Alert('检索中发现错误,请稍后重试或直接访问');$('#searchlist').html('');}
});
}
function searchFinish()
{
$('html, body').animate({scrollTop:$('#gsearch_t').offset().top}, 'slow');
}
function dataVersion(uuid)
{
$.ajax({
'type':"POST",
'url':'/data/getversion',
'data':'ac=list&uuid='+uuid,
'success':onDataVersionLoad,
'timeout': 30000,
'error': function(){Alert('处理中出现错误,请刷新页面后重试');return false;}
});
}
function onDataVersionLoad(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{Alert(data.error);return false;}
if(typeof(data.list)!='undefined')
{
var html = "";
for(v in data.list)
{
html+='<li><p>'+data.list[v].changelog+'</p><p>'+data.list[v].ts_created+' by '+data.list[v].username+'</p></li>';
}
$.colorbox({'innerWidth':'50%','innerHeight':'80%','html':'<div class="datalist"><ul>'+html+'</ul></div>'});
}
}
else{
Alert('出现错误,请稍后再试');return false;
}
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4 style="font-size:16px;font-weight:bold;">'+html+'</h4>'});
}