forked from gdcc/dataverse-previewers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 23_RO-Crate_previewer
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title class="htmlPreviewText">Html Preview</title> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | ||
<script type="text/javascript" src="js/xss.js"></script> | ||
<script type="text/javascript" src="js/richhtml.js"></script> | ||
<script src="lib/jquery.i18n.js"></script> | ||
<script src="lib/jquery.i18n.messagestore.js"></script> | ||
<script src="lib/jquery.i18n.language.js"></script> | ||
<script type="text/javascript" src="js/retriever.js"></script> | ||
<!-- Latest compiled and minified CSS --> | ||
<link | ||
rel="stylesheet" | ||
href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" | ||
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" | ||
crossorigin="anonymous" | ||
/> | ||
<!-- Optional theme --> | ||
<link | ||
rel="stylesheet" | ||
href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" | ||
integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" | ||
crossorigin="anonymous" | ||
/> | ||
<link type="text/css" rel="stylesheet" href="css/preview.css" /> | ||
</head> | ||
|
||
<body class="container"> | ||
<main> | ||
<img id="logo" alt="Site Logo" /> | ||
<h1 class="page-title htmlPreviewText">Insecure Html Preview</h1> | ||
<div class="preview-container"> | ||
<div class="preview-header"></div> | ||
<div class="preview"></div> | ||
</div> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
$(document).ready(function () { | ||
|
||
const MESSAGE = $.i18n("richHtmlPreviewText") | ||
userConfirms = confirm(MESSAGE) | ||
|
||
if (userConfirms) { | ||
// Preview the HTML file | ||
startPreview(true); | ||
} else { | ||
// Redirect to the file page | ||
queryParams = new URLSearchParams(window.location.search.substring(1)); | ||
var siteUrl = queryParams.get("siteUrl"); | ||
var fileID = queryParams.get("fileid"); | ||
var versionUrl = siteUrl + "/api/datasets/" | ||
+ queryParams.get("datasetid") + "/versions/" | ||
+ queryParams.get("datasetversion"); | ||
|
||
fetchMetaAndRedirect(versionUrl, fileID, siteUrl); | ||
} | ||
}); | ||
|
||
function fetchMetaAndRedirect(versionURL, fileID, siteUrl) { | ||
$.ajax({ | ||
type: 'GET', | ||
dataType: "json", | ||
crosssite: true, | ||
url: versionURL, | ||
success: function (data, status) { | ||
console.log(data); | ||
redirectToFilePage(data, siteUrl, fileID); | ||
}, | ||
error: function (request, status, error) { | ||
alert("Could not find persistent ID for file. Redirecting to the Dataverse page.") | ||
window.location.replace(siteUrl); | ||
} | ||
}); | ||
} | ||
|
||
function redirectToFilePage(data, siteUrl, fileID) { | ||
// Search for the file ID in the JSON | ||
const files = data.data.files | ||
const persistentFile = files.find(file => file.dataFile.id == fileID) | ||
const persistentFileId = persistentFile.dataFile.persistentId | ||
const fileVersion = persistentFile.version | ||
|
||
// Redirect to the file page | ||
const fileUrl = siteUrl + "/file.xhtml?persistentId=" + persistentFileId + "&version=" + fileVersion | ||
window.location.replace(fileUrl); | ||
} | ||
|
||
function translateBaseHtmlPage() { | ||
var htmlPreviewText = $.i18n("htmlPreviewText"); | ||
$('.htmlPreviewText').text(htmlPreviewText); | ||
} | ||
|
||
function writeContentAndData(data, fileUrl, file, title, authors) { | ||
addStandardPreviewHeader(file, title, authors); | ||
options = { | ||
"stripIgnoreTag": true, | ||
}; // Custom rules | ||
|
||
$('.preview').append($("<div/>").html(data)); | ||
} |