Draggable handle : Drag Drop « Scriptaculous « JavaScript DHTML






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>

   
  








Related examples in the same category

1.Drag and drop: invert
2.Drag and drop to reorder
3.Drag and drop: ghosting effect
4.Drag and drop: hover class
5.Drag and drop: snap
6.Drag and drop: force to scroll
7.Drag and drop between two tables
8.Droppable target
9.Add delay to drag and drop
10.Ghosting vs. non-ghosting
11.Draggable with scroll bar