utilities.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //INIZIO PREPARAZIOEN QUERY
  2. // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  3. thisUrlParams = {};
  4. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  5. thisUrlParams[key] = value;
  6. });
  7. console.log('URL get params: ', thisUrlParams.params);
  8. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. function doJsonQuery(query) {
  14. queryURL = prepareQueryURL(query);
  15. return $.ajax({
  16. url: queryURL,
  17. dataType: "json",
  18. type: 'GET'
  19. });
  20. }
  21. // Funzioni per raccattare + stringhificare l'output
  22. queryStringOutput = "";
  23. function stringifyResponse(val){
  24. resultArray = val['results']['bindings'];
  25. out = "";
  26. for(i = 0; i < resultArray.length; i++){
  27. out = out + JSON.stringify(resultArray[i])
  28. }
  29. queryStringOutput = (queryStringOutput + out).replace("}{",",");
  30. }
  31. //FINE PREPARAZIONE QUERY
  32. $(document).on("click", ".luogo", function (ev) {
  33. var link = this.id;
  34. window.open("Luogo.html?link="+this.id, "_self");
  35. });
  36. $(document).on("click", ".persona", function (ev) {
  37. var link = this.id;
  38. window.open("Persona.html?link="+this.id, "_self");
  39. });
  40. $(document).on("click", ".lettera", function (ev) {
  41. var link = this.id;
  42. window.open("lettera.html?link="+this.id, "_self");
  43. });
  44. $(document).on("click", ".object", function (ev) {
  45. var link = this.id;
  46. window.open("object.html?link="+this.id, "_self");
  47. });
  48. $(document).on("click", ".artwork", function (ev) {
  49. var link = this.id;
  50. window.open("OA.html?link="+this.id, "_self");
  51. });
  52. function schedaASPO(info){
  53. window.open(info);
  54. }
  55. $(document).on("click", ".hyp", function (ev) {
  56. var baseurl = window.location.origin+window.location.pathname;
  57. let slash = baseurl.lastIndexOf("/");
  58. var type = $(this).val() + '.html';
  59. var link = this.id;
  60. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  61. var link = this.id;
  62. $("#myModal").empty();
  63. $("#myModal").css("display", "block");
  64. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  65. url + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  66. });
  67. $(document).on("click", ".close", function (ev) {
  68. var link = this.id;
  69. $("#myModal").css("display", "none");
  70. });
  71. $(document).on("click", ".back", function (ev) {
  72. $("#myTab").css("display", "none");
  73. });
  74. function changeStyle() {
  75. var element = document.getElementById("glass");
  76. element.classList.toggle("img-magnifier-glass");
  77. }
  78. $(document).on("click", ".zoomImg", function (ev) {
  79. if (!!document.getElementById("glass")) {
  80. destroyMagnifier();
  81. } else {
  82. createMagnifier("expandedImg", 3);
  83. }
  84. });
  85. $(document).on("click", ".cit", function (ev) {
  86. var author ="RESTORE. smart access to digital heritage and memory"
  87. var year = new Date().getFullYear()
  88. var today = new Date();
  89. var dd = String(today.getDate()).padStart(2, '0');
  90. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  91. var yyyy = today.getFullYear();
  92. today = dd + '/' + mm + '/' + yyyy;
  93. var baseurl = window.location.origin+window.location.pathname;
  94. let slash = baseurl.lastIndexOf("/");
  95. var type = $(this).val() + '.html';
  96. var link = this.id;
  97. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  98. //alert(nome_autore);
  99. //$('#myModal').text("");
  100. $("#myModal").empty();
  101. $("#myModal").css("display", "block");
  102. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  103. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  104. });
  105. function titleCase(str) {
  106. var splitStr = str.toLowerCase().split(' ');
  107. for (var i = 0; i < splitStr.length; i++) {
  108. // You do not need to check if i is larger than splitStr length, as your for does that for you
  109. // Assign it back to the array
  110. splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
  111. }
  112. // Directly return the joined string
  113. new_str = splitStr.join(' ');
  114. finalString = new_str.replaceAll(" Di ", " di ").replace(" Moglie ", " moglie ")
  115. return finalString;
  116. }
  117. function copyToClipboard(text) {
  118. var sampleTextarea = document.createElement("textarea");
  119. document.body.appendChild(sampleTextarea);
  120. sampleTextarea.value = text; //save main text in it
  121. sampleTextarea.select(); //select textarea contenrs
  122. document.execCommand("copy");
  123. document.body.removeChild(sampleTextarea);
  124. }
  125. function myFunction(){
  126. var copy = document.getElementById("myInput");
  127. copyText = copy.textContent;
  128. copyToClipboard(copyText);
  129. //copyToClipboard(copyText.value);
  130. }
  131. function expandImg(imgs) {
  132. var expandImg = document.getElementById("expandedImg");
  133. var imgText = document.getElementById("imgtext");
  134. expandImg.src = imgs.src;
  135. imgText.innerHTML = imgs.alt;
  136. expandImg.parentElement.style.display = "block";
  137. }
  138. function toggleNews(id) {
  139. $( "#" + id + " .newsText" ).toggle( "slow", function() {
  140. });
  141. }
  142. var myIndex = 0;
  143. //slide();
  144. function slide() {
  145. var i;
  146. var x = document.getElementsByClassName("slide");
  147. for (i = 0; i < x.length; i++) {
  148. x[i].style.display = "none";
  149. }
  150. myIndex++;
  151. if (myIndex > x.length) {myIndex = 1}
  152. x[myIndex-1].style.display = "block";
  153. setTimeout(slide, 12000);
  154. }
  155. function runOpenseadragon(tiles) {
  156. console.log(tiles);
  157. var viewer = OpenSeadragon({
  158. id: "contentDiv",
  159. prefixUrl: "https://cdn.jsdelivr.net/npm/openseadragon/build/openseadragon/images/",
  160. maxZoomPixelRatio: 3,
  161. toolbar: "toolbarDiv",
  162. springStiffness: 10,
  163. sequenceMode: true,
  164. showReferenceStrip: true,
  165. autoHideControls: false,
  166. tileSources: tiles,
  167. });
  168. }