Svenskt biografisktlexikon

Fills a select box with all women connected to SBL

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/[email protected]/animate.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<h2>Integration with Wikipedia: Svenskt biografisktlexikon<br />
Prototype to test searching in Wikipedia about people presented in "Svenskt biografisktlexikon" <a href="https://www.wikidata.org/wiki/Property_talk:P3217" target=_blank>P3217</a>
</h2>
<div id="explain">
What knows Swedish Wikipedia about those people? <br />
Below all persons at "Svenskt biografisktlexikon" that Wikidata knows about are presented in the listbox. When selecting one 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 /></b>See also<br /><br />
<ll class="list">
  <li>Same for <a target=_blank href="https://jsfiddle.net/salgo60/2qut3yxj/embedded/result/">Swedish Church parishes in Wikidata</a> and for <a target=_blank href=" https://jsfiddle.net/salgo60/wkrug0bL/embedded/result/"">SKBL</a></li>
  <li><a target=_blank href="http://minancestry.blogspot.se/2017/05/sbl-wikidata.html">Blog SBL Svenskt biografiskt lexikon - Wikidata</a></li>
  <li><a target=_blank href="https://goo.gl/gErSTW">Statistics sv:Wikipedia</a> -  +22 000 views/day
  </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 value="da">Danish</option>
  <option value="fi">Finland</option>
  <option value="it">Italy</option>
  <option value="ru">Russian</option>
  <option value="eo">Esperanto</option>
  <option value="ja">Japan</option>
  <option value="zh">China</option>
  <option...

CSS

/* Start by setting display:none to make this hidden.
   Then we position it in relation to the viewport window
   with position:fixed. Width, height, top and left speak
   speak for themselves. Background we set to 80% white with
   our animation centered, and no-repeating */
.modal {
    display:    none;
    position:   fixed;
    z-index:    1000;
    top:        0;
    left:       0;
    height:     100%;
    width:      100%;
    background: rgba( 255, 255, 255, .8 ) 
                url('http://sampsonresume.com/labs/pIkfp.gif') 
                50% 50% 
                no-repeat;
}

/* When the body has the loading class, we turn
   the scrollbar off with overflow:hidden */
body.loading {
    overflow: hidden;   
}

/* Anytime the body has the loading class, our
   modal element will be visible */
body.loading .modal {
    display: block;
}

 body {
   color: #444;
   background: #BBD2C5;
   /* fallback for old browsers */
   background: -webkit-linear-gradient(to left, #536976, #BBD2C5);
   /* Chrome 10-25, Safari 5.1-6 */
   background: linear-gradient(to left, #536976, #BBD2C5);
   /* 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;
 }
#URL {
   margin-top: 20px;
   padding: 0 5%;
   color: white;
}

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


#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:...

JavaScript

$body = $("body");https://jsfiddle.net/salgo60/wkdcz4h2/209/#

$(document).on({
    ajaxStart: function() { $body.addClass("loading");    },
    ajaxStop: function() { $body.removeClass("loading"); }    
});

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

 $.event.trigger("ajaxStart");
 console.log("Trigger Ajax Start")
	var query = 'SELECT ?itemLabel WHERE {    ?item wdt:P31 wd:Q5.   ?item wdt:P3217 ?SBL.   SERVICE wikibase:label { bd:serviceParam wikibase:language "sv","en" } } ORDER BY ?itemLabel limit 10000'; // finds SBL related people

	var api = new wikibase.queryService.api.Sparql();
	api.query(query).done(function() {
 					var nrHits = api.getResultRawData().results.bindings.length;
  		$("#Hits").html("SBL people in the listbox = " + nrHits + " <div data-wow-duration='6s' data-wow-offset='10' class='wow bounceInUp more'>Select a person</div>");   	$.each(api.getResultRawData().results.bindings, function(key, value) {
  		$('.SBLList').append($('<option/>').text(value.itemLabel.value));
  	});
	});  
});

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

  });
	$( '.SBLList' ).change(function() {       
    var input = $('.SBLList').val();
    var srcopt = '&srqiprofile=classic';
    
//		srcopt = '&srqiprofile=' + $('.searchOptionList').val();
//    $("#URL").html(srcopt);
		var searchLimit = 400 // number of results in search 
    var url = `https://sv.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...