-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.htm
More file actions
157 lines (135 loc) · 5.75 KB
/
index.htm
File metadata and controls
157 lines (135 loc) · 5.75 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: Drag and Drop</title>
<link rel="stylesheet" href="css/html5demos.css">
<script src="js/h5utils.js"></script></head>
<body>
<section id="wrapper">
<header>
<h1>Simple Drag and Drop</h1>
</header>
<style>
article div {
margin: 10px 0;
}
label {
line-height: 32px;
}
/* for safari */
*[draggable=true] {
-khtml-user-drag: element;
cursor: move;
}
#drop {
border: 3px dashed #ccc;
padding: 10px;
background: #fff;
min-height: 200px;
/* overflow-y: auto;*/
}
#drop .info {
color: #999;
text-align: center;
}
#drop ul {
margin: 0;
padding: 0;
}
#drop li {
border-top: 2px solid #ccc;
list-style: none;
padding: 5px;
font-size: 90%;
}
#drop li:first-child {
border-top: 0;
}
</style>
<article>
<section>
<p>Instructions: grab <em>anything</em> and drag it in to the drop zone below. I've included some text below, but you can drag urls, bookmarklets, files, <em>anything</em>.</p>
<p>Check out the functionality in different browsers, because the same content appears differently when dropped. Something to watch out for in the future.</p>
<p>Change the options below to see the difference between the default Text and sniffing for data (not supported in IE I'm afraid).</p>
<p>Try also dropping a few files from your desktop on the drop zone and notice the content-type: text/uri-list</p>
<div>
<input type="radio" name="getDataType" value="text" id="text" checked="checked" /> <label for="text">getData('Text')</label>
</div>
<div>
<input type="radio" name="getDataType" value="type" id="type" /> <label for="type">getData(e.dataTransfer.types[0]) based on detected content type</label>
</div>
</section>
<section id="drag">
<p><img class="photo" src="https://twimg0-a.akamaihd.net/profile_images/1648259432/IMG_5089_small.jpg" alt="Andrei Ovidiu" style="float: left; margin: 3px 10px 10px 0;" /> My name is <a class="fn n url" rel="me" href="http://oracolive.com">Andrei Ovidiu</a> (<a href="http://twitter.com/oracol">@oracol on Twitter</a> and <a href="http://oracolive.blogspot.com/">my blog</a>). <span class="adr">I run a small <abbr class="type" title="Work">business</abbr> in <a href="http://www.flickr.com/places//Germany/North+Rhine-Westphalia/Düsseldorf"><span class="region">Düsseldorf</span>, <abbr class="country-name" title="Deutschland">Germany</abbr></a> called <a class="org url" rel="me" href="http://oracolive.com">Oracolive</a> and I specialise in backend & front-end development .</span></p>
</section>
<section id="drop">
<p class="info">Drop here for info about the dragged item</p>
</section>
</article>
<script>
function cancel(e) {
if (e.preventDefault) e.preventDefault(); // required by FF + Safari
e.dataTransfer.dropEffect = 'copy'; // tells the browser what drop effect is allowed here
return false; // required by IE
}
function entities(s) {
var e = {
'"' : '"',
'&' : '&',
'<' : '<',
'>' : '>'
};
return s.replace(/["&<>]/g, function (m) {
return e[m];
});
}
var getDataType = document.querySelector('#text');
var drop = document.querySelector('#drop');
// Tells the browser that we *can* drop on this target
addEvent(drop, 'dragover', cancel);
addEvent(drop, 'dragenter', cancel);
addEvent(drop, 'drop', function (e) {
if (e.preventDefault) e.preventDefault(); // stops the browser from redirecting off to the text.
// just rendering the text in to the list
// clear out the original text
drop.innerHTML = '<ul></ul>';
var li = document.createElement('li');
/** THIS IS THE MAGIC: we read from getData based on the content type - so it grabs the item matching that format **/
if (getDataType.checked == false && e.dataTransfer.types) {
li.innerHTML = '<ul>';
[].forEach.call(e.dataTransfer.types, function (type) {
li.innerHTML += '<li>' + entities(e.dataTransfer.getData(type) + ' (content-type: ' + type + ')') + '</li>';
});
li.innerHTML += '</ul>';
} else {
// ... however, if we're IE, we don't have the .types property, so we'll just get the Text value
li.innerHTML = e.dataTransfer.getData('Text');
}
var ul = drop.querySelector('ul');
if (ul.firstChild) {
ul.insertBefore(li, ul.firstChild);
} else {
ul.appendChild(li);
}
return false;
});
</script><a id="html5badge" href="http://www.w3.org/html/logo/">
<img src="http://www.w3.org/html/logo/badge/html5-badge-h-connectivity-device-graphics-multimedia-performance-semantics-storage.png" width="325" height="64" alt="HTML5 Powered with Connectivity / Realtime, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage" title="HTML5 Powered with Connectivity / Realtime, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage">
</a>
<footer><a href="/">HTML5 demos</a>/<a id="built" href="http://twitter.com/oracol">@oracol built this</a>/<a href="#view-source">view source</a></footer>
</section>
<a href="http://github.com/oracol/html5"><img style="position: absolute; top: 0; left: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_left_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<script src="js/prettify.packed.js"></script>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>