Riksarkivet TORA

Fills a select box with locations in TORA

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: Riksarkivet TORA <a href="https://www.wikidata.org/wiki/Property_talk:P4820" target=_blank>P4820</a><br />
Prototype to test searching in Wikipedia about locations presented at "Riksarkivet TORA"</h2>
<div id="explain">
What knows Swedish Wikipedia about those locations? <br />
Below all locations in TORA that Wikidata knows about are presented in the listbox. When selecting a location 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 />
<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/0pdaymko/embedded/result/">National museum</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</a>, <a target=blank href="https://jsfiddle.net/salgo60/2wt63e8L/embedded/result/">Swedish socknar</a>, <a target=blank href="https://jsfiddle.net/salgo60/2wt63e8L/embedded/result/">test Bygdeband</a></li><li><a href="https://www.mediawiki.org/wiki/API:Search">API:Search</a></li>
  <li><a...

CSS

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

JavaScript

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


	var query = 'SELECT ?itemLabel WHERE {    ?item wdt:P4820 ?TORAid. SERVICE wikibase:label { bd:serviceParam wikibase:language "sv","en" } } ORDER BY ?itemLabel'; // finds TORA related people

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

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

  });
	$( '.TORAList' ).change(function() {       
    var input = $('.TORAList').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 parameter </p>
            </div>
          `
          $("#output").html(notFound);
          $("#not-found").delay(5000).fadeOut(500);
          		$("#Hits").html("");    			
        } else {
          let output = "";
          let numberofHits = "Number of hits in Swedish Wikipedia = " +...