Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    JavaScript


Advertisements:










Using YUI Drag And Drop


I am using YUI's Drag and Drop utility to add some drag & drop functionality to a CMS I'm building.

This works just fine and is very easy to set up, but the thing I'm wondering about, how do I restrict the dragging? In other words; how can I make sure an element gets dragged within the borders of, say, some div and not outside them?


View 2 Replies (Posted: Jan 25, 2007, 03:28)

Sponsored Links:

Related Forum Messages For JavaScript category:
Drag And Drop: Submit A File From Drag And Drop With Regular Form?
I've got a form that uploads files (post), with a few <input type='file'/> tags, and I want users to be able to drag and drop files onto the web page, eg, from their desktop. When they do this, the files should be added to the form as file input tags

It shouldn't matter where they drop it on the page (and I am already handling this drop event on the page)

When I have the File object for the file they dragged, how can I add it to the form as an <input type='file'/>? Or, is there another way to add it to the form so it'll be sent when the form is submitted, as if it was selected using the file input itself?

Posted: Jun 25 11 at 1:22

View 2 Replies!   View Related
JQuery :: UI Drag And Drop - Hide The Originating Container When The Drag Starts?
Im building a popup image gallery where a user can drag an image from the popup div and drop it elsewhere on the page.

The popup gallery is an overlay div (using css) so there are no iframes or anything as such.

I've successfully implemented the drag and drop using JQUERY UI, however what I want is -

Whenever a user drags an image out of the gallery popup div, the popup div should hide/fadeout and the image can be dropped elsewhere. But the problem is, as soon as I hide the gallery popup div (originating container), my helper clone also disappears. (however the drop can still be made, but I lose the visual feedback)

I've tried moving the position of the gallery div to -999,-999 (without hiding it) but even that hides my visual feedback clone (the helper)

Posted: Dec 5 11 at 16:43

View 1 Replies!   View Related
JQuery :: Using UI Drag-and-drop: Changing The Dragged Element On Drop?
When using jQuery UI draggables and droppables, how do you change the dragged-and-dropped element on drop? I am trying to drag one DIV to another sortable DIV. On drop, I'd like to change the classes on the dropped DIV and change its innerHTML content.

After reading various StackOverflow questions, my code looks like this:

