Current location: Hot Scripts Forums » General Web Coding » JavaScript » Add "Handles" to these draggable boxes?

Add "Handles" to these draggable boxes?

Reply
  #1 (permalink)  
Old 10-21-09, 12:32 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,653
Thanks: 0
Thanked 21 Times in 21 Posts
If you need the aElts array for some other part of the program, than I have added it to the script.
But you must understand that the aElts array has nothing to do with the drag&drop functions.
I have merely added it to the script for other purposes you may have, but otherwise it is only adding time to the script and serves no purpose to the script.
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Drag, Snap and Sort</title>
<link rel="stylesheet" type="text/css" href="../../newwalterzorn.css">
<style>
#dragItemsContainer
{
 width:200px;
 padding:10px;
 padding-bottom:5px;
 border:1px solid #000;
 background:#ddd;
 }
.commonStyle
{
 position:relative;
 width:200px;
 height:15px;
 margin-bottom:5px;
 font-size:12px;
 }
#lyr0{background:red;}
#lyr1{background:green;}
#lyr2{background:blue;}
#lyr3{background:yellow;}
#lyr4{background:purple;}
</style>
</head>
<body>
<script type="text/javascript" src="wz_dragdrop.js"></script>
<div id="dragItemsContainer">
 <div class="commonStyle" id="lyr0">Item 1</div>
 <div class="commonStyle" id="lyr1">Item 2</div>
 <div class="commonStyle" id="lyr2">Item 3</div>
 <div class="commonStyle" id="lyr3">Item 4</div>
 <div class="commonStyle" id="lyr4">Item 5</div>
<div>
<script type="text/javascript">
<!--
SET_DHTML(CURSOR_MOVE,"lyr0","lyr1","lyr2","lyr3","lyr4");

var sElementPosX,sElementPosY,sElementName,dElementName,dropTarget,picElementPos,dropElementPos;
var aElts = new Array("lyr0","lyr1","lyr2","lyr3","lyr4");
function my_PickFunc(){
 sElementPosX=dd.obj.x;
 sElementPosY=dd.obj.y;
 sElementName=dd.obj.name;
 for(var i=0;i<aElts.length;i++){if(sElementName == aElts[i]){picElementPos = i;}}
}
function my_DropFunc(){
 dropTarget=dd.obj.getEltBelow();
 dropTarget!=null?swapElements():restoreElement();
 dElementName=dropTarget.name;
 for(var i=0;i<aElts.length;i++){if(dElementName == aElts[i]){dropElementPos = i;}}
 arrange_aElts_Elements();
}
function swapElements(){
 dd.obj.moveTo(dropTarget.x,dropTarget.y);
 dd.elements[dropTarget.name].moveTo(sElementPosX,sElementPosY);
}
function restoreElement(){
 dd.obj.moveTo(sElementPosX,sElementPosY);
}
function arrange_aElts_Elements()
{
 var tempName1 = aElts[picElementPos];
 var tempName2 = aElts[dropElementPos];
 aElts[picElementPos] = tempName2;
 aElts[dropElementPos] = tempName1;
 }
-->
</script>
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 10-21-09 at 12:41 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to job0107 For This Useful Post:
End User (10-21-09)
  #2 (permalink)  
Old 10-21-09, 08:56 AM
End User's Avatar
End User End User is online now
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 2,833
Thanks: 13
Thanked 10 Times in 9 Posts
Quote:
Originally Posted by job0107 View Post
If you need the aElts array for some other part of the program, than I have added it to the script.
But you must understand that the aElts array has nothing to do with the drag&drop functions.
I have merely added it to the script for other purposes you may have, but otherwise it is only adding time to the script and serves no purpose to the script.
Thank you for adding that.....yes, I know the aElts array is separate from the D&D functions and not part of the actual script.

Out of curiosity, how would you determine the order of the elements if you didn't use something like the aElts array? I was trying to find all of the vertical element positions (dd.elements.foo.y) and use those then determine the sorting order that way, but I wasn't having much luck with it.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-21-09, 09:39 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,653
Thanks: 0
Thanked 21 Times in 21 Posts
Quote:
Originally Posted by End User View Post

Out of curiosity, how would you determine the order of the elements if you didn't use something like the aElts array? I was trying to find all of the vertical element positions (dd.elements.foo.y) and use those then determine the sorting order that way, but I wasn't having much luck with it.
Everything I checked gave the original order.
I couldn't find anything that would produce the changed order.
So using the aElts array seemed the only logical solution.
Using the x&y coordinates of the elements would require more programming then just swapping elements in an array.
And besides, after your array is setup the way you want it, there are a lot of function that you can use that are very efficient.
__________________
Jerry Broughton

Last edited by job0107; 10-21-09 at 09:48 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to job0107 For This Useful Post:
End User (10-21-09)
  #4 (permalink)  
Old 10-21-09, 10:21 AM
End User's Avatar
End User End User is online now
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 2,833
Thanks: 13
Thanked 10 Times in 9 Posts
Quote:
Originally Posted by job0107 View Post
Everything I checked gave the original order.
I couldn't find anything that would produce the changed order.
So using the aElts array seemed the only logical solution.
That's what I figured- I couldn't find any native function that exposed the new, rearranged order. That's why the aElts array was important to me.


Quote:
Originally Posted by job0107 View Post
Using the x&y coordinates of the elements would require more programming then just swapping elements in an array.
Yep...in fact, it required so much that it basically became somewhat of a death march for me.

Quote:
Originally Posted by job0107 View Post
And besides, after your array is setup the way you want it, there are a lot of function that you can use that are very efficient.
Walter Zorn's library is pretty slick, lots of powerful stuff in there for layer control, resizing, dragging, opacity, etc etc. I'm going to be experimenting with adding new elements on the fly, which looks like it should be pretty straightforward. (Famous last words...)
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Multi script PayPal add to cart order form Tito1 JavaScript 5 02-23-09 05:21 AM
Read from file, add to list Saturn Job Offers & Assistance 10 02-08-09 11:00 PM
Add images & search boxes in header & body to pulldowns hightechredneck JavaScript 0 09-17-08 01:11 PM
Add another two fields blinn_shade JavaScript 1 10-15-07 11:35 PM
Alter Table Help DDRcasey PHP 0 06-14-05 01:08 AM


All times are GMT -5. The time now is 11:04 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.