Skip to content

Commit

Permalink
ro-crate previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
ErykKul committed Sep 29, 2023
1 parent 45be6fb commit 5a077d7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
17 changes: 15 additions & 2 deletions previewers/betatest/ROCrate.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<title class="rocratePreviewText">RO-Crate 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/ro-crate-dynamic.js"></script>
<script type="text/javascript" src="js/rocrate.js"></script>
<script src="lib/jquery.i18n.js"></script>
<script src="lib/jquery.i18n.messagestore.js"></script>
Expand All @@ -17,15 +16,29 @@
<!-- 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 rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link type="text/css" rel="stylesheet" href="css/preview.css" />
<style>
table.table {
padding-bottom: 300px;
}
</style>

<script type="application/ld+json"></script>
</head>

<body class="container">
<main><img id='logo' alt='Site Logo'>
<h1 class="page-title rocratePreviewText">RO-Crate Preview</h1>
<div class='preview-container'>
<div class='preview-header'></div>
<div class='preview'></div>
<div class='preview'>
<div class="jumbotron">
<div id="check"></div>
</div>
<div id="summary"></div>
</div>
</div>
</main>
</body>
Expand Down
43 changes: 43 additions & 0 deletions previewers/betatest/js/ro-crate-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,49 @@ async function check() {
document.getElementById("check").innerHTML = `<details><summary>${checker.summarize()}</summary><a href='#___check___'><pre>${checker.report()}</pre></a></details>`;
};

async function load() {
if (!meta) {
meta = new ROCrate(
JSON.parse(document.querySelector('script[type="application/ld+json"]').innerHTML)
);
preview = await new Preview(meta, config);
meta.resolveContext().then(function () {updatePage()}); // This is async
}
var css = document.createElement('style');
css.type = 'text/css';
var styles = 'summary { display: list-item; }';
css.appendChild(document.createTextNode(styles));

document.getElementsByTagName("head")[0].appendChild(css);


document.getElementsByTagName("body").append
document.getElementById("check").innerHTML = "<button><a href='#___check___'>Check this crate</a></button>";
updatePage();
}

window.onhashchange = function () {
load();
};

window.onload = function () {
load();
};



async function updatePage() {
var hash = location.hash;

if (hash.startsWith("#___check")) {
check();
} else if (hash) {
await preview.display(unescape(hash.replace("#", "")));
} else {
await preview.display(preview.root["@id"]);
}
}

},{"./ro-crate-preview":4,"chai":33,"ro-crate":70}],3:[function(require,module,exports){
/*

Expand Down
10 changes: 2 additions & 8 deletions previewers/betatest/js/rocrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ function translateBaseHtmlPage() {

async function writeContentAndData(data, fileUrl, file, title, authors) {
addStandardPreviewHeader(file, title, authors);

json = JSON.parse(data);
const crate = new ROCrate(json);
const preview = new Preview(crate);
const id = "RO-Crate_preview";
const html = await this.renderMetadataForItem();

$('.preview').append($("<div id=\"" + id +"\"/>").html(html));
$('.preview').append($("<script type=\"application/ld+json\"/>").value(data));
$('.preview').append($("<script type=\"text/javascript\" src=\"js/ro-crate-dynamic.js\"/>"));
}

0 comments on commit 5a077d7

Please sign in to comment.