-
Notifications
You must be signed in to change notification settings - Fork 1
/
ads_query_importer_widget.js
37 lines (34 loc) · 10.7 KB
/
ads_query_importer_widget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Copyright (C) 2011, The SAO/NASA Astrophysics Data System
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var ADS_WIDGET_SERVER_URL="http://adsabs.harvard.edu/query_importer_widget",ADS_WIDGET_PARAMETERS={ads_query_back_base_url:"http://adsabs.harvard.edu",ads_query_title:null,ads_query_highlight_author:null,ads_query_max_num_authors:1,ads_query_max_records_to_print:null,ads_query_omit_bibcode:false,ads_query_omit_authors:false,ads_query_omit_title:false,ads_query_omit_journal:false,ads_query_omit_date:false,ads_query_omit_link_to_ads:false,ads_query_link_on_field:"bibcode",ads_query_print_order:"bibcode|title|authors|journal|date"},
ADS_WIDGET_VALID_FIELDS={bibcode:true,title:true,authors:true,journal:true,date:true},ADS_WIDGET_VALID_ADS_SERVERS={"http://adsabs.harvard.edu":true,"http://cdsads.u-strasbg.fr":true,"http://ukads.nottingham.ac.uk":true,"http://esoads.eso.org":true,"http://ads.ari.uni-heidelberg.de":true,"http://ads.inasan.ru":true,"http://ads.mao.kiev.ua":true,"http://ads.astro.puc.cl":true,"http://ads.nao.ac.jp":true,"http://ads.bao.ac.cn":true,"http://ads.iucaa.ernet.in":true,"http://ads.arsip.lipi.go.id":true,
"http://saaoads.chpc.ac.za":true,"http://ads.on.br":true};function ads_widget_complete_url(a){if(a.length==0)return a;/^(https?|ftp):\/\//i.test(a)||(a="http://"+a);return a}
function ads_widget_is_valid_url(a){return a.length==0?false:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(a)}
function ads_widget_parse_user_paramenters(){if(typeof ads_query_back_base_url!=="undefined"&&ads_widget_is_valid_url(ads_query_back_base_url))ads_query_back_base_url.substring(ads_query_back_base_url.length-1,ads_query_back_base_url.length)=="/"&&(ads_query_back_base_url=ads_query_back_base_url.substring(0,ads_query_back_base_url.length-1)),ADS_WIDGET_VALID_ADS_SERVERS[ads_query_back_base_url]&&(ADS_WIDGET_PARAMETERS.ads_query_back_base_url=ads_query_back_base_url);typeof ads_query_title!=="undefined"&&
(ADS_WIDGET_PARAMETERS.ads_query_title=ads_query_title);typeof ads_query_highlight_author!=="undefined"&&(ADS_WIDGET_PARAMETERS.ads_query_highlight_author=ads_query_highlight_author);typeof ads_query_max_num_authors!=="undefined"&&(ADS_WIDGET_PARAMETERS.ads_query_max_num_authors=typeof ads_query_max_num_authors!=="number"?parseInt(ads_query_max_num_authors):ads_query_max_num_authors);typeof ads_query_max_records_to_print!=="undefined"&&(ADS_WIDGET_PARAMETERS.ads_query_max_records_to_print=typeof ads_query_max_records_to_print!==
"number"?parseInt(ads_query_max_records_to_print):ads_query_max_records_to_print);typeof ads_query_omit_bibcode!=="undefined"&&typeof ads_query_omit_bibcode==="boolean"&&(ADS_WIDGET_PARAMETERS.ads_query_omit_bibcode=ads_query_omit_bibcode);typeof ads_query_omit_authors!=="undefined"&&typeof ads_query_omit_authors==="boolean"&&(ADS_WIDGET_PARAMETERS.ads_query_omit_authors=ads_query_omit_authors);typeof ads_query_omit_title!=="undefined"&&typeof ads_query_omit_title==="boolean"&&(ADS_WIDGET_PARAMETERS.ads_query_omit_title=
ads_query_omit_title);typeof ads_query_omit_journal!=="undefined"&&typeof ads_query_omit_journal==="boolean"&&(ADS_WIDGET_PARAMETERS.ads_query_omit_journal=ads_query_omit_journal);typeof ads_query_omit_date!=="undefined"&&typeof ads_query_omit_date==="boolean"&&(ADS_WIDGET_PARAMETERS.ads_query_omit_date=ads_query_omit_date);typeof ads_query_omit_link_to_ads!=="undefined"&&typeof ads_query_omit_link_to_ads==="boolean"&&(ADS_WIDGET_PARAMETERS.ads_query_omit_link_to_ads=ads_query_omit_link_to_ads);typeof ads_query_link_on_field!==
"undefined"&&ADS_WIDGET_VALID_FIELDS[ads_query_link_on_field]&&(ADS_WIDGET_PARAMETERS.ads_query_link_on_field=ads_query_link_on_field);if(typeof ads_query_print_order!=="undefined"){var a=ads_query_print_order.split("|"),b=true,d;for(d in a)ADS_WIDGET_VALID_FIELDS[a[d]]||(b=false);b&&(ADS_WIDGET_PARAMETERS.ads_query_print_order=ads_query_print_order)}}
$(document).ready(function(){var a=false;$("#ads_query_importer_widget").length||($("body").append('<div id="ads_query_importer_widget"><span class="ads_query_importer_widget-error">ERROR: please create a DIV tag with the id "ads_query_importer_widget"</span></div>'),a=true);if(typeof ads_query_url==="undefined")$("#ads_query_importer_widget").append('<span class="ads_query_importer_widget-error">ERROR: please specify a query to the ADS database!</span>'),a=true;else if(ads_query_url=ads_widget_complete_url(ads_query_url),
ads_widget_is_valid_url(ads_query_url)){var b=false,d;for(d in ADS_WIDGET_VALID_ADS_SERVERS)ads_query_url.indexOf(d)==0&&(b=true);b||($("#ads_query_importer_widget").append('<span class="ads_query_importer_widget-error">ERROR: The URL specified is pointing to any ADS server. Please correct it.</span>'),a=true)}else $("#ads_query_importer_widget").append('<span class="ads_query_importer_widget-error">ERROR: The URL specified is not valid. Please specify a valid one.</span>'),a=true;ads_widget_parse_user_paramenters();
a||(a=$('<script type="text/javascript" src="'+ADS_WIDGET_SERVER_URL+"/?url_to_proxy="+encodeURI(ads_query_url)+'"><\/script>'),$("head").append(a))});
function ads_widget_parse_query_data(){var a=ADS_WIDGET_PARAMETERS.ads_query_print_order.split("|"),b={},d;for(d in a)b[a[d]]=true;a="";ADS_WIDGET_PARAMETERS.ads_query_title!==null&&(a+='<span class="ads_query_importer_widget-result-list-title">'+ADS_WIDGET_PARAMETERS.ads_query_title+"</span>\n");if(ads_query_importer_widget_query_result.retrieved==0)a+="<h3>No record selected with the specified ADS query.</h3>\n";else{a+='<ul class="ads_query_importer_widget-result-list">\n';d=ads_query_importer_widget_query_result.records;
for(r in d){if(ADS_WIDGET_PARAMETERS.ads_query_max_records_to_print!==null&&r>=ADS_WIDGET_PARAMETERS.ads_query_max_records_to_print)break;var c=d[r],f="";b.bibcode&&ADS_WIDGET_PARAMETERS.ads_query_omit_bibcode!==true&&(f=ads_widget_format_bibcode(c.bibcode));var g="";b.title&&ADS_WIDGET_PARAMETERS.ads_query_omit_title!==true&&(g=ads_widget_format_title(c.title));var h="";b.journal&&ADS_WIDGET_PARAMETERS.ads_query_omit_journal!==true&&(h=ads_widget_format_journal(c.journal));var i="";b.date&&ADS_WIDGET_PARAMETERS.ads_query_omit_date!==
true&&(i=ads_widget_format_date(c.pubdate));var j="";b.authors&&ADS_WIDGET_PARAMETERS.ads_query_omit_authors!==true&&(j=ads_widget_format_authors(c.authors,ADS_WIDGET_PARAMETERS.ads_query_max_num_authors,ADS_WIDGET_PARAMETERS.ads_query_highlight_author));c=ADS_WIDGET_PARAMETERS.ads_query_back_base_url+"/abs/"+encodeURI(c.bibcode);a+="<li>";for(var e in b)e=="bibcode"?a+=ADS_WIDGET_PARAMETERS.ads_query_link_on_field=="bibcode"&&!ADS_WIDGET_PARAMETERS.ads_query_omit_link_to_ads?ads_widget_format_link_to_ads(f,
c):f:e=="title"?a+=ADS_WIDGET_PARAMETERS.ads_query_link_on_field=="title"&&!ADS_WIDGET_PARAMETERS.ads_query_omit_link_to_ads?ads_widget_format_link_to_ads(g,c):g:e=="journal"?a+=ADS_WIDGET_PARAMETERS.ads_query_link_on_field=="journal"&&!ADS_WIDGET_PARAMETERS.ads_query_omit_link_to_ads?ads_widget_format_link_to_ads(h,c):h:e=="date"?a+=ADS_WIDGET_PARAMETERS.ads_query_link_on_field=="date"&&!ADS_WIDGET_PARAMETERS.ads_query_omit_link_to_ads?ads_widget_format_link_to_ads(i,c):i:e=="authors"&&(a+=ADS_WIDGET_PARAMETERS.ads_query_link_on_field==
"authors"&&!ADS_WIDGET_PARAMETERS.ads_query_omit_link_to_ads?ads_widget_format_link_to_ads(j,c):j);a+="</li>\n"}a+="</ul>\n";ADS_WIDGET_PARAMETERS.ads_query_max_records_to_print!==null&&ads_query_importer_widget_query_result.retrieved>ADS_WIDGET_PARAMETERS.ads_query_max_records_to_print&&(a+='<p class="ads_query_importer_widget-result-other-records-not-printed">Other '+(ads_query_importer_widget_query_result.retrieved-ADS_WIDGET_PARAMETERS.ads_query_max_records_to_print)+" records retrieved but not showed.</p>\n");
a+='<p class="ads_query_importer_widget-acknowledgement"> The original query on ADS is available <a href="'+ads_query_url+'" target="_blank">HERE</a>.<br/>Service offered by <a href="http://adsabs.harvard.edu/" target="_blank">The SAO/NASA Astrophysics Data System</a>. </p>'}$("#ads_query_importer_widget").html(a)}function ads_widget_format_bibcode(a){return'<span class="ads_query_importer_widget-result-list-bibcode">'+a+"</span>\n"}
function ads_widget_format_title(a){return'<span class="ads_query_importer_widget-result-list-article-title">'+a+"</span>\n"}function ads_widget_format_journal(a){return'<span class="ads_query_importer_widget-result-list-journal">'+a+"</span>\n"}function ads_widget_format_date(a){return'<span class="ads_query_importer_widget-result-list-date">'+a+"</span>\n"}
function ads_widget_format_authors(a,b,d){auth_html_str='<span class="ads_query_importer_widget-result-list-authors">';num_auth_print=a.length>=b?b:a.length;for(var c=0;c<num_auth_print;c++)auth_html_str+=d!==null&&a[c].toLowerCase().indexOf(d.toLowerCase())==0?'<span class="ads_query_importer_widget-result-list-highlithed-author">'+a[c]+"</span>; ":a[c]+"; ";a.length>b&&(auth_html_str+='<span class="ads_query_importer_widget-result-list-other-authors">and '+(a.length-b)+" coauthors</span>");auth_html_str+=
"</span>\n";return auth_html_str}function ads_widget_format_link_to_ads(a,b){return'<a target="_blank" href="'+b+'" class="ads_query_importer_widget-result-link-to-ads">'+a+"</a>"};