Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _includes/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

[0560]: {{ site.cookbook_url | absolute_url }}/recipe/0560-resources-on-a-timeline/ "Rendering Resources Sequentially on a Timeline"
[0561]: {{ site.cookbook_url | absolute_url }}/recipe/0561-text-on-image/ "Visible Text Resource on a Canvas"
[0599]: {{ site.cookbook_url | absolute_url }}/recipe/0599-drag-and-drop/ "Drag and Drop"

[cookbook-process]: {{site.cookbook_url | absolute_url }}/recipe

Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Recipes using [Content State API](https://iiif.io/api/content-state/1.0/)
* [Loading a manifest with a viewer using a link][0466]
* [Open a specific region of a canvas in a viewer][0485]
* [Sharing a link for opening two or more Canvases][0540]

* [Drag and drop][0599]


## Technical
Expand Down
53 changes: 53 additions & 0 deletions recipe/0599-drag-and-drop/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Name of Recipe
id: -1
layout: recipe
tags: [tbc]
summary: "tbc"
viewers:
topic:
- basic
---

## Use Case

As a person wanting to annotate a IIIF resource, you would like to open a manifest in a viewer not present or available in the web interface where you first find the resource.

## Implementation Notes

Implementing this recipe requires a resource provider and a viewer provider each to implement their part. The resource provider must have a draggable item that can have a `dataTransfer.setData` method attached to the item's `dragstart` event and the viewer provider must have an interface capable of handling the data in its `drop` event.

## Restrictions

Because implementation is two-part, you may only have control over one half of the ability to drag and drop. Consequently, and since this action is only in a GUI environment, you will need to consider whether visitors to your IIIF interface would benefit from some kind of support text.

## Example

Describe the solution in prose and provide an example.
The example json document must be an external document, and imported with the following:

{% include manifest_links.html viewers="" manifest="manifest.json" %}

<img src="https://iiif.io/api/cookbook/assets/images/logos/logo-sm.png" draggable="true" ondragstart="drag(event)" alt="IIIF logo; drag and drop onto a supporting viewer to see this resource in that viewer">

<script>
function drag(ev) {
ev.dataTransfer.setData("text/plain", JSON.stringify({
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://example.org/content-states/1",
"type": "Annotation",
"motivation": ["contentState"],
"target": {
"id": "https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json",
"type": "Manifest"
}
}));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing this with my demo site: https://iiif.gdmrdigital.com/import_to_viewers/DragDropDestination.html to see if I could get it working. I had to make an update as you set the data type as text/plain which I think is correct but my app didn't use that value so that should be fixed now.

The other issue I came across is that I think dataTransfer only transfers Strings so when you put the JSON in as the data it converts it to a string of object [object] and you loose the data. I think you need to wrap that in JSON.stringify() to ensure the annotation is converted into a String before passing it .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was starting with the bits from that Slack conversation, so I'm happy to get updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logo image has disappeared

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, when I drag from the recipe in progress I get a strange error in the browser tools:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://newspapers.library.wales/iiif/2.0/image/3412218/info.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 403.
Even though the manifest in the script in the recipe is https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json, not the Wales library one.

</script>

## Related Recipes

Provide a bulleted list of related recipes and why they are relevant.

{% include acronyms.md %}
{% include links.md %}
54 changes: 54 additions & 0 deletions recipe/0599-drag-and-drop/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "{{ id.url }}",
"type": "Manifest",
"label": { "en": [ "Visible Text Annotation" ] },
"items": [
{
"id": "{{ id.path }}/canvas",
"type": "Canvas",
"height": 31722,
"width": 70399,
"items": [
{
"id": "{{ id.path }}/page/p1/1",
"type": "AnnotationPage",
"items": [
{
"id": "{{ id.path }}/annotation/p0001-image",
"type": "Annotation",
"motivation": "painting",
"body": {
"id": "https://iiif.io/api/image/3.0/example/reference/36ca0a3370db128ec984b33d71a1543d-100320001004/full/max/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"height": 31722,
"width": 70399,
"service": [
{
"id": "https://iiif.io/api/image/3.0/example/reference/36ca0a3370db128ec984b33d71a1543d-100320001004",
"profile": "level1",
"type": "ImageService3"
}
]
},
"target": "{{ id.path }}/canvas"
},
{
"id": "{{ id.path }}/annotation/p0001-text",
"type": "Annotation",
"motivation": "painting",
"body": {
"type": "TextualBody",
"format": "text/html",
"value": "<p style='font-size:1000px; background-color: rgba(16, 16, 16, 0.5); padding:300px'>The koto is to the right, carried in a cloth wrapping.</p>",
"language": "en"
},
"target": "{{ id.path }}/canvas#xywh=5500,12200,8000,5000"
}
]
}
]
}
]
}
Loading