aboutsummaryrefslogtreecommitdiffstats
path: root/library/Sortable/src/EventDispatcher.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-08-03 07:12:35 +0000
committerMario <mario@mariovavti.com>2021-08-03 07:12:35 +0000
commitcddc0217724f1a7661014d50e4c940e623a0c2dc (patch)
treef24595d659adbb7d1e5d2e8e6dcd829b093887bb /library/Sortable/src/EventDispatcher.js
parent571bae9d1c07bb08270163a314c91c138b42e62f (diff)
downloadvolse-hubzilla-cddc0217724f1a7661014d50e4c940e623a0c2dc.tar.gz
volse-hubzilla-cddc0217724f1a7661014d50e4c940e623a0c2dc.tar.bz2
volse-hubzilla-cddc0217724f1a7661014d50e4c940e623a0c2dc.zip
Apps drag and drop feature
Diffstat (limited to 'library/Sortable/src/EventDispatcher.js')
-rw-r--r--library/Sortable/src/EventDispatcher.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/library/Sortable/src/EventDispatcher.js b/library/Sortable/src/EventDispatcher.js
new file mode 100644
index 000000000..e47cb5809
--- /dev/null
+++ b/library/Sortable/src/EventDispatcher.js
@@ -0,0 +1,57 @@
+import { IE11OrLess, Edge } from './BrowserInfo.js';
+import { expando } from './utils.js';
+import PluginManager from './PluginManager.js';
+
+export default function dispatchEvent(
+ {
+ sortable, rootEl, name,
+ targetEl, cloneEl, toEl, fromEl,
+ oldIndex, newIndex,
+ oldDraggableIndex, newDraggableIndex,
+ originalEvent, putSortable, extraEventProperties
+ }
+) {
+ sortable = (sortable || (rootEl && rootEl[expando]));
+ if (!sortable) return;
+
+ let evt,
+ options = sortable.options,
+ onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
+ // Support for new CustomEvent feature
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
+ evt = new CustomEvent(name, {
+ bubbles: true,
+ cancelable: true
+ });
+ } else {
+ evt = document.createEvent('Event');
+ evt.initEvent(name, true, true);
+ }
+
+ evt.to = toEl || rootEl;
+ evt.from = fromEl || rootEl;
+ evt.item = targetEl || rootEl;
+ evt.clone = cloneEl;
+
+ evt.oldIndex = oldIndex;
+ evt.newIndex = newIndex;
+
+ evt.oldDraggableIndex = oldDraggableIndex;
+ evt.newDraggableIndex = newDraggableIndex;
+
+ evt.originalEvent = originalEvent;
+ evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
+
+ let allEventProperties = { ...extraEventProperties, ...PluginManager.getEventProperties(name, sortable) };
+ for (let option in allEventProperties) {
+ evt[option] = allEventProperties[option];
+ }
+
+ if (rootEl) {
+ rootEl.dispatchEvent(evt);
+ }
+
+ if (options[onName]) {
+ options[onName].call(sortable, evt);
+ }
+}