I've got an update to the post I sent last month. Although my original
question was rather specific, I soon realized that I needed to solve a
broader problem and I'm happy to report that I've figured out a simple
solution!
Here's the (broader) problem: I drag an element within a sortable.
Sometimes I drag it to a different position and sometimes I don't. I
want to run different functions on the dragged element depending on
whether it has moved.
The callback OnUpdate is triggered when an element is moved, but it
doesn't know which element. The entire list is its parameter.
Conversely, reverteffect knows which element is being dragged, but it
doesn't know whether it's gone to a different position or not.
Conveniently, OnUpdate is called before reverteffect. My solution
involves using OnUpdate to add a temporary class to the list
enclosure. Then, reverteffect is used to test whether that class
exists. If it does, the class is removed and a function is called on
the moved element. If it doesn't, a different function can be called
on the dragged-but-not-moved element. Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<title>
script.aculo.us Sortable Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /
>
<script src="prototype.js" type="text/javascript"></script>
<script src="scriptaculous.js" type="text/javascript"></script>
<script type="text/javascript">
var moveStartEffect = function(element) {
element._opacity = Element.getOpacity(element);
Draggable._dragging[element] = true;
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:
0.7});
element.setStyle({backgroundColor:'#bfb'});
}
var moveRevertEffect = 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,
queue: {scope:'_draggable', position:'end'}
});
if (element.up().hasClassName('sortUpdate')) {
element.up().removeClassName('sortUpdate');
alert(
element.id + ' has been moved');
} else {
alert(
element.id + ' has not moved');
}
element.setStyle({backgroundColor:'#fff'});
}
</script>
<style>
div#testlist {
list-style-type:none;
margin:0;
padding:0;
}
div#testlist div.thingie {
background-color:#FFF;
width:200px;
font:12px Verdana;
padding:4px;
}
div#testlist div.thingie .over {
background-color:#fcb;
}
div#testlist div.thingie img {
float:left;
margin-right:8px;
cursor:move;
}
</style>
</head>
<body>
<h2>Drag and Drop Test</h2>
<div id="testlist">
<div class="thingie" id="item_1"><img src="img_UpDown.gif"
class="moveme" alt=""/> This is item No. 1</div>
<div class="thingie" id="item_2"><img src="img_UpDown.gif"
class="moveme" alt=""/> This is item No. 2</div>
<div class="thingie" id="item_3"><img src="img_UpDown.gif"
class="moveme" alt=""/> This is item No. 3</div>
<div class="thingie" id="item_4"><img src="img_UpDown.gif"
class="moveme" alt=""/> This is item No. 4</div>
<div class="thingie" id="item_5"><img src="img_UpDown.gif"
class="moveme" alt=""/> This is item No. 5</div>
<div class="thingie" id="item_6"><img src="img_UpDown.gif"
class="moveme" alt=""/> This is item No. 6</div>
</div>
<script type="text/javascript" language="javascript" charset="utf-8">
Sortable.create('testlist',
{ghosting:false,constraint:false,tag:'div',hoverclass:'over',
handle:'moveme',
starteffect:moveStartEffect, reverteffect:moveRevertEffect,
onUpdate: function(element) {
element.addClassName('sortUpdate');
}
});
</script>
</body>
</html>
On Sep 10, 9:19 pm, "Jon B." <
jbernha...@gmail.com> wrote:
> I'm trying to use thereverteffectoption on a sortable and it's not