[780] | 1 | $.ui.plugin.add("draggable", "alsoDrag", {
|
---|
| 2 | start: function() {
|
---|
| 3 | var that = $(this).data("ui-draggable"),
|
---|
| 4 | o = that.options,
|
---|
| 5 | _store = function (exp) {
|
---|
| 6 | $(exp).each(function() {
|
---|
| 7 | var el = $(this);
|
---|
| 8 | el.data("ui-draggable-alsoDrag", {
|
---|
| 9 | top: parseInt(el.css("top"), 10),
|
---|
| 10 | left: parseInt(el.css("left"), 10)
|
---|
| 11 | });
|
---|
| 12 | });
|
---|
| 13 | };
|
---|
| 14 |
|
---|
| 15 | if (typeof(o.alsoDrag) === "object" && !o.alsoDrag.parentNode) {
|
---|
| 16 | if (o.alsoDrag.length) { o.alsoDrag = o.alsoDrag[0]; _store(o.alsoDrag); }
|
---|
| 17 | else { $.each(o.alsoDrag, function (exp) { _store(exp); }); }
|
---|
| 18 | }else{
|
---|
| 19 | _store(o.alsoDrag);
|
---|
| 20 | }
|
---|
| 21 | },
|
---|
| 22 | drag: function () {
|
---|
| 23 | var that = $(this).data("ui-draggable"),
|
---|
| 24 | o = that.options,
|
---|
| 25 | os = that.originalSize,
|
---|
| 26 | op = that.originalPosition,
|
---|
| 27 | delta = {
|
---|
| 28 | top: (that.position.top - op.top) || 0,
|
---|
| 29 | left: (that.position.left - op.left) || 0
|
---|
| 30 | },
|
---|
| 31 |
|
---|
| 32 | _alsoDrag = function (exp, c) {
|
---|
| 33 | $(exp).each(function() {
|
---|
| 34 | var el = $(this), start = $(this).data("ui-draggable-alsoDrag"), style = {},
|
---|
| 35 | css = ["top", "left"];
|
---|
| 36 |
|
---|
| 37 | $.each(css, function (i, prop) {
|
---|
| 38 | var sum = (start[prop]||0) + (delta[prop]||0);
|
---|
| 39 | style[prop] = sum || null;
|
---|
| 40 | });
|
---|
| 41 |
|
---|
| 42 | el.css(style);
|
---|
| 43 | });
|
---|
| 44 | };
|
---|
| 45 |
|
---|
| 46 | if (typeof(o.alsoDrag) === "object" && !o.alsoDrag.nodeType) {
|
---|
| 47 | $.each(o.alsoDrag, function (exp, c) { _alsoDrag(exp, c); });
|
---|
| 48 | }else{
|
---|
| 49 | _alsoDrag(o.alsoDrag);
|
---|
| 50 | }
|
---|
| 51 | },
|
---|
| 52 | stop: function() {
|
---|
| 53 | $(this).removeData("draggable-alsoDrag");
|
---|
| 54 | }
|
---|
| 55 | }); |
---|