From f7376e9597e277cf12905f929ee3e7513e45bd9d Mon Sep 17 00:00:00 2001 From: jr-k Date: Wed, 17 Jul 2024 18:07:02 +0200 Subject: [PATCH] better explr --- data/www/js/lib/jquery-multidraggable.js | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 data/www/js/lib/jquery-multidraggable.js diff --git a/data/www/js/lib/jquery-multidraggable.js b/data/www/js/lib/jquery-multidraggable.js new file mode 100755 index 0000000..c91ca3e --- /dev/null +++ b/data/www/js/lib/jquery-multidraggable.js @@ -0,0 +1,55 @@ +/** + * JQuery MultiDraggable Plugin + * + * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) + * + * Written by Sudheer Someshwara + * + * MultiDraggable is a jQuery plugin which extends jQuery UI Draggable to add multi drag and live functionality. + * + **/ +(function ($, undefined) { + $.fn.multiDraggable = function (opts) { + var initLeftOffset = [] + , initTopOffset = []; + return this.each(function () { + $(this).on("mouseover", function () { + if (!$(this).data("init")) { + $(this).data("init", true).draggable(opts, { + start: function (event, ui) { + const pos = $(this).position(); + $.each($(opts.group) || {}, function (key, value) { + $(value).addClass('ui-draggable-dragging'); + const elemPos = $(value).position(); + initLeftOffset[key] = elemPos.left - pos.left; + initTopOffset[key] = elemPos.top - pos.top; + }); + opts.startNative ? opts.startNative() : {}; + }, + drag: function (event, ui) { + const pos = $(this).offset(); + $.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) { + const pos = $(this).offset(); + $.each($(opts.group) || {}, function (key, value) { + $(value).removeClass('ui-draggable-dragging'); + $(value).offset({ + left: pos.left + initLeftOffset[key], + top: pos.top + initTopOffset[key] + }); + }); + opts.stopNative ? opts.stopNative() : {}; + }, + }); + } + }); + }); + }; +}(jQuery)); \ No newline at end of file