Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js |
— | — | @@ -738,14 +738,41 @@ |
739 | 739 | return value.toLowerCase().substr(0, prefix.length) == prefix.toLowerCase(); |
740 | 740 | } |
741 | 741 | |
| 742 | +function IsNumeric(sText){ |
| 743 | + var ValidChars = "0123456789. "; |
| 744 | + var IsNumber=true; |
| 745 | + var Char; |
| 746 | + |
| 747 | + |
| 748 | + for (i = 0; i < sText.length && IsNumber == true; i++){ |
| 749 | + Char = sText.charAt(i); |
| 750 | + if (ValidChars.indexOf(Char) == -1){ |
| 751 | + IsNumber = false; |
| 752 | + } |
| 753 | + } |
| 754 | + return IsNumber; |
| 755 | +} |
| 756 | + |
| 757 | +function trim(value){ |
| 758 | + value = value.replace(/^\s+/,''); |
| 759 | + value = value.replace(/\s+$/,''); |
| 760 | + return value; |
| 761 | +} |
| 762 | + |
742 | 763 | function urlFieldChanged(urlField) { |
743 | 764 | var labelField = document.getElementById(stripSuffix(urlField.id, "url") + "label"); |
744 | 765 | var url = urlField.value; |
745 | | - |
746 | | -// if (startsWith(url, "http://www.ncbi.nlm.nih.gov")) { |
747 | | -// var pubMedId = 1000; |
748 | | -// labelField.value = getPubMedTitle(pubMedId); |
749 | | -// } |
| 766 | + |
| 767 | + if (startsWith(url, "http://www.ncbi.nlm.nih.gov") ) { |
| 768 | + pubMedIdRec = ExtractText( url, "TermToSearch=", 0, "&ordinalpos", 0 ); |
| 769 | + if ( pubMedIdRec != null ){ |
| 770 | + labelField.value = getPubMedTitle(pubMedIdRec[1]); |
| 771 | + } |
| 772 | + } |
| 773 | + else if ( IsNumeric( url ) ){ |
| 774 | + labelField.value = getPubMedTitle(trim(url)); |
| 775 | + urlField.value = "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=pubmed&Cmd=ShowDetailView&TermToSearch=" + trim(url) + "&ordinalpos=1&itool=EntrezSystem2.PEntrez.Pubmed.Pubmed_ResultsPanel.Pubmed_RVDocSum"; |
| 776 | + } |
750 | 777 | } |
751 | 778 | |
752 | 779 | // Knewco specific Javascript |
— | — | @@ -815,10 +842,10 @@ |
816 | 843 | } |
817 | 844 | |
818 | 845 | xmlhttp.open( "GET", "http://"+ HOST + "/knewco/get.py?http://www.ncbi.nlm.nih.gov/entrez/utils/pmfetch.fcgi?db=PubMed&id="+pmid+"&report=xml&mode=text", false ); |
819 | | - xmlhttp.send(null); |
| 846 | + xmlhttp.send(null); |
820 | 847 | |
821 | 848 | if ( xmlhttp.status == 200){ |
822 | | - AuthorsRec = ExtractText( xmlhttp.responseText, "<AuthorList>", 0, "</AuthorList>", 0 ); |
| 849 | + AuthorsRec = ExtractText( xmlhttp.responseText, "<AuthorList", 0, "</AuthorList>", 0 ); |
823 | 850 | if ( AuthorsRec != null ) { |
824 | 851 | Authors = AuthorsRec[1]; |
825 | 852 | } |
— | — | @@ -829,7 +856,7 @@ |
830 | 857 | var Offset = 0; |
831 | 858 | var AuthorText = ""; |
832 | 859 | while (true) { |
833 | | - AuthorRec = ExtractText( Authors.slice( Offset ), "<Author>", 0, "</Author>", 0 ); |
| 860 | + AuthorRec = ExtractText( Authors.slice( Offset ), "<Author", 0, "</Author>", 0 ); |
834 | 861 | if ( AuthorRec == null ){ |
835 | 862 | break; |
836 | 863 | } |
— | — | @@ -867,10 +894,15 @@ |
868 | 895 | } |
869 | 896 | TitleRec = ExtractText( xmlhttp.responseText, "<ArticleTitle>", 0, "</ArticleTitle>", 0 ); |
870 | 897 | if ( TitleRec != null ){ |
871 | | - return [AuthorText, TitleRec[1]]; |
| 898 | + if ( AuthorText != "" ){ |
| 899 | + return AuthorText + ". " + TitleRec[1]; |
| 900 | + } |
| 901 | + else { |
| 902 | + return TitleRec[1]; |
| 903 | + } |
872 | 904 | } |
873 | 905 | else { |
874 | | - return [AuthorText, "unknown title"]; |
| 906 | + return AuthorText; |
875 | 907 | } |
876 | 908 | } |
877 | 909 | } catch(e){ |