Browse code

Add tom select npm package

Benjamin Roth authored on02/02/2023 12:00:30
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,62 @@
1
+/**
2
+* Tom Select v2.2.2
3
+* Licensed under the Apache License, Version 2.0 (the "License");
4
+*/
5
+
6
+/**
7
+ * Plugin: "drag_drop" (Tom Select)
8
+ * Copyright (c) contributors
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
11
+ * file except in compliance with the License. You may obtain a copy of the License at:
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
16
+ * ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ *
19
+ */
20
+function plugin () {
21
+  var self = this;
22
+  if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');
23
+  if (self.settings.mode !== 'multi') return;
24
+  var orig_lock = self.lock;
25
+  var orig_unlock = self.unlock;
26
+  self.hook('instead', 'lock', () => {
27
+    var sortable = $(self.control).data('sortable');
28
+    if (sortable) sortable.disable();
29
+    return orig_lock.call(self);
30
+  });
31
+  self.hook('instead', 'unlock', () => {
32
+    var sortable = $(self.control).data('sortable');
33
+    if (sortable) sortable.enable();
34
+    return orig_unlock.call(self);
35
+  });
36
+  self.on('initialize', () => {
37
+    var $control = $(self.control).sortable({
38
+      items: '[data-value]',
39
+      forcePlaceholderSize: true,
40
+      disabled: self.isLocked,
41
+      start: (e, ui) => {
42
+        ui.placeholder.css('width', ui.helper.css('width'));
43
+        $control.css({
44
+          overflow: 'visible'
45
+        });
46
+      },
47
+      stop: () => {
48
+        $control.css({
49
+          overflow: 'hidden'
50
+        });
51
+        var values = [];
52
+        $control.children('[data-value]').each(function () {
53
+          if (this.dataset.value) values.push(this.dataset.value);
54
+        });
55
+        self.setValue(values);
56
+      }
57
+    });
58
+  });
59
+}
60
+
61
+export { plugin as default };
62
+//# sourceMappingURL=plugin.js.map