├── LICENSE.txt
├── README.markdown
├── example
├── reorder.html
├── simple.html
└── style.css
├── index.html
├── jquery.drag-drop.plugin.js
└── jquery.drag-drop.plugin.min.js
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2012 Mikael Plate, http://mikeplate.com
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in the
7 | Software without restriction, including without limitation the rights to use,
8 | copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 | Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | Drag and Drop, jQuery Plugin
2 | ============================
3 |
4 | Overview
5 | --------
6 |
7 | This is a jQuery plugin for handling drag and drop operations with transparent support for both mouse
8 | and touch events. This means that you will be able to use the exact same code for desktop and mobile
9 | web sites.
10 |
11 | Usage
12 | -----
13 |
14 | Include the JavaScript file jquery.drag-drop.plugin.js in your html page.
15 |
16 | ~~~~ html
17 |
18 |
19 | ~~~~
20 |
21 | The plugin is named "dragdrop" and can be applied to an element or a container of elements that should
22 | be draggable. You will probably also specify some options while applying the plugin.
23 |
24 | ~~~~ javascript
25 | $("#area").dragdrop();
26 | $("#area").dragdrop({ makeClone: true, dragClass: "whileDragging"});
27 | ~~~~
28 |
29 | Without any options, the default behaviour is to enable dragging of any elements inside the matched
30 | elements when dragdrop() is called and to enable dropping on any element that has the CSS class
31 | "drop" applied. But by using function callbacks like canDrag and canDrop, you can specify exactly
32 | what can be dragged and where it can be dropped. And you can also specify what actually happens on
33 | a drop with the function callback didDrop.
34 |
35 | If you have an element containing many draggable elements, you can either attach the plugin to
36 | each individual element inside the container or attach it to the single containing element and
37 | then implement canDrag to make sure that the correct child of the container is dragged.
38 |
39 | Options
40 | -------
41 |
42 | The plugin supports the following options when it is initialized for a source:
43 |
44 | * __makeClone__ can be true or false. Default is false. If true, the actual source element won't be the
45 | element that is dragged but rather a clone of it.
46 | * __sourceClass__ can be the name of a CSS class. This class is applied to the source element
47 | in its original position (if visible) while it is dragged.
48 | * __sourceHide__ can be true or false. When true, the original element is set to invisible while the
49 | dragging occurs.
50 | * __dragClass__ can be the name of a CSS class. If specified, it is applied to the element that is
51 | being dragged while the drag operation is active. Note that if makeClone is false, this is also
52 | the actual source element.
53 | * __canDropClass__ can be the name of a CSS class. If specified, will be applied to the droppable
54 | area element whenever a dragged element is hovering over it, to signify that the user can drop
55 | at this time.
56 | * __dropClass__ can be the name of a CSS class. This class name is used to identify droppable
57 | area elements. The default is "drop". If a callback function is specified under "canDrop", this
58 | class name has no effect.
59 | * __container__ can be a jQuery element of a container. If specified, elements dragged will not be able
60 | to move outside of that container.
61 | * __canDrag__ can be a callback function that returns true or false. You can use this callback if you'd
62 | like to apply the plugin to a larger container, and then only make specific elements inside that
63 | container draggable by returning true from the callback if you've determined the current element
64 | as eligable for dragging.
65 | * __canDrop__ can be a callback function that returns true or false. Return true if the dragged element
66 | can be dropped on the specified element. If this function is used, the "dropClass" setting has
67 | no effect.
68 | * __didDrop__ can be a callback function. If specified, it is assumed to take care of all operations
69 | and effects to occur after a successful drag and drop has been performed. Otherwise, the default
70 | operation is to restore the class on the source element and if makeClone is false the
71 | element will be appended as a child to the droppable element.
72 |
73 | License
74 | -------
75 |
76 | This software is released under the [MIT License](https://github.com/mikeplate/jquery-drag-drop-plugin/blob/master/LICENSE.txt).
77 |
78 |
--------------------------------------------------------------------------------
/example/reorder.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Drag and Drop jQuery Plugin Reorder Example
6 |
7 |
8 |
9 |
50 |
51 |
52 |
Drag any of letter boxes to the area below and note some different visuals and rules that can be specified as options and in stylesheets. Read more below about the different plugin customizations that is demonstrated.
52 |
53 |
A
54 |
Bb
55 |
C
56 |
D
57 |
E
58 |
F
59 |
60 |
61 |
G
62 |
H
63 |
I
64 |
J
65 |
K
66 |
L
67 |
68 |
69 |
M
70 |
N
71 |
O
72 |
P
73 |
Q
74 |
R
75 |
76 |
77 |
78 |
A-F shows the default behavior of dragging the original element around.
79 |
80 |
Works with compound elements as in the box "Bb"
81 |
82 |
G-L shows custom behavior of dragging a clone of the element and using a different css class for its appearence.
83 |
84 |
Plugin is attached to container element
85 |
Source element is hidden while dragging
86 |
Box "J" is not draggable
87 |
When drop area has 2 elements, no more dropped elements are accepted
88 |
89 |
M-R shows highlighting the drop area.
90 |
91 |
Dragging is confined to the containing element centered on the page
92 |
When dropped, text contents of drop area is concatenated with dropped letter
This jQuery plugin can handle both mouse- and touch-based drag and drop operations transparently. Its goal is to be simple to use without a lot of options. It is heavily based on style sheet class names and JavaScript callbacks for its customization.