| 1 |
import { IE11OrLess, Edge } from './BrowserInfo.js'; |
| 2 |
import { expando } from './utils.js'; |
| 3 |
import PluginManager from './PluginManager.js'; |
| 4 |
|
| 5 |
export default function dispatchEvent( |
| 6 |
{ |
| 7 |
sortable, rootEl, name, |
| 8 |
targetEl, cloneEl, toEl, fromEl, |
| 9 |
oldIndex, newIndex, |
| 10 |
oldDraggableIndex, newDraggableIndex, |
| 11 |
originalEvent, putSortable, extraEventProperties |
| 12 |
} |
| 13 |
) { |
| 14 |
sortable = (sortable || (rootEl && rootEl[expando])); |
| 15 |
if (!sortable) return; |
| 16 |
|
| 17 |
let evt, |
| 18 |
options = sortable.options, |
| 19 |
onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1); |
| 20 |
// Support for new CustomEvent feature |
| 21 |
if (window.CustomEvent && !IE11OrLess && !Edge) { |
| 22 |
evt = new CustomEvent(name, { |
| 23 |
bubbles: true, |
| 24 |
cancelable: true |
| 25 |
}); |
| 26 |
} else { |
| 27 |
evt = document.createEvent('Event'); |
| 28 |
evt.initEvent(name, true, true); |
| 29 |
} |
| 30 |
|
| 31 |
evt.to = toEl || rootEl; |
| 32 |
evt.from = fromEl || rootEl; |
| 33 |
evt.item = targetEl || rootEl; |
| 34 |
evt.clone = cloneEl; |
| 35 |
|
| 36 |
evt.oldIndex = oldIndex; |
| 37 |
evt.newIndex = newIndex; |
| 38 |
|
| 39 |
evt.oldDraggableIndex = oldDraggableIndex; |
| 40 |
evt.newDraggableIndex = newDraggableIndex; |
| 41 |
|
| 42 |
evt.originalEvent = originalEvent; |
| 43 |
evt.pullMode = putSortable ? putSortable.lastPutMode : undefined; |
| 44 |
|
| 45 |
let allEventProperties = { ...extraEventProperties, ...PluginManager.getEventProperties(name, sortable) }; |
| 46 |
for (let option in allEventProperties) { |
| 47 |
evt[option] = allEventProperties[option]; |
| 48 |
} |
| 49 |
|
| 50 |
if (rootEl) { |
| 51 |
rootEl.dispatchEvent(evt); |
| 52 |
} |
| 53 |
|
| 54 |
if (options[onName]) { |
| 55 |
options[onName].call(sortable, evt); |
| 56 |
} |
| 57 |
} |
| 58 |
|