$(".column").droppable({
accept: '.element-dragging',
drop: function(event, ui) {
if ($(ui.draggable).hasClass("elemtxt")) {

[Code].....

A full copy of my code is located at [URL]

Posted: Jul 22 09 at 0:37

View 1 Replies!   View Related
HTML5 Drag And Drop Events - DragLeave Fires Before Drop
In drag and drop the dragLeave event sometimes fires before the drop event.

This is causing problems because the target is getting the listeners in dragEnter with dragLeave and drop removing the listeners. If dragLeave fires before drop, then there is no listener for the drop.

I think the reason has something to do with another contra-intuitive: the dragEnter sometimes fires multiple times for the same target, even with propagation off. With multiple dragEnters, one would spawn a drop while the others would spawn a dragLeave. If this is the case, perhaps I could associate the dragLeave with the dragEnter - but I see no means of that coordination.

function dragEnter( e ) {
e.stopPropatation();
// is multiple fires of dragEnter for same cell
if( curCell == this ) return;

[Code]....

If the "clearing listeners" were not performed, the next step would have been:

drop: this=e8

Posted: Apr 2 11 at 6:42

View 1 Replies!   View Related
Dojo Abort Drag / Drop Operation In Dnd / Drop / Before
I wanted to know if there is a way I can abort the default drop operation in dojo. I am doing some custom manipulation in the function,

dojo.subscribe("/dnd/drop/before", function(source, nodes, iscopy){
//Custom manipulation
});

And from this function, I want to cancel the drop, similar to what happens when you press the Esc Key?

Posted: Jul 14 10 at 18:06

View 1 Replies!   View Related
JQuery :: Drag And Drop - Get DROP Left And Top Position?
I need to know where the user drops the element. How do I echo both the .left and .top position on drop?

<div id="Draggable" style="position: fixed;">
<img src="images/door1.jpg" id="door">
</div>
<script type="text/javascript">

[Code]....

Posted: Sep 2 at 18:42

View 3 Replies!   View Related
JQuery :: Drag And Drop - Checking For A Drop Outside A Droppable?
I'm trying to test whether a jQuery draggable is being dropped outside of a legal droppable. This would normally be solved 90% of the time by reverting the draggable, but I don't want to do that. Instead, I want to do one thing if the draggable is dropped onto a droppable (working great!), and something else if it is dropped outside of all possible droppables (currently getting the better of me!).

In a nutshell:

jQuery('#droppable').droppable(
{
accept: '#draggable',
drop: function(event, ui)

[Code].....

Posted: Nov 11 11 at 10:40

View 2 Replies!   View Related
Jquery :: Accordion Drag And Drop To A Drop Area?
I am trying to implement a feature with jquery accordion much like the MS Outlook accordion feature where, when I minimize the accordion,there is an area at the bottom where the accordions are put and when I maximize the height of the accordion the elements are taken back to accordion container.

So as an alternate solutions I thought of doing that like drag and drop. I want to put a div at the bottom of the accordion where I can drop the current accordion elements. The thing I want to implement and have done some parts are:

I've made accordion elements sortable so that I can drag and drop to that div I've made a div where I want to put/drop the accordion elements,hence made that dropapble When I drop from accordion container to bottom container, it should remove that from accordion and put the dropped object into that bottom div but show as icon to users. By bottom container is also sortable/draggable and I can put back the accordion element from bottom to top accordion elements. When I drop from bottom to top, bottom will remove that element and top will append that.

I have already started to implement and here is the code in JSFIDDLE Custom accordion D&N.

when I drop the jquery ui.element object how to store that in that div and show as icon. And the points 3-5 above.

Posted: Nov 23 11 at 10:29

View 1 Replies!   View Related
Cancel Drop Event In YUI Drag And Drop Utility?
We are using drag & drop utility between one source and multiple targets. We have a restriction that one of the target can only have one child element while the other ones can have multiple items.

I have tried subscribing dragDropEvent of the proxy item and returning false in case the destination target has multiple child elements, with out much luck. code...

Posted: May 10 09 at 16:58

View 1 Replies!   View Related
Jquery :: Drag And Drop Ui Drop Box Limit?
I want to limit a droppable to only take 1 draggable at a time

Example: I have 3 draggable boxes and 2 droppable target boxes. I am trying to to limit the drop boxes to only accept item at a time. I do not want to disable the drop box i just want to limit how many you can drop on it to only 1. I want a solution thats expandable. I am also trying to keep track where you drop the box.

I redid my demo: [URL]

Posted: Nov 4 11 at 2:59

View 1 Replies!   View Related
Drag And Drop Breaks After First Drop?
So, what it does: You can successfully drag something anywhere, but when you click it again, it resets to its original position (I don't know why), and when you try to drag it again, as soon as your cursor touches the object it disappears (I don't know why). why it is happening and how to fix it!

// JavaScript Document
var posX;
var posY;
var element;

[Code]....

the html is a simple (position is set to relative):

<p id="square" onmousedown="drag(event)">meep</p>

EDIT: This is the first time I've written javascript code and would like to learn the basics, which is why I am not using a library.

Posted: 02-20-2011, 09:47 PM

View 1 Replies!   View Related
How To Drag And Drop
I can't figure out how to drag and drop. I've followed some tutorials but no success. I use Firefox as my browser. Any tutorial you would recommend?

Posted: 03-06-2010, 12:24 AM

View 2 Replies!   View Related
Drag From Outside Web Browser And Drop
As the subject says, is this possible. I'd like to drag a file onto a button and have the filename accesable within that pages javascript.

Posted: July 23rd, 2005

View 1 Replies!   View Related
Drag & Drop With Pictures
I build my first Drag & Drop with JavaScript and I would like to drag
the pictures when I click on it.

When I create a normal div tag with some text the script works, but
when I put a image in the div tag it works not correctly.

Here is my Code... I integrated three pictures and one text, then you
can see the differences.

a part of my html site:

Posted: December 23rd, 2006

View 2 Replies!   View Related
Emulating Drag And Drop?
I'm in the middle of creating a project management system for our office, and I was wondering if javascript is capable of emulating drag and drop? This would allow me to do some cool stuff.

Posted: July 20th, 2005

View 1 Replies!   View Related
Drag And Drop Within A Text?
Is it possible to drop html element into a text at mouse pointer position, using JQuery?

I've been implementing song text editor (yet another...) with drag-and-drop guitar chord positioning. I would click a chord, drag it and drop between lyrics letters. Lyrics are contentEditable div.

My quick solution was surrounding each letter with a <span class="letter"> tag and make entire song (letters + chords) sortable. Sortable has cancel attribute for span.letter, so you cannot move letters :-). But it implies maintaining this text structure while editing lyrics and seems not to be so efficient.

Can I achieve this in a more simple way, particularily without surrounding each letter with a tag?

Posted: Dec 21 10 at 19:27

View 1 Replies!   View Related
Drag And Drop For Prototype?
I was wondering if there are any good drag and drop plugins for Prototype. I'm well aware of the great drag and drop plugin available for jQuery, but I'm looking for a plugin for Prototype.

Posted: Jan 3 at 21:26

View 2 Replies!   View Related
Drag And Drop Library
After a good deal of internal development, I've decided this library will do more good in the wild. It works in IE6, Safari 2, Opera 9, Firefox 1.5, and IE5.5/Mac (sort of buggy behavior with text selection in IE5.5/Mac though). It should also work in virtually any version of Gecko, Opera 6+, Safari 1, and IE5+ (anybody who wants to test those, feel free). The scripting is highly efficient, and only exposes two functions globally, Draggable and Droppable. The below code is licensed under the LGPL, though it is available under other licenses per request.

Let me know if you have any issues with it - this is something I'm interested in maintaining. Also, compared to other scripts, such as script.tac.ulo.us, this is much less code (lots of whitespace/comments could be taken out), and more widely supported across browsers.

Other than below, it can be found here: http://www.jasonkarldavis.com/scripts/dragdropable/dragdropable.html

// dragdropable.js (1.0.1)
//Copyright (C) 2006 Jason Davis, www.jasonkarldavis.com
//This code is licensed under the LGPL:
//http://www.gnu.org/licenses/lgpl.html
//
// Documentation:
//This script exposes two global variables, Draggable and Droppable. To make an
//element draggable, simply call `Draggable(element)`. This sets the necessary
//CSS properties and event handlers. It also overrides the addEventListener and
//and attachEvent methods (if present) to include the following events:
//onstart(When the element begins dragging)
//ondrag(When the element is being dragged)
//onstop(When the element has stopped dragging)
//You may also assign element.onstart, element.ondrag, and element.onstart to
//add event listeners.
//Lastly, if you need to physically prevent an element from dragging, you may
//call event.preventDefault() from within the onstart handler.
//
//To make an element droppable (have things dragged onto it), call
//`Droppable(element)`. This sets the necessary event handlers and coordinate
//searches. Once again, it overrides addEventListener and attachEvent to
//include the following events:
//onhover(When another element has been dragged over the element)
//ondrop(When another element has been dropped onto the element)
//onunhover(When another element has been dragged off the element)
//As before, you may also set element.onhover, element.ondrop, and
//element.onunhover directly.
//To remove all drop points from the current session, call `Droppable.reset()`.
//
//The event object is also extended with the following properties:
//dragTarget(The element being dragged)
//dropTarget(The element being dropped onto)
//
// Known bugs:
//* removeEventListener and detachEvent do not work with the custom events.
//Workaround: Use direct assignment (element.onevent) instead.
//* There is no way to remove a single drop point.
//Workaround: Call Droppable.reset(), then reinitialize the other drop points.
//* There is no way to remove dragging from an element.
//Workaround: element.onstart = function(event) { event.preventDefault() }
//* Changing position of droppable elements after initialization breaks drop
//Workaround: Static droppables are much faster than moving ones. Either call
//Droppable.reset() and reinitialize often, or ask the author to modify the
//script to account for this (and accept the resulting slowdown)


function Draggable(element) {
// initialize drag variable
var x = 0, y = 0, oldMouseMove, oldMouseUp;

// get style properties of element
var computedStyle;
if (typeof document.defaultView != "undefined" && typeof document.defaultView.getComputedStyle != "undefined")
computedStyle = document.defaultView.getComputedStyle(element, "");
else if (typeof element.currentStyle != "undefined")
computedStyle = element.currentStyle;
else
computedStyle = element.style;

// prep element for dragging
if (computedStyle.position == "static" || computedStyle.position == "")
element.style.position = "relative";
if (computedStyle.zIndex == "auto" || computedStyle.zIndex == "")
element.style.zIndex = 1;
element.style.left = isNaN(parseInt(computedStyle.left)) ? "0" : computedStyle.left;
element.style.top = isNaN(parseInt(computedStyle.top )) ? "0" : computedStyle.top;

// default event listeners
function onstart(event) {
event.dragTarget = element;
x = event.clientX;
y = event.clientY;

// Override preventDefault
event.preventDefault = (function(original) {
return function() {
element.ownerDocument.onmousemove = oldMouseMove;
element.ownerDocument.onmouseup = oldMouseUp;
original.call(event);
}
})(event.preventDefault || function() {});

if (element.onstart) element.onstart(event);
}
function ondrag(event) {
event.dragTarget = element;
element.style.left = parseInt(element.style.left) + event.clientX - x + "px";
element.style.top = parseInt(element.style.top) + event.clientY - y + "px";
x = event.clientX;
y = event.clientY;
Droppable.query(event);

if (element.ondrag) element.ondrag(event);
}
function onstop(event) {
event.dragTarget = element;
Droppable.query(event);

if (element.onstop) element.onstop(event);
}

// make listeners active
element.onmousedown = (function(oldMouseDown) {
return function() {
// Call old listener
if (oldMouseDown) oldMouseDown.apply(this, arguments);

// Store old event handlers
oldMouseMove = this.ownerDocument.onmousemove;
oldMouseUp = this.ownerDocument.onmouseup;

// Setup events
this.ownerDocument.onmousemove = function() {
// Call old listener
if (oldMouseMove) oldMouseMove.apply(this, arguments);

// Call ondrag
ondrag.call(element, arguments[0] || event);

return false;
}
this.ownerDocument.onmouseup = function() {
// Call old listener
if (oldMouseUp) oldMouseUp.apply(this, arguments);

// Call onstop
onstop.call(element, arguments[0] || event);

// Restore old event listeners
this.onmousemove = oldMouseMove;
this.onmouseup = oldMouseUp;

return false;
}

// Call onstart
onstart.call(this, arguments[0] || event);

return false;
}
})(element.onmousedown);

// override event attachers
if (element.addEventListener)
element.addEventListener = (function(original) {
return function(event, listener, useCapture) {
switch (event) {
case "start":
onstart = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onstart);
break;
case "drag":
ondrag = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(ondrag);
break;
case "stop":
onstop = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onstop);
break;
default:
original.call(element, event, listener, useCapture);
}
}
})(element.addEventListener);

if (element.attachEvent)
element.attachEvent = (function(original) {
return function(event, listener) {
switch (event) {
case "onstart":
onstart = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onstart);
break;
case "ondrag":
ondrag = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(ondrag);
break;
case "onstop":
onstop = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onstop);
break;
default:
original.call(element, event, listener);
}
}
})(element.attachEvent);


if (window.attachEvent)
window.attachEvent("onbeforeunload", function() {
onstart = ondrag = onstop = element.onmousedown = element.addEventListener = element.attachEvent = null;
element = null;
});
}


// initialize Droppable in the global scope
var Droppable;

(function() {
if (document.getBoxObjectFor) {
function getOffset(element) {
var box = document.getBoxObjectFor(element);
return { x: box.x, y: box.y };
}
}
else if (document.all && navigator.appName == "Microsoft Internet Explorer" && !window.opera) {
function getOffset(element) {
var range = document.body.createTextRange();
range.moveToElementText(element);
var rect = range.getBoundingClientRect();
return { x: rect.left, y: rect.top };
}
}
else {
function getOffset(element) {
var accumulator = arguments[1] || { x: 0, y: 0 };
if (element && element != document.body) {
accumulator.x += element.offsetLeft;
accumulator.y += element.offsetTop;
return getOffset(element.offsetParent, accumulator);
}
else {
return accumulator;
}
}
}

// initialize private pointers to current target information
var cTarget = null, cHover = null, cUnhover = null, cDrop = null;
function hotSpots(x,y) {
cTarget = cHover = cUnhover = cDrop = null;
}

// declare Droppable within the private scope
Droppable = function(element) {
// Calculate offset
var offset = getOffset(element);

// Calculate other edge offset
var edge = { x: offset.x + element.offsetWidth, y: offset.y + element.offsetHeight };

// Assign a finder function
hotSpots = (function(old) {
return function(x,y) {
if (offset.x <= x && x <= edge.x && offset.y <= y && y <= edge.y) {
cTarget = element;
cHover = onhover;
cUnhover = onunhover;
cDrop = ondrop;
}
else {
old(x,y);
}
}
})(hotSpots);

// default event listeners
function onhover(event) {
event.dropTarget = element;
if (element.onhover) element.onhover(event);
}
function onunhover(event) {
event.dropTarget = element;
if (element.onunhover) element.onunhover(event);
}
function ondrop(event) {
event.dropTarget = element;
if (element.ondrop) element.ondrop(event);
}

// override event attachers
if (element.addEventListener)
element.addEventListener = (function(original) {
return function(event, listener, useCapture) {
switch (event) {
case "hover":
onhover = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onhover);
break;
case "unhover":
onunhover = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onunhover);
break;
case "drop":
ondrop = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(ondrop);
break;
default:
original.call(element, event, listener, useCapture);
}
}
})(element.addEventListener);

if (element.attachEvent)
element.attachEvent = (function(original) {
return function(event, listener) {
switch (event) {
case "onhover":
onhover = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onhover);
break;
case "onunhover":
onunhover = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(onunhover);
break;
case "ondrop":
ondrop = (function(old) {
return function(event) { old.call(element,event); listener.call(element,event); }
})(ondrop);
break;
default:
original.call(element, event, listener);
}
}
})(element.attachEvent);


if (window.attachEvent)
window.attachEvent("onbeforeunload", function() {
hotSpots = onhover = onunhover = ondrop = element.addEventListener = element.attachEvent = cTarget = cHover = cUnhover = cDrop = null;
element = null;
});
}

// Setup a query method
Droppable.query = function(event) {
var oTarget = cTarget,
oHover = cHover,
oUnhover = cUnhover,
oDrop = cDrop;

var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft,
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;


hotSpots(event.clientX + scrollLeft, event.clientY + scrollTop);

switch (event.type) {
case "mousemove": // onhover & onunhover
if (oTarget != null && oTarget != cTarget)
oUnhover.call(oTarget, event);
if (oTarget == null && cTarget != null)
cHover.call(cTarget, event);
break;
case "mouseup": // ondrop
if (cTarget != null) {
cUnhover.call(cTarget, event);
cDrop.call(cTarget, event);
}
break;
}
}

Droppable.reset = function() {
hotSpots = function(x,y) {
cTarget = cHover = cUnhover = cDrop = null;
}
hotSpots();
}
})();

