WD Laureate version 2

Fills a select box with values from the query service

by Magnus Sälgö

HTML

<script src="https://cdn.rawgit.com/wikimedia/wikidata-query-gui/master/wikibase/queryService/api/Sparql.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.5.2/animate.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<h2>Integration with Wikipedia:<br />
Prototype to test searching Nobel API <a href="https://nobelprize.readme.io/docs/laureate" target=_blank>laureate</a> version 2
</h2>
see <a href="https://phabricator.wikimedia.org/T234889" target="_blank">T234889</a> -  <a href="http://jsfiddle.net/salgo60/80uc7dav/embedded/result" target="_blank">version 1.0 API</a><br /><br />
<div id="explain">
What knows different language Wikipedia about laureate? <br /><br />
Below all laureate  at Nobelprize.org . When selecting one prize winner a Wikipedia search is done... lesson learned is 
<ul>
<li>that we write a lot about Nobel prize winners but using text retrieval is not a good way to get good precision</li><li>a tool like <a href="https://www.mediawiki.org/wiki/Extension:ArticlePlaceholder" target=_blank>Article Placeholder</a> could be very helpful for small Wikipedia languages to get "articles" about  all Nobel prize winners</li>
</ul>if you have questions dont hesitate to contact Magnus Sälgö +46-70-5937579, <a href="https://twitter.com/salgo60" target=_blank>twitter</a></div>  <br />See also
<table border=0 width=800px><tr><td><ll class="list">
  <li><a href="https://www.mediawiki.org/wiki/API:Search">API:Search</a></li>
<li><a target=_blank href="https://jsfiddle.net/salgo60/wkrug0bL/embedded/result/">Same but for SKBL</a>, <a target=_blank href="https://jsfiddle.net/salgo60/2qut3yxj/embedded/result/">Swedish Church parishes</a>, <a target=_blank href="https://jsfiddle.net/salgo60/0pdaymko/embedded/result/">National museum</a>, <a target=_blank href="https://jsfiddle.net/salgo60/gL6o3eyq/embedded/result/">TORA</a>, <a target=_blank...

CSS

body {
   color: #444;
   background: #e2ffff;
   /* fallback for old browsers */
   background: -webkit-linear-gradient(to left, #9ab800, #e2ffff);
   /* Chrome 10-25, Safari 5.1-6 */
   background: linear-gradient(to left, #9ab800, #e2ffff);
   /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
   font-family: 'Dosis', sans-serif;
   background-repeat: no-repeat;
   background-size: cover;
   min-height: 100vh;
   font-size: 16px;
 }

 a {
   color: #444;
   cursor: pointer;
 }

 a:hover {
   color: #555;
   text-decoration: none;
 }
#URLNobel #URL {
   margin-top: 20px;
   padding: 0 5%;
   color: darkblue;
}

#Hits {
   margin-top: 20px;
   padding: 0 5%;
   color: #437746;
   font-size: 30px;
}

.more {
   color: darkgreen;
} 
#output {
   margin-top: 40px;
   padding: 0 5%;
 }

 
.list a {
  text-decoration: none;
}
 
li a:hover {
  background: lightgreen;
}

h2 a:hover {
  background: lightgreen;
}


 #text {
   padding: 10px 20px;
   border-top-left-radius: 30px;
   border-bottom-left-radius: 30px;
   border: 0px solid;
   width: 50%;
 }

 #text:focus {
   box-shadow: 1px 3px 40px 5px #536970;
   outline: none;
 }
 #not-found p {
   font-size: 20px;
  }

.result {
  padding: 0.5% 2%;
  background: #fff;
  margin: 1.5%;
  border-left: 7px solid #536976;
}

.result h2 {
  color: #536976;
}
  

 button {
   background: #536976;
   color: #fff;
   padding: 10px 20px;
   border: 1px solid #536976;
   border-radius: 30px;
   margin-left: -55px;
 }


 .currLaureate{
    background-color: aliceblue;
    margin: 8px;
    size: 12px;
    border-radius: 25px;
    border: 2px solid darkBlue;
    padding: 20px; 
    width: 500px;
    height:150px;    
 }

.searchmatch{
      color: #a0ccd2;
}
#explain
{
     color: darkgreen;
     font-family: "Times New Roman", Times, serif;     
}

JavaScript

$(function() {
	new WOW().init();
  let laurentApiURL ="https://api.nobelprize.org/2.0/laureates?limit=2000"
  console.log(laurentApiURL);
            $("#URLNobel").html('<b<b>API call Nobel:</b> <a href="' + laurentApiURL + '" target=_blank>' + laurentApiURL + '</a>');


   $.ajax({
      type: "GET",
      url: laurentApiURL,
      dataType: "json",
      success: function(data) {
				console.log("Done");
        let laurentInfo = data.laureates;
        var nrHits = laurentInfo.length;
				console.log(nrHits);
        console.log(laurentInfo);
 
		$("#Hits").html("We retrieved from NobelPrize.org " + nrHits + " records. Please <div data-wow-duration='6s' data-wow-offset='10' class='wow bounceInUp more'>select an Laureate</div>");   
        $.each(laurentInfo, (i, val) => {
          if (typeof val.fullName !== "undefined") {
          	fullname = val.fullName.en || ''}
            else {
            	if (typeof val.orgName !== "undefined"){
              fullname = val.orgName.en || ''
              }
            }
          year = val.nobelPrizes[0].awardYear || ''
          category = val.nobelPrizes[0].category.en || ''
	        nameFull = fullname + " - " + year + ": " + category 
	        if (nameFull.length > 7) // workaround as API returns garbage 
// https://phabricator.wikimedia.org/T206444 Error reported
          	{$('.laureateList').append($('<option/>').text(nameFull).val(fullname));}
        }
      )
	}});
	console.log("After");

 });


	$( '.searchOptionList' ).change(function() {       
    var srcopt = '&srqiprofile=' + $('.searchOptionList').val();
    $("#URL").html(srcopt);

  });

	$( '.wikiLang' ).change(function() {       
		retrieveWiki();
  });


	$( '.laureateList' ).change(function() {       
		retrieveWiki();
	});
  
	$( '.searchOptionList' ).change(function() {       
		retrieveWiki();
	});
 

  function retrieveWiki(){
    var input = $('.laureateList').val();
    //var srcopt = '&srqiprofile=classic';
    var srcopt =...