blob: f27626f66cf9dde60332be3444df947e01c7cfd0 [file] [log] [blame]
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="500px" height="500px" viewBox="0 0 500 500">
<title>SVG link drag and drop: allowed effects 'copy','move','link' and 'none'</title>
<a xlink:href="data:text/plain,1">
<circle cx="50" cy="50" r="40" fill="green"/>
</a>
<textArea x="10" y="100" width="480" height="200" font-size="30">You should be able to drag green circle and drop it onto any of the boxes below. Choosen box should turn green once circle is dropped on it.</textArea>
<rect x="10" y="300" width="100" height="100" fill="silver"/>
<rect x="120" y="300" width="100" height="100" fill="gray"/>
<rect x="230" y="300" width="100" height="100" fill="gray"/>
<rect x="340" y="300" width="100" height="100" fill="black"/>
<script type="application/ecmascript">
var a = document.querySelector('a'), rect = document.querySelectorAll('rect'),
effects = ['copy','move','link','all'], e = 0;
a.addEventListener('dragstart',
function (event)
{event.dataTransfer.effectAllowed = effects[e]}
,false);
for(var i = 0; i != rect.length; i++)
{rect[i].addEventListener('dragenter',
function (event)
{event.preventDefault();
event.dataTransfer.effectAllowed = effects[e];}
,false);
rect[i].addEventListener('dragover',
function (event)
{event.preventDefault()}
,false);
rect[i].addEventListener('drop',
function (event)
{if(event.dataTransfer.dropEffect == effects[e] &amp;&amp; event.dataTransfer.effectAllowed == effects[e] &amp;&amp; i != 3)
{event.target.setAttribute('fill','green');}
e = (e+1)%3;}
,false);}
</script>
</svg>