-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
93 lines (88 loc) · 3.52 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>OBS Overlay Drag Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div class="gone">
<!-- This image is used when dragging elements -->
<img src="obs.png" id="dragImage" />
</div>
<div class="container">
<h1>OBS Overlay Drag-and-drop Demo</h1>
<p>This page is a demo of a <strong>simple widget you can drag</strong> from a website straight into OBS, no extra steps required.</p>
<div class="row">
<div class="col-12 col-md-6">
<img src="demo-gif.gif" class="img-thumbnail" />
<br /><br />
</div>
<div class="col-12 col-md-6"></div>
</div>
<div class="row no-gutters">
<br />
<p>Using the OBS v25 RC? Try dragging one of these buttons! <strong>Note:</strong> This will not work if OBS is running as Administrator.</p>
</div>
<div class="row" id="button-wrapper">
<!-- This element is automatically populated using JavaScript. -->
</div>
<div>
<br />
<h3>Supported Parameters</h3>
<p>These are standard URL parameters. They will define the initial state of the source once it's in OBS. You can then customize it as normal.</p>
<table class="table">
<thead>
<tr>
<th scope="col">Field name</th>
<th scope="col">Description</th>
<th scope="col">Fallback</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>layer-name</code></td>
<td>Name of the source in the OBS list</td>
<td>URL Domain</td>
</tr>
<tr>
<td><code>layer-width</code></td>
<td>Width of the source in the canvas</td>
<td>Canvas width</td>
</tr>
<tr>
<td><code>layer-height</code></td>
<td>Height of the source in the canvas</td>
<td>Canvas height</td>
</tr>
</tbody>
</table>
<br />
<h3>For Web Developers</h3>
<p>There are a few ways you can use this on your website.</p>
<p>The most basic method is a simple anchor (<code><a href=""></code>). The user drags the link into OBS, and OBS will parse the URL & parameters. Browser compatibility in this area is not perfect, but this means that existing links and buttons can be dragged into OBS without modification.</p>
<p><strong>Recommended: </strong>For an advanced, fancy design, you want to use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer">DataTransfer API.</a> Specifically, the <code>dragstart</code> event. Example code below:</p>
<p><pre><code>
let dragged;
// Configure an offset from the cursor for your drag icon
const pos = 30;
// Add an event listener
document.addEventListener("dragstart", e => {
dragged = e.target;
// Customize the visible 'thumbnail' while dragging
e.dataTransfer.setDragImage(document.querySelector('#dragImage'), pos, pos);
// Set the data type, and the value. You specifically want text/uri-list.
e.dataTransfer.setData("text/uri-list", dragged.href);
});
// Optionally, remove the focus from the button
document.addEventListener("dragend", e => dragged.blur());
// If using an anchor, block the default behaviour
document.addEventListener("click", e => e.preventDefault());
</code></pre></p>
</div>
</div>
</body>
</html>