-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from IIIF/add_content_state_links
Adding Content State encode
- Loading branch information
Showing
3 changed files
with
41 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{% if include.viewers %} | ||
{% assign viewers = include.viewers | split: "," %} | ||
{% else %} | ||
{% assign viewers = page.viewers %} | ||
{% endif %} | ||
[JSON-LD]({{ include.iiif-content }}) {% for viewerTxt in viewers %}{% assign viewer = viewerTxt | strip %}| {% include viewer_link.html type=viewer manifest=include.iiif-content class="content-state" %}{% endfor %} | ||
|
||
{% if page.code %} | ||
{% include code_links.html %} | ||
{% endif %} | ||
|
||
<script> | ||
function encodeContentState(plainContentState) { | ||
let uriEncoded = encodeURIComponent(plainContentState); // using built in function | ||
let base64 = btoa(uriEncoded); // using built in function | ||
let base64url = base64.replace(/\+/g, "-").replace(/\//g, "_"); | ||
let base64urlNoPadding = base64url.replace(/=/g, ""); | ||
return base64urlNoPadding; | ||
} | ||
|
||
const links = document.getElementsByClassName("content-state"); | ||
|
||
Array.from(links).forEach(link => { | ||
link.title = "Generating iiif-content link...." | ||
fetch(link.dataset.iiifContent).then(response=> { | ||
response.json().then (anno => { | ||
const encoded = encodeContentState(JSON.stringify(anno)); | ||
|
||
if (/iiif-content=.*&/.test(link.href)){ | ||
link.href = link.href.replace(/iiif-content=.*&/, "iiif-content=" + encoded + '&'); | ||
} else { | ||
link.href = link.href.replace(/iiif-content=.*$/, "iiif-content=" + encoded); | ||
} | ||
link.title = ""; | ||
}) | ||
|
||
}); | ||
}); | ||
</script> |
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