Skip to content

Commit aa83cc5

Browse files
committed
Expanded implementation notes, added new example πŸ“βž•
Committing a touch early to possibly show to cookbook authors call
1 parent 9558b95 commit aa83cc5

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

β€Žrecipe/0599-drag-and-drop/index.mdβ€Ž

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ topic:
1313

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

16-
Alternately, as a viewer developer, you would like to allow your viewer to accept manifests from dragged-over items.
16+
Alternately, as a viewer developer, you would like to allow your viewer to receive dragged-over items.
1717

1818
## Implementation Notes
1919

@@ -23,31 +23,14 @@ Implementing this recipe requires a resource provider and a viewer each to imple
2323

2424
The resource provider must have a draggable item β€” such as an image β€” that makes use of the DataTransfer object. It will have a [`dataTransfer.setData` method](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) attached to the item's `dragstart` event.
2525

26-
### For Viewer Developers
27-
28-
A supporting viewer must have an interface capable of handling the DataTransfer object's data carried by the draggable item in its `drop` event.
29-
30-
## Restrictions
31-
32-
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.
33-
34-
Viewer developers will have a special need to consider security when implementing a droppable interface.
35-
36-
## Example
37-
38-
Below are a link to this recipe's Manifest, an image of the IIIF logo decorated with the appropriate JavaScript event handler attributes, and a visible version of the script called by the image's event handlers. For a supporting viewer, the IIIF logo image below could be dragged onto its viewing area and dropped, which would result in the viewer retrieving the manifest for the IIIF Cookbook recipe titled ["Internationalization and Multi-language Values"][0006].
39-
40-
{% include manifest_links.html viewers="" manifest="manifest.json" %}
41-
42-
<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">
43-
26+
A script implementing such a method for a Manifest could look like the below.
4427
```
4528
<script>
4629
function drag(ev) {
4730
ev.dataTransfer.setData("text/plain", JSON.stringify({
4831
"@context": "http://iiif.io/api/presentation/3/context.json",
49-
"id": "https://iiif.io/api/cookbook/recipe/0599-drag-and-drop/dnd-manifest.json",
50-
"type": "Annotation",
32+
"id": "https://iiif.io/api/cookbook/recipe/0599-drag-and-drop/dnd-manifest",
33+
"type": "Manifest",
5134
"motivation": ["contentState"],
5235
"target": {
5336
"id": "https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json",
@@ -58,11 +41,49 @@ function drag(ev) {
5841
</script>
5942
```
6043

44+
Note that the script forces the manifest content into a string, which the receiving viewer's handling script is A script implementing such a method for a single Canvas of a Manifest could look like the below. (Noting that there is no likely practical difference from the above since this manifest contains but one Canvas.)
45+
```
46+
<script>
47+
function drag(ev) {
48+
ev.dataTransfer.setData("text/plain", JSON.stringify({
49+
"@context": "http://iiif.io/api/presentation/3/context.json",
50+
"id": "https://iiif.io/api/cookbook/recipe/0599-drag-and-drop/dnd-manifest",
51+
"type": "Annotation",
52+
"motivation": ["contentState"],
53+
"target": {
54+
"id": "https://iiif.io/api/cookbook/recipe/0006-text-language/canvas/p1",
55+
"type": "Canvas",
56+
"partOf": [{
57+
"id": "https://iiif.io/api/cookbook/recipe/0006-text-language/manifest.json",
58+
"type": "Manifest"
59+
}]
60+
}
61+
}));
62+
}
63+
</script>
64+
```
65+
66+
### For Viewer Developers
67+
68+
A supporting viewer must have an interface capable of handling the DataTransfer object's data carried by the draggable item in its `drop` event.
69+
70+
## Restrictions
71+
72+
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.
73+
74+
Viewer developers will have a special need to consider security when implementing a droppable interface.
75+
76+
## Example
77+
78+
Below are a link to this recipe's Manifest, an image of the IIIF logo decorated with the appropriate JavaScript event handler attributes, and a visible version of the script called by the image's event handlers. For a supporting viewer, the IIIF logo image below could be dragged onto its viewing area and dropped, which would result in the viewer retrieving the manifest for the IIIF Cookbook recipe titled ["Internationalization and Multi-language Values"][0006].
79+
80+
<img src="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">
81+
6182
<script>
6283
function drag(ev) {
6384
ev.dataTransfer.setData("text/plain", JSON.stringify({
6485
"@context": "http://iiif.io/api/presentation/3/context.json",
65-
"id": "https://iiif.io/api/cookbook/recipe/0599-drag-and-drop/dnd-manifest.json",
86+
"id": "https://iiif.io/api/cookbook/recipe/0599-drag-and-drop/dnd-manifest",
6687
"type": "Annotation",
6788
"motivation": ["contentState"],
6889
"target": {

0 commit comments

Comments
Β (0)