// Fix the function prototype for IE5/Mac
if (typeof Function.prototype.apply == "undefined")
Function.prototype.apply = function(scope, args) {
if (!args) args = [];
var index = 0, result;
do { -- index } while (typeof scope[index] != "undefined");
scope[index] = this;

switch (args.length) {
case 0:
result = scope[index]();
break;
case 1:
result = scope[index](args[0]);
break;
case 2:
result = scope[index](args[0], args[1]);
break;
case 3:
result = scope[index](args[0], args[1], args[2]);
break;
case 4:
result = scope[index](args[0], args[1], args[2], args[3]);
break;
default:
result = scope[index](args[0], args[1], args[2], args[3], args[4]);
break;
}

delete scope[index];
return result;
}

if (typeof Function.prototype.call == "undefined")
Function.prototype.call = function(scope) {
var args = new Array(Math.max(arguments.length-1, 0));
for (var i = 1; i < arguments.length; i++)
args[i-1] = arguments[i];
return this.apply(scope, args);
}

Posted: 01-11-2006, 03:23 AM

View 7 Replies!   View Related
Create A Drag And Drop Box?
I really like the drag-drop box from bbc.co.uk, but I don't know how to do it. Can anybody help me to create a page like that?

Posted: Jan 28th, 2010

View 1 Replies!   View Related
Drag & Drop From Scratch?
Anyone know a good 'Drag&Drop' tutorial? i mean those tutorials that teach you how to implement the drag-and-drop-elements from scratch. All what i found so far were tutorial(s) teaching you how to use an existing library. I'll eventually use a library, but i'd rather learn it's basics first and implement it myself the first time.

Posted: Mar 27, 2006, 05:15

View 4 Replies!   View Related
Drag & Drop Tree
Does anyone know of a publicly available drag & drop tree script? Google only turned up a bunch of nice tree scripts, but none of them have drag & drop functionality.

Posted: Mar 28, 2006, 19:36

View 3 Replies!   View Related
Drag 'n' Drop Project
Here is a small test for all those hardcore JavaScript programmers. Is it possible to drag'n'drop a text/image element (eg. A or IMG tag) from one (I)FRAME to another (I)FRAME. This is easy & possible with IE's proprietary ondrag events. However the question is, is there a work-around using standard W3C/Firefox onmousedown, onmouseup, etc. events only? Code:

Posted: Jun 27, 2006, 06:53

View 2 Replies!   View Related
Using Drag And Drop In Websites?
As i would now like to develop better webapps then the basic php and javascript ones that i currently create, i would like to know how web devs create some of the amazing websites that i have used over the past few years.

For example, On some of the websites that i visit they have the ability to drag and drop items from a palette onto the webpage. I am thinking mostly about some of the online diagramming tools that i have seen. How do they do this because i am currently baffled.

I would like to start creating these types of websites and currently i have no idea how to proceed. I first want to create some small tester websites that allow just very basic drag and drop use. If anyone could point me in the right directions in terms of links to tutorials or library's that have this feature then i would be most grateful.

Posted: Oct 16 10 at 16:08

View 5 Replies!   View Related
Php - Drag And Drop Into A Textbox?
I have a list of people on the left hand side of a page, this list is populated by PHP.

Each person is in their own div (this can be changed but I thought div's may be easier to work with). I want to be able to drag any one of these people onto a textbox, thus entering their name into that textbox.

Also to make it more awkward, I don't really want to be using jQuery or prototype. Or any of the others really.

How would I check to see if something has been dragged on top of a textbox? And how would I get the ID of that element?

What I don't know is how to check if something has been dragged on top of the textbox (input box, not text area, but that's no big issue.) I know there would never be a magical param like onDragOnto="" but hopefully that will show you what I mean

Posted: Nov 13 11 at 1:09

View 1 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved