| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
|---|
| 2 |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|---|
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|---|
| 4 |
<head> |
|---|
| 5 |
<title>Test Drag and drop with MochiKit</title> |
|---|
| 6 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|---|
| 7 |
<link href="simple_dnd.css" rel="stylesheet" type="text/css" /> |
|---|
| 8 |
<script type="text/javascript" src="../../MochiKit/MochiKit.js"></script> |
|---|
| 9 |
<script type="text/javascript" src="../../MochiKit/New.js"></script> |
|---|
| 10 |
<script type="text/javascript" src="../../MochiKit/Visual.js"></script> |
|---|
| 11 |
<script type="text/javascript" src="../../MochiKit/DragAndDrop.js"></script> |
|---|
| 12 |
</head> |
|---|
| 13 |
<body> |
|---|
| 14 |
<h3>Drag and Drop examples.</h3> |
|---|
| 15 |
<div> |
|---|
| 16 |
<div id="drag-1" class="drag">test drag 1</div> |
|---|
| 17 |
<div id="drag-2" class="drag">test drag 2 (horizontal)</div> |
|---|
| 18 |
<div id="drag-3" class="drag">test drag 3 (vertical)</div> |
|---|
| 19 |
<div id="drag-4" class="drag">test drag 4 (selectclass)</div> |
|---|
| 20 |
<div id="drag-5" class="drag">test drag 5 (fixed)</div> |
|---|
| 21 |
<div id="drag-6" class="drag">test drag 6 (absolute)</div> |
|---|
| 22 |
<div id="drag-7" class="drag">test drag 7 (relative)</div> |
|---|
| 23 |
</div> |
|---|
| 24 |
<div id="dropzones"> |
|---|
| 25 |
<div id="drop-1" class="drop">test drop 1</div> |
|---|
| 26 |
<div id="drop-2" class="drop">test drop 2 (hoverclass)</div> |
|---|
| 27 |
<div id="drop-3" class="drop">test drop 3 (activeclass)</div> |
|---|
| 28 |
<div id="drop-4" class="drop">test drop 4 (hoverFunc)</div> |
|---|
| 29 |
<div id="drop-5" class="drop">test drop 5 (activeFunc)</div> |
|---|
| 30 |
<div id="drop-6">test drop 6</div> |
|---|
| 31 |
<div id="droptext">No select</div> |
|---|
| 32 |
</div> |
|---|
| 33 |
<script type="text/javascript"> |
|---|
| 34 |
|
|---|
| 35 |
var saveTxt = ""; |
|---|
| 36 |
onHoverFunc = function (element, onhover) { |
|---|
| 37 |
if (onhover) { |
|---|
| 38 |
saveTxt = element.childNodes[0].nodeValue; |
|---|
| 39 |
element.childNodes[0].nodeValue = "Please drop on me!"; |
|---|
| 40 |
} else { |
|---|
| 41 |
element.childNodes[0].nodeValue = saveTxt; |
|---|
| 42 |
} |
|---|
| 43 |
}; |
|---|
| 44 |
onActiveFunc = function (element, dragElt) { |
|---|
| 45 |
element.childNodes[0].nodeValue += " and I'm active ! (" + dragElt.id + ")"; |
|---|
| 46 |
}; |
|---|
| 47 |
onDesactiveFunc = function (element, dragElt) { |
|---|
| 48 |
var ind = element.childNodes[0].nodeValue.lastIndexOf(" and I'm active !"); |
|---|
| 49 |
element.childNodes[0].nodeValue = element.childNodes[0].nodeValue.slice(0, ind); |
|---|
| 50 |
}; |
|---|
| 51 |
onSelectFunc = function (element) { |
|---|
| 52 |
new MochiKit.Visual.Highlight(element); |
|---|
| 53 |
}; |
|---|
| 54 |
onDeselectFunc = function (element) { |
|---|
| 55 |
element.childNodes[0].nodeValue += "."; |
|---|
| 56 |
}; |
|---|
| 57 |
ondrop = function (element, dropElt) { |
|---|
| 58 |
MochiKit.Visual.pulsate(dropElt); |
|---|
| 59 |
MochiKit.DOM.getElement('droptext').childNodes[0].nodeValue = "Selected: " + element.id; |
|---|
| 60 |
}; |
|---|
| 61 |
|
|---|
| 62 |
new MochiKit.DragAndDrop.Draggable('drag-1', {'revert': true, 'ghosting': true}); |
|---|
| 63 |
new MochiKit.DragAndDrop.Draggable('drag-2', {'revert': true, 'constraint': 'horizontal'}); |
|---|
| 64 |
new MochiKit.DragAndDrop.Draggable('drag-3', {'revert': true, 'constraint': 'vertical'}); |
|---|
| 65 |
new MochiKit.DragAndDrop.Draggable('drag-4', {'revert': true, 'selectclass': 'drag-select'}); |
|---|
| 66 |
new MochiKit.DragAndDrop.Draggable('drag-5', {'revert': true, 'starteffect': onSelectFunc, 'endeffect': onDeselectFunc}); |
|---|
| 67 |
new MochiKit.DragAndDrop.Draggable('drag-6', {'revert': true}); |
|---|
| 68 |
new MochiKit.DragAndDrop.Draggable('drag-7', {'revert': true}); |
|---|
| 69 |
|
|---|
| 70 |
new MochiKit.DragAndDrop.Droppable('drop-1', {'ondrop': ondrop}); |
|---|
| 71 |
new MochiKit.DragAndDrop.Droppable('drop-2', {'ondrop': ondrop, 'hoverclass': 'drop-hover'}); |
|---|
| 72 |
new MochiKit.DragAndDrop.Droppable('drop-3', {'ondrop': ondrop, 'activeclass': 'drop-active'}); |
|---|
| 73 |
new MochiKit.DragAndDrop.Droppable('drop-4', {'ondrop': ondrop, 'hoverfunc': onHoverFunc}); |
|---|
| 74 |
new MochiKit.DragAndDrop.Droppable('drop-5', {'ondrop': ondrop, 'onactive': onActiveFunc, 'ondesactive': onDesactiveFunc}); |
|---|
| 75 |
new MochiKit.DragAndDrop.Droppable('drop-6', {'ondrop': ondrop, 'transparent': true}); |
|---|
| 76 |
|
|---|
| 77 |
</script> |
|---|
| 78 |
<div> |
|---|
| 79 |
Links to other samples: |
|---|
| 80 |
<ul> |
|---|
| 81 |
<li><a href="dnd_boxes.html">Boxes DND</a></li> |
|---|
| 82 |
<li><a href="dnd_hoverclass.html">Hoverclass DND</a></li> |
|---|
| 83 |
<li><a href="dnd_snap.html">Snap DND</a></li> |
|---|
| 84 |
<li><a href="dnd_ghost.html">Ghost DND</a></li> |
|---|
| 85 |
<li><a href="dnd_scroll.html">Scroll DND</a></li> |
|---|
| 86 |
<li><a href="dnd_full.html">Full DND</a></li> |
|---|
| 87 |
</ul> |
|---|
| 88 |
</div> |
|---|
| 89 |
</body> |
|---|
| 90 |
</html> |
|---|