JavaScript DHTML/Scriptaculous/Drag Drop — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:26, 26 мая 2010
Содержание
- 1 Add delay to drag and drop
- 2 Drag and drop between two tables
- 3 Drag and drop: force to scroll
- 4 Drag and drop: ghosting effect
- 5 Drag and drop: hover class
- 6 Drag and drop: invert
- 7 Drag and drop: snap
- 8 Drag and drop to reorder
- 9 Draggable handle
- 10 Draggable with scroll bar
- 11 Droppable target
- 12 Ghosting vs. non-ghosting
Add delay to drag and drop
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>script.aculo.us functional test</title>
<script type="text/javascript" src="scriptaculous-js-1.8.2/lib/prototype.js"></script>
<script type="text/javascript" src="scriptaculous-js-1.8.2/src/effects.js"></script>
<script type="text/javascript" src="scriptaculous-js-1.8.2/src/dragdrop.js"></script>
<script type="text/javascript">
var myStartEffect = function(element) {
element._opacity = Element.getOpacity(element);
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
new Effect.Highlight(element, {});
}
</script>
<style type="text/css">
h1 {font-size: 1.2em; text-align:center;}
li {
margin: 5px auto;
padding: 2px;
width: 200px;
text-align:center;
list-style-type:none;
border: 2px solid #779;
background-color: #dde
}
div {
margin: 5px auto;
padding: 2px;
width: 300px;
text-align:center;
border: 2px solid #797;
background-color: #ded
}
</style>
</head>
<body>
<h1>No delay sortable</h1>
<ul id="sort1">
<li id="s1_1">one</li>
<li id="s1_2">two</li>
<li id="s1_3">three</li>
</ul>
<h1>Delayed sortable (500 ms)</h1>
<ul id="sort2">
<li id="s2_1">one</li>
<li id="s2_2">two</li>
<li id="s2_3">three</li>
</ul>
<h1>No delay draggable</h1>
<div id="drag1">
Lorem ipsum
</div>
<h1>Delayed draggable (1000 ms)</h1>
<div id="drag2">
Lorem ipsum
</div>
<script type="text/javascript" charset="utf-8">
Sortable.create("sort1", {starteffect: myStartEffect});
Sortable.create("sort2", {starteffect:myStartEffect, delay:500});
new Draggable("drag1", {starteffect:myStartEffect});
new Draggable("drag2", {starteffect:myStartEffect, delay:1000});
</script>
</body>
</html>
Drag and drop between two tables
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<html>
<head>
<title>Drag & Drop</title>
<style type="text/css">
td
{
width: 10em;
text-align: center;
}
table.mytable {
list-style-type: none;
padding: 4px 4px 0 4px;
margin: 0px;
font-size: 13px;
font-family: Arial, sans-serif;
}
table.mytable tr {
margin-bottom: 4px;
padding: 2px 2px;
border: 1px solid #c00;
background-color: #eee;
}
div.draggable {
cursor:move;
padding:2px;
background-color: #BBCCDD;
}
div.dropsite {
padding:2px;
background-color: #DDBB99;
}
div.hoverclass123
{
border:1px solid red;
}
</style>
<script language="JavaScript" type="text/javascript" src="scriptaculous-js-1.8.2/lib/prototype.js"></script>
<script language="JavaScript" type="text/javascript" src="scriptaculous-js-1.8.2/src/scriptaculous.js"></script>
<script language="JavaScript" type="text/javascript">
Position.includeScrollOffsets = true;
window.onload = function()
{
var t1 = document.getElementById("t1");
add_divs(t1, "td", "draggable");
var trs = t1.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++)
{
var divs = document.getElementsByClassName("draggable", trs[i]);
var drag_text = divs[2].innerHTML;
for (var j = 0; j < divs.length; ++j)
{
new Draggable(divs[j], {ghosting:true, revert:true});
}
}
var t2 = document.getElementById("t2");
add_divs(t2, "td", "dropsite");
var divs = document.getElementsByClassName("dropsite", t2);
for (var j = 0; j < divs.length; ++j)
{
Droppables.add(divs[j], {accept:"draggable",
hoverclass:"hoverclass123",
onDrop:function(element, dropon, event)
{ debug("dropped " + element.innerHTML + " on "
+ dropon.innerHTML + "\n")}});
}
};
function debug(text)
{
document.getElementById("debug").innerHTML
= "<pre>" + text + "</pre>";
}
function add_divs(table, tag, classname)
{
var items = table.getElementsByTagName(tag);
for (var i = 0; i < items.length; i++)
items[i].innerHTML =
"<div class="" + classname + "">" + items[i].innerHTML + "</div>";
}
</script>
</head>
<body>
<p>Drag from this table:</p>
<DIV STYLE="padding-left: 50pt;">
<DIV STYLE="overflow: auto; width: 250; height: 100;
border: 1px gray solid;
padding:0px; margin: 0px;">
<table id="t1" class="sortable mytable">
<tr><td>one</td><td>1</td><td>uno</td></tr>
<tr><td>two</td><td>2</td><td>dos</td></tr>
<tr><td>three</td><td>3</td><td>tres</td></tr>
<tr><td>four</td><td>4</td><td>quatro</td></tr>
<tr><td>five</td><td>5</td><td>cinco</td></tr>
<tr><td>six</td><td>6</td><td>seis</td></tr>
<tr><td>seven</td><td>7</td><td>siete</td></tr>
<tr><td>eight</td><td>8</td><td>ocho</td></tr>
<tr><td>nine</td><td>9</td><td>nueve</td></tr>
<tr><td>ten</td><td>10</td><td>diez</td></tr>
</table>
</DIV>
</DIV>
<p>
<p>Drop on this table:</p>
<DIV STYLE="padding-left: 50pt;">
<DIV STYLE="overflow: auto; width: 250; height: 100;
border: 1px gray solid;
padding:0px; margin: 0px;">
<table id="t2" class="sortable mytable">
<tr><td>eleven</td><td>11</td><td>once</td></tr>
<tr><td>twelve</td><td>12</td><td>doce</td></tr>
<tr><td>thirteen</td><td>13</td><td>trece</td></tr>
<tr><td>fourteen</td><td>14</td><td>catorce</td></tr>
<tr><td>fifteen</td><td>15</td><td>quince</td></tr>
<tr><td>sixteen</td><td>16</td><td>dieciseis</td></tr>
<tr><td>seventeen</td><td>17</td><td>diecisiete</td></tr>
<tr><td>eightteen</td><td>18</td><td>dieciocho</td></tr>
<tr><td>nineteen</td><td>19</td><td>diecinueve</td></tr>
<tr><td>twenty</td><td>20</td><td>veinte</td></tr>
</table>
</DIV>
</DIV>
<p>
<div id="debug"></div>
</p>
</body>
</html>
Drag and drop: force to scroll
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script type="text/javascript">
Position.includeScrollOffsets = true;
Draggables.clear = function (event) {
while (Draggables.drags.length) {
var d = Draggables.drags.pop();
var e = d.element;
d.stopScrolling();
d.destroy();
d.element = null;
if (e.parentNode) {e.parentNode.removeChild(e)};
}
}
function cleanup() { //try to remove circular references
lis = document.getElementsByTagName("li");
for (i = 0; i < lis.length; i++) {
if (lis[i].longListItem) {lis[i].longListItem.destroy();}
else if (lis[i].container) {lis[i].container.destroy();}
}
Draggables.clear();
}
window.onload = function() {
var li = $("masterList").getElementsByTagName("LI");
for (var i = 0; i < li.length; i++) {
//var d = new LongListItem(li[i]);
//li[i].onmousedown = d.onMouseDown.bindAsEventListener(d);
var d = new Draggable(li[i],
{revert: true,
ghosting: false,
scroll: "rightContainers"
});
}
var divs = $("rightContainers").getElementsByTagName("div");
for (i = 0; i < divs.length; i++) {
if (divs[i].className && Element.hasClassName(divs[i], "container")) {
Droppables.add(divs[i].id, {hoverclass: "hover", scrollingParent: "rightContainers"});
}
}
Event.observe(window, "unload", cleanup, false);
}
</script>
<style type="text/css">
html, body {
margin:0; padding: 0;
height: 100% !important;
}
body {
position:relative;
color: black;
background-color: white;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
}
h1 {font-size:115%;}
h2 {font-size: 110%;}
h3 {font-size: 105%;}
div, p, li, td {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: small;
}
p {margin: 0 0 .7em 0; padding:0;}
ul {
position:relative;
list-style: none;
margin:0; padding:0;
overflow: visible;
}
li {position:relative;}
.instructions {font-style:italic;}
#leftDiv {
position: absolute;
top: 0; left: 0; bottom: 0;
width: 30%;
margin: 0; padding: 7px;
border-right: 2px solid #bb9;
background-color: #eed;
}
#leftDiv li, #rightContainers div.container li {
margin: 3px 0; padding: 3px 3em 3px 10px;
border: 2px solid #456;
background-color: #cde;
cursor: move;
}
#rightContainers {
padding: .5em;
position: absolute;
top: 0; bottom: 0; right: 0; left: 35%;
overflow:auto;
}
#rightContainers div.container{
background-color: #bb9;
margin: 0 0 40px 0; padding: 0 0 1px 0;
border: 2px solid #775;
}
#rightContainers div.container h2{
margin:0; padding: 2px 1em 0 1em;
text-align:center;
}
#rightContainers div.container ul {
margin: 5px; padding: 0 3px;
background-color: white;
border: 1px solid black;
}
#rightContainers div.container ul.empty {
padding: 3px 0;
}
#rightContainers div.hover {
background-color: #eed;
}
</style>
<!--[if IE]><style type="text/css">
#leftDiv {
height: expression((document.body.clientHeight - 44) + "px");
}
#leftDiv ul{width:93%;}
#leftDiv li div.count {
right:4px;
top:4px;
}
#rightContainers li a.remove {
display:block;
float:none;
position:absolute;
top: 4px;
right: 1.6em;
margin:0; padding:0 .2em;
}
</style><![endif]-->
</head>
<body>
<div id="leftDiv" class="">
<form id="frmContinue" action="#" method="post">
<p class="instructions">Shrink your window until the right-hand pane is scrollable.</p>
<p class="instructions">Drag from the list on left to groups on the right, force the right-hand pane to scroll.</p>
<input name="data" type="hidden" value=" ">
</form>
<ul id="masterList">
<li id="drag1">One</li>
<li id="drag2">Two</li>
<li id="drag3">Three</li>
<li id="drag4">Four</li>
<li id="drag5">Five</li>
<li id="drag6">Six</li>
<li id="drag7">Seven</li>
<li id="drag8">Eight</li>
</ul>
</div>
<div id="rightContainers" class="">
</form>
<div id="grp1" class="container">
<h2><span id="grp1_name">Group 1</span></h2>
<ul id="grp1ul" class="empty"></ul>
</div>
<div id="grp2" class="container">
<h2><span id="grp2_name">Group 2</span></h2>
<ul id="grp2ul" class="empty"></ul>
</div>
<div id="grp3" class="container">
<h2><span id="grp3_name">Group 3</span></h2>
<ul id="grp3ul" class="empty"></ul>
</div>
<div id="grp4" class="container">
<h2><span id="grp4_name">Group 4</span></h2>
<ul id="grp4ul" class="empty"></ul>
</div>
<div id="grp5" class="container">
<h2><span id="grp5_name">Group 5</span></h2>
<ul id="grp5ul" class="empty"></ul>
</div>
<div id="grp6" class="container">
<h2><span id="grp6_name">Group 6</span></h2>
<ul id="grp6ul" class="empty"></ul>
</div>
<div id="grp7" class="container">
<h2><span id="grp7_name">Group 7</span></h2>
<ul id="grp7ul" class="empty"></ul>
</div>
<div id="grp8" class="container">
<h2><span id="grp8_name">Group 8</span></h2>
<ul id="grp8ul" class="empty"></ul>
</div>
<div id="grp9" class="container">
<h2><span id="grp9_name">Group 9</span></h2>
<ul id="grp9ul" class="empty"></ul>
</div>
</div>
</body>
</html>
Drag and drop: ghosting effect
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>script.aculo.us Drag and drop functional test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
</head>
<body style="background-color:#eee;">
<div style="position:relative;margin-left:100px;top:40px;background-color:white;">
(inside position:relative container)
<h1>script.aculo.us Drag and drop functional test file</h1>
<h2>Draggables/Droppables</h2>
<div id="absolute_positioned_element" class="box1" style="width:150px;height:150px;background:#bbf;">
<b>Ghosting effect</b>
<input type="text" value="blah"/>
<div id="hurradiegams">test!</div>
<br/>
</div>
<a href="#" onclick="alert($("hurradiegams").innerHTML); return false;">alert contents of test div</a>
<div id="absolute_positioned_element2" class="box1" style="width:150px;height:150px;background:#bbf;">
<span id="handle1">Ghost effect</span><br/>
</div>
<script type="text/javascript" language="javascript" charset="utf-8">
Position.includeScrollOffsets = true;
new Draggable("absolute_positioned_element",{ghosting: true});
new Draggable("absolute_positioned_element2",{ghosting: true, revert:true});
</script>
</div>
</body>
</html>
Drag and drop: hover class
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<html>
<head>
<title>script.aculo.us Drag and drop functional test file</title>
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
</head>
<style>
div.hoverclass123 {
border:1px solid red;
}
</style>
<body>
<h1>script.aculo.us Drag and drop functional test file</h1>
<h2>w/o hoverclass</h2>
<div id="cart" class="cart" style="text-align:center;height:50px;padding:10px;background-color:#fba">
### DROP HERE ###
</div>
<script type="text/javascript">Droppables.add("cart", {onDrop:function(element,dropon){alert("w/o hoverclass, should be \"product_id\":" + encodeURIComponent(element.id) + ", dropon should be \"cart\":" + dropon.id)}})</script>
<br/>
<img alt="Product2" id="product_id" src="icon.png" /> <-- drag this!
<script type="text/javascript">new Draggable("product_id", {revert:true})</script>
<h2>w/ hoverclass</h2>
<div id="carth" class="cart" style="text-align:center;height:50px;padding:10px;background-color:#fba">
### DROP HERE ###
</div>
<script type="text/javascript">Droppables.add("carth", {hoverclass:"hoverclass123",onDrop:function(element, dropon, event){alert("w/ hoverclass: should be \"product_id\":" + encodeURIComponent(element.id) + ", dropon should be \"carth\":" + dropon.id)}})</script>
</body>
</html>
Drag and drop: invert
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>script.aculo.us Drag and drop functional test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
<style type="text/css" media="screen">
#thelist li { background: green; margin:5px; padding: 30px; }
#thelist2 li { background: #ffb; margin:2px; padding: 2px; }
</style>
</head>
<body>
<h1>script.aculo.us Drag and drop functional test file</h1>
<h2>Draggables/Droppables</h2>
<div id="revertbox1" class="box1" style="z-index:1000;width:150px;height:150px;background:#bbf;">
<span id="handle1">drag here</span><br/>
<input type="checkbox" id="shouldrevert1"/> Revert?
</div>
<div id="revertbox2" class="box" style="z-index:1000;width:150px;height:150px;background:#bbf;">
<span id="handle2">drag here</span><br/>
<input type="checkbox" id="shouldrevert2"/> Revert?
I"ve onStart, onDrag and onEnd events!<br/>
<span id="event-info"></span>
</div>
<div id="specialbox" class="box" style="z-index:1000;width:150px;height:150px;background:#fbb;">
This box overrides the default endeffect
</div>
<div id="specialbox2" class="box" style="z-index:1000;width:150px;height:150px;background:#fbb;">
This box overrides the default starteffect
</div>
<div id="specialbox3" class="box" style="z-index:1000;width:150px;height:150px;background:#fbb;">
This box overrides the default end- and starteffects
</div>
<div id="droptarget1" style="width:200px;height:200px;background-color:#eee;">accepts first box</div>
<div id="droptarget2" style="width:200px;height:200px;background-color:#eee;">accepts second box</div>
<script type="text/javascript" language="javascript" charset="utf-8">
new Draggable("revertbox1",{scroll:window,handle:"handle1",revert:function(element){return ($("shouldrevert1").checked)}});
new Draggable("revertbox2",{
handle:"handle2",
revert:function(element){return ($("shouldrevert2").checked)},
onStart:function(){$("revertbox2").setStyle({backgroundColor:"#bfb"})},
onDrag:function(){$("event-info").update("drag!")},
onEnd:function(){alert("end!")}
});
Droppables.add("droptarget1",{accept:["box1","otherstuff"],onDrop:function(){alert("drop!")}});
Droppables.add("droptarget2",{accept:"box",onDrop:function(){alert("drop!")}});
new Draggable("specialbox",{
endeffect:function(){
new Effect.Highlight("specialbox",{queue:"end"});
}
});
new Draggable("specialbox2",{
starteffect:function(){
new Effect.Highlight("specialbox2",{queue:"end"});
}
});
new Draggable("specialbox3",{
starteffect:function(){
new Effect.Highlight("specialbox3",{queue:"end"});
},
endeffect:function(){
new Effect.Highlight("specialbox3",{queue:"end"});
}
});
</script>
</body>
</html>
Drag and drop: snap
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>script.aculo.us Drag and drop functional test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
<style type="text/css" media="screen">
div.box { background: green; width:100px; height:100px }
div.box-container { background: yellow; width:200px; height:200px }
</style>
</head>
<body>
<h1>script.aculo.us Drag and drop functional test file</h1>
<h2>Draggables/Droppables</h2>
<div id="box-normal" class="box">
Normal box
</div>
<div id="box-grid-numeric" class="box">
snap: 25
</div>
<div id="box-grid-array" class="box">
snap: [5,25]
</div>
<div id="box-grid-procedural" class="box">
snap: procedural (e.g. constrain to box)
</div>
<div class="box-container">
<div id="box-grid-procedural-gets-draggable" class="box">
snap: procedural (e.g. constrain to parent element)
</div>
</div>
<script type="text/javascript" language="javascript" charset="utf-8">
new Draggable("box-normal",{snap:false,revert:true});
new Draggable("box-grid-numeric",{snap:25,revert:true});
new Draggable("box-grid-array",{snap:[5,25],revert:true});
new Draggable("box-grid-procedural",{
snap: function(x,y) {
return[
x<100 ? (x > 0 ? x : 0 ) : 100,
y<50 ? (y > 0 ? y : 0) : 50];
},
revert:true
});
new Draggable("box-grid-procedural-gets-draggable",{
snap: function(x,y,draggable) {
function constrain(n, lower, upper) {
if (n > upper) return upper;
else if (n < lower) return lower;
else return n;
}
element_dimensions = Element.getDimensions(draggable.element);
parent_dimensions = Element.getDimensions(draggable.element.parentNode);
return[
constrain(x, 0, parent_dimensions.width - element_dimensions.width),
constrain(y, 0, parent_dimensions.height - element_dimensions.height)];
},
revert:true
});
</script>
</body>
</html>
Drag and drop to reorder
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>script.aculo.us Drag and drop functional test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
<style type="text/css" media="screen">
#thelist li { background: green; margin:5px; padding: 30px; }
#thelist2 li { background: #ffb; margin:2px; padding: 2px; }
</style>
</head>
<body>
<h1>script.aculo.us Drag and drop functional test file</h1>
<h2>Draggables/Droppables</h2>
<div style="width:400px;height:400px;overflow:scroll;position:relative;" id="scroll-container">
<ul id="thelist2" style="padding: 2px; background:red;">
<li>Relatively here!</li>
<li><input onclick="this.checked = !this.checked" name="x" id="x" type="checkbox"/>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
</ul>
</div>
<pre id="debug"></pre>
<script type="text/javascript" language="javascript" charset="utf-8">
// Sortable.create("thelist", {overlap: "horizontal", constraint: false});
Position.includeScrollOffsets = true;
Sortable.create("thelist2",{scroll:"scroll-container"});
</script>
</body>
</html>
Draggable handle
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>script.aculo.us Drag and drop functional test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
<style type="text/css" media="screen">
#thelist li { background: green; margin:5px; padding: 30px; }
#thelist2 li { background: #ffb; margin:2px; padding: 2px; }
#revertbox2 { position:absolute;top:40px;left:50px;z-index:1000;width:150px;height:150px;background:#bbf; }
</style>
</head>
<body>
<h1>script.aculo.us Drag and drop functional test file</h1>
<h2>Draggables/Droppables</h2>
<a href="#" onclick="alert($H(Sortable.sortables).inspect());return false">inspect sortables</a>
<div id="revertbox1" class="box1" style="opacity:0.5;z-index:1000;width:150px;height:150px;background:#bfb;">
<span class="handle1">drag here</span>
<span class="handle1">(but not here)</span><br/>
<input type="checkbox" id="shouldrevert1"/> Revert?
</div>
<div id="revertbox2" class="box">
<span id="handle2">drag here</span><br/>
<input type="checkbox" id="shouldrevert2"/> Revert?
</div>
<div id="xxxx">testtest</div>
<script type="text/javascript" language="javascript" charset="utf-8">
new Draggable("revertbox1",{scroll:window,zindex:-5,handle:"handle1",revert:function(element){return ($("shouldrevert1").checked)}});
new Draggable("revertbox2",{scroll:window,handle:"handle2",revert:function(element){return ($("shouldrevert2").checked)}});
Droppables.add("xxxx",{accept:["box1","box2"],onDrop:function(){alert("drop!")}});
</script>
<ul id="thelist" style="padding: 10px; position: absolute; top:20px; left:200px;z-index:1000;">
<li id="thelist_4">Hey there! I"m absolutely positioned</li>
<li id="thelist_1">one<br/><form id="form1"><input type="checkbox" onclick="this.checked = !this.checked" value="x" name="x" id="xyz"/><input type="text" id="xxx"></input></form></li>
<li id="thelist_2">two<br/><form id="form2"><input type="text" id="xyx"></input></form></li>
<li id="thelist_3">three<br/><form id="form3"><input type="text" id="xu3"></input></form></li>
</ul>
<ul id="thelist2" style="padding: 2px; background:red;">
<li>Relatively here!</li>
<li><input onclick="this.checked = !this.checked" name="x" id="x" type="checkbox"/>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
</ul>
<script type="text/javascript" language="javascript" charset="utf-8">
// Sortable.create("thelist", {overlap: "horizontal", constraint: false});
Sortable.create("thelist");
Sortable.create("thelist2");
</script>
</body>
</html>
Draggable with scroll bar
<html>
<head>
<title>Untitled Document</title>
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
<script type="text/javascript">
Event.observe(window, "load", function() {
new Draggable("my", { scroll: "container" });
});
</script>
</head>
<body>
<div id="container">
<p>A</p>
<p id="my">Drag this around!</p>
<p>C</p>
</div>
</body>
</html>
Droppable target
<!--
Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!-- revised from scriptaculous-js-1.8.2 demo code -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
</head>
<body>
<div id="source" style="height: 100px; width: 100px; background-color: gray;">
Draggable
</div>
<script type="text/javascript">
new Draggable("source", {
revert:"failure",
onDropped: function(element){ $(element).update("I WAS DROPPED!") },
reverteffect: function(element, top_offset, left_offset) {
var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
new Effect.Move(element, {
x: -left_offset, y: -top_offset, duration: dur,
transition: Effect.Transitions.spring,
queue: {scope:"_draggable", position:"end"}
});
}
});
</script>
<br/>
<div id="target" style="height: 100px; width: 100px; background-color: green;">
Good Target
</div>
<script type="text/javascript">
Droppables.add("target", {
onDrop:function(element){ Effect.Puff($("source")); }
});
</script>
<br/>
</body>
</html>
Ghosting vs. non-ghosting
<html>
<head>
<title>Untitled Document</title>
<script src="scriptaculous-js-1.8.2/lib/prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/scriptaculous.js" type="text/javascript"></script>
<script src="scriptaculous-js-1.8.2/src/unittest.js" type="text/javascript"></script>
<script type="text/javascript">
Event.observe(window, "load", function() {
new Draggable("regular");
new Draggable("ghostly", { ghosting: true });
});
</script>
</head>
<body>
<p id="regular" class="pad">This drags regularly</p>
<p id="ghostly" class="pad">This drags with ghosting</p>
</body>
</html>