Swedish National museum

Fills a select box from Natmus

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>
<div id="explain">
<h3>Integration with Wikipedia: Swedish National museum <a href="https://www.wikidata.org/wiki/Property_talk:P2538" target=_blank>P2538</a></h3>
Prototype to test searching in Wikipedia people presented at "Swedish National museum" 
<br>What knows Swedish Wikipedia about those people? When selecting one person a Wikipedia search is done and the result is displayed as "snippets" ==> the search engine explains why this Wikipedia article is of interest...if you have questions dont hesitate to contact Magnus Sälgö +46-70-5937579</div> <br />See also<br /><br />
<ll class="list"><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/2wt63e8L/embedded/result/">Swedish "socknar"</a>, <a target=_blank href="https://jsfiddle.net/salgo60/gL6o3eyq/embedded/result/">TORA</a>, <a target=_blank href="https://jsfiddle.net/salgo60/oxtuy9rL/embedded/result/">Litteraturbanken/The Swedish Litterature Bank</a>, <a target=blank href="https://jsfiddle.net/salgo60/7etq6rmu/embedded/result/">SBL</a>, <a target=blank href="https://jsfiddle.net/salgo60/4eqgarbj/embedded/result/">Smithsonian</li>
<li><a href="https://www.mediawiki.org/wiki/API:Search">API:Search</a></li>
  <li><a href="https://www.mediawiki.org/wiki/Page_Previews">Page Previews</a></li>
</ll><br /><br />
<select class="wikiLang">
  <option value="sv">Swedish</option>
  <option value="en">English</option>
  <option value="de">German</option>
  <option value="no">Norway</option>
  <option...

CSS

body {
   color: #444;
   background: #BBD2C5;
   /* fallback for old browsers */
   background: -webkit-linear-gradient(to left, #006976, #FFD2C5);
   /* Chrome 10-25, Safari 5.1-6 */
   background: linear-gradient(to left, #006976, #FFD2C5);
   /* 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;
 }

#Hits {
   margin-top: 10px;
   padding: 0 5%;
   color: white;
   font-size: 34px;
}


#output {
   margin-top: 40px;
   padding: 0 5%;
 }

 
.list a {
  text-decoration: none;
}
 
li 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;
 }


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

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

.explain2
{
     color: darkgreen;
     font-size: 16px;
     font-family: "Times New Roman", Times, serif;     
}
.more {
   color: darkgreen;
} 
#URL {
   margin-top: 20px;
   padding: 0 5%;
   color: darkblue;
}

JavaScript

$(function() {
	new WOW().init();


	var query = 'SELECT ?itemLabel WHERE { ?item wdt:P31 wd:Q5. ?item wdt:P2538 ?NatMus. SERVICE wikibase:label { bd:serviceParam wikibase:language "sv","en" } } ORDER BY  ?itemLabel '; // finds SKBL related people

	var api = new wikibase.queryService.api.Sparql();
	api.query(query).done(function() {
	  	var nrHits = api.getResultRawData().results.bindings.length;

  		$("#Hits").html("Artists in the listbox = " + nrHits + " <div data-wow-duration='6s' data-wow-offset='10' class='wow bounceInUp more'>Select an artist</div>");   
 			$.each(api.getResultRawData().results.bindings, function(key, value) {
  		$('.SKBLList').append($('<option/>').text(value.itemLabel.value));
  	});
	});
});

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


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


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

    var searchLimit = 400 // number of results in search 
    var url = `https://`  + wikiLang + `.wikipedia.org/w/api.php?action=query&list=search&srsearch=` + input + `&srlimit=` + searchLimit + `&format=json&prop=info&inprop=url` + srcopt;

    $.ajax({
      type: "GET",
      url: url,
      dataType: "jsonp",
      success: function(data) {
        let info = data.query.search;
        console.log(info);

        if (info.length === 0) {
          let notFound = "";
          notFound += `
            <div id="not-found" class="wow fadeIn text-center" data-wow-duration="0.5s">
              <p> No result for parameter </p>
            </div>
          `
          $("#output").html(notFound);
          $("#not-found").delay(5000).fadeOut(500);
        } else {
          let output = "";
          let numberofHits = "Number of hits in " + wikiLang + " Wikipedia = " + info.length + " <div data-wow-duration='6s' data-wow-offset='10' class='wow bounceInUp...