Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to solve the problem if the dom object that have the have the class name different everytime #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Multi Draggable provides live and multi element draggable functionality to jQuer

Usage:

1. Can you used same way as you do for Draggable. In addition, you can add "group" option, which determines which group of elements to be dragged together.
1. Can you used same way as you do for Draggable. In addition, you can add "group" option as a jquery object or selector, which determines which group of elements to be dragged together.

Ex 1: $(".className").multiDraggable({ group: $(.className)});

Expand All @@ -15,15 +15,21 @@ Ex 2: $("#drag1").multiDraggable({ group: [$("#drag1"),$("#drag2") ]});

In this case, dragging #drag1, makes #drag2 drag along with it, even though #drag2 is not draggable.

Ex 3: (".className").multiDraggable({
group: $(.className),
Ex 3: $(".className").multiDraggable({
group: $(".className"),
startNative: function (event,ui) {},
stopNative : function (event,ui) {},
dragNative : function (event,ui) {}
});

You can use all events, options and methods of jQuery UI Draggable, except that
-'start' is now 'startNative'
-'drag' is now 'dragNative'
-'stop' is now 'stopNative'
- everything else remains the same.
- everything else remains the same.

Ex 3: $(".className").multiDraggable({ group: ".className" });

In this case , by parsing in a jquery selector string will drag the dom object that have the classs name when user start to drag.

Ex4: $(".className").multiDraggable("destroy") to restore to init.
57 changes: 42 additions & 15 deletions multidraggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,61 @@
(function ($) {
$.fn.multiDraggable = function (opts) {
var initLeftOffset = []
,initTopOffset = [];
,initTopOffset = [];

if(opts == "destroy"){
return this.each(function(){
$(this)
.draggable("destroy")
.unbind(".multiDraggable")
.data("init","");
});
}

return this.each (function (){
$(this).live("mouseover", function() {
$(this).bind("mouseover.multiDraggable", function() {
if (!$(this).data("init")) {
$(this).data("init", true).draggable(opts,{
start: function (event,ui) {
var pos = $(this).position();
$.each(opts.group || {}, function(key,value) {
var elemPos = $(value).position();
initLeftOffset[key] = elemPos.left - pos.left;
initTopOffset[key] = elemPos.top - pos.top;
});

if (typeof opts.group == "string"){
opts.group = $(opts.group);
}

opts.group.not($(this));

if(opts.group.length>0){
$.each(opts.group || {}, function(key,value) {
var elemPos = $(value).position();
initLeftOffset[key] = elemPos.left - pos.left;
initTopOffset[key] = elemPos.top - pos.top;
});
}
opts.startNative ? opts.startNative() : {};
},
drag: function(event,ui) {
var pos = $(this).offset();
$.each(opts.group || {}, function(key,value) {
$(value).offset({left: pos.left + initLeftOffset[key],
top: pos.top + initTopOffset[key]});
});

if(opts.group.length>0){
$.each(opts.group || {}, function(key,value) {
$(value).offset({left: pos.left + initLeftOffset[key],
top: pos.top + initTopOffset[key]});
});
}

opts.dragNative ? opts.dragNative() : {};
},
stop: function(event,ui) {
var pos = $(this).offset();
$.each(opts.group || {}, function(key,value) {
$(value).offset({left: pos.left + initLeftOffset[key],
top: pos.top + initTopOffset[key]});
});

if(opts.group.length>0){
$.each(opts.group || {}, function(key,value) {
$(value).offset({left: pos.left + initLeftOffset[key],
top: pos.top + initTopOffset[key]});
});
}

opts.stopNative ? opts.stopNative() : {};
},
});
Expand Down