utilities.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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);
  35. });
  36. $(document).on("click", ".persona", function (ev) {
  37. var link = this.id;
  38. window.open("Persona.html?link="+this.id);
  39. });
  40. $(document).on("click", ".lettera", function (ev) {
  41. var link = this.id;
  42. window.open("lettera.html?link="+this.id);
  43. });
  44. $(document).on("click", ".object", function (ev) {
  45. var link = this.id;
  46. window.open("object.html?link="+this.id);
  47. });
  48. $(document).on("click", ".artwork", function (ev) {
  49. var link = this.id;
  50. window.open("OA.html?link="+this.id);
  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. $(document).on("click", ".cit", function (ev) {
  75. var author ="RESTORE. smart access to digital heritage and memory"
  76. var year = new Date().getFullYear()
  77. var today = new Date();
  78. var dd = String(today.getDate()).padStart(2, '0');
  79. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  80. var yyyy = today.getFullYear();
  81. today = dd + '/' + mm + '/' + yyyy;
  82. var baseurl = window.location.origin+window.location.pathname;
  83. let slash = baseurl.lastIndexOf("/");
  84. var type = $(this).val() + '.html';
  85. var link = this.id;
  86. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  87. //alert(nome_autore);
  88. //$('#myModal').text("");
  89. $("#myModal").empty();
  90. $("#myModal").css("display", "block");
  91. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  92. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  93. });
  94. function titleCase(str) {
  95. var splitStr = str.toLowerCase().split(' ');
  96. for (var i = 0; i < splitStr.length; i++) {
  97. // You do not need to check if i is larger than splitStr length, as your for does that for you
  98. // Assign it back to the array
  99. splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
  100. }
  101. // Directly return the joined string
  102. new_str = splitStr.join(' ');
  103. finalString = new_str.replace(" Di ", " di ")
  104. return finalString;
  105. }
  106. function copyToClipboard(text) {
  107. var sampleTextarea = document.createElement("textarea");
  108. document.body.appendChild(sampleTextarea);
  109. sampleTextarea.value = text; //save main text in it
  110. sampleTextarea.select(); //select textarea contenrs
  111. document.execCommand("copy");
  112. document.body.removeChild(sampleTextarea);
  113. }
  114. function myFunction(){
  115. var copy = document.getElementById("myInput");
  116. copyText = copy.textContent;
  117. copyToClipboard(copyText);
  118. //copyToClipboard(copyText.value);
  119. }