Skip to content

Commit 384c447

Browse files
authored
added examples (SolidOS#311)
* added examples * fixed errors
1 parent 2223776 commit 384c447

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

examples/draganddrop/index.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='UTF-8'>
5+
<title>solid-ui UI.widgets.draganddrop examples page</title>
6+
<script type="text/javascript" src="../../lib/webpack-bundle.js"></script>
7+
<script>
8+
const $ = document.querySelector.bind(document)
9+
function showSource(widgetName) {
10+
$(`#viewSource-${widgetName}`).innerHTML = $(`#script-${widgetName}`).innerText
11+
.replace(/&/g, "&amp;")
12+
.replace(/</g, "&lt;")
13+
.replace(/>/g, "&gt;")
14+
.replace(/"/g, "&quot;")
15+
.replace(/'/g, "&#039;")
16+
}
17+
</script>
18+
</head>
19+
<body>
20+
<h2 id="makeDropTarget"><a href="#makeDropTarget">DragAndDrop</a></h2>
21+
<p><strong>DragAndDrop</strong> has three functions that can be used to handle dragging and dropping of uris, files, and
22+
images.</p>
23+
24+
<p><strong>makeDraggable</strong> is used to make an element Draggable. Along with the
25+
HTML Element, it is also necessary to pass an object with a uri. This is used to set the data on the
26+
EventListener for 'dragstart'. </p>
27+
28+
<p><strong>makeDropTarget</strong> is used to make an element enabled as a drop target. Along with the HTML Element, it is also
29+
necessary to pass in two callback functions; one to handle draggable uris and the other to handle draggable
30+
files and images.</p>
31+
32+
<p><strong>uploadFiles</strong> is used to process the files that a user is uploading.</p>
33+
34+
35+
<p id="drag" draggable="true"><strong>Drag me to the target! </strong> </p>
36+
37+
<div id="target">
38+
<p>Drag the message above or drag any file or image and drop it on this target to see it work. </p>
39+
<img src="../../src/icons/noun_748003.svg" width="200" height="200">
40+
</div>
41+
42+
<script id="script-makeDropTarget">
43+
const droppedURIHandler = function() {
44+
return alert('URI was dropped')
45+
}
46+
const droppedFileHandler = function () {
47+
return alert('File was dropped')
48+
/* Example from meeting panes for using uploadFiles in the droppedFileHandler function
49+
which is passed to the makeDropTarget function.
50+
***************
51+
function (files) {
52+
UI.widgets.uploadFiles(kb.fetcher, files, meeting.dir().uri + 'Files', meeting.dir().uri + 'Pictures',
53+
function (theFile, _destURI) {
54+
if (theFile.type.startsWith('image/')) {
55+
makePicturesFolder('Files') // if necessary
56+
} else {
57+
makeMaterialsFolder('Pictures')
58+
}
59+
}) */
60+
}
61+
const target = document.querySelector('#target')
62+
const dragElement = document.querySelector('#drag')
63+
const uri = new UI.rdf.NamedNode('https://exampleuser.inrupt.net')
64+
UI.widgets.makeDropTarget(target, droppedURIHandler, droppedFileHandler)
65+
UI.widgets.makeDraggable(dragElement,uri)
66+
</script>
67+
<pre id="viewSource-makeDropTarget"></pre>
68+
<script>
69+
showSource('makeDropTarget')
70+
</script>
71+
</body>
72+
</html>

0 commit comments

Comments
 (0)