From 7f3a5def03e8c4e61b1ba7e49a498df4784be624 Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Thu, 29 Nov 2018 18:59:53 -0800 Subject: [PATCH] Use normalizeEvent so that addon works if app uses jQuery --- addon/components/draggable-object-target.js | 7 ++++--- addon/services/drag-coordinator.js | 14 ++++++++------ package.json | 5 +++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/addon/components/draggable-object-target.js b/addon/components/draggable-object-target.js index 97c2c8d..740cec8 100644 --- a/addon/components/draggable-object-target.js +++ b/addon/components/draggable-object-target.js @@ -1,5 +1,6 @@ import Component from '@ember/component'; import Droppable from 'ember-drag-drop/mixins/droppable'; +import { normalizeEvent } from 'ember-jquery-legacy'; export default Component.extend(Droppable, { classNameBindings: ['overrideClass'], @@ -44,21 +45,21 @@ export default Component.extend(Droppable, { click(e) { let onClick = this.get('onClick'); if (onClick) { - onClick(e); + onClick(normalizeEvent(e)); } }, mouseDown(e) { let mouseDown = this.get('onMouseDown'); if (mouseDown) { - mouseDown(e); + mouseDown(normalizeEvent(e)); } }, mouseEnter(e) { let mouseEnter = this.get('onMouseEnter'); if (mouseEnter) { - mouseEnter(e); + mouseEnter(normalizeEvent(e)); } }, diff --git a/addon/services/drag-coordinator.js b/addon/services/drag-coordinator.js index c8670c5..ab463ef 100644 --- a/addon/services/drag-coordinator.js +++ b/addon/services/drag-coordinator.js @@ -1,6 +1,7 @@ import Service from '@ember/service'; import { alias } from '@ember/object/computed'; import { A } from '@ember/array'; +import { normalizeEvent } from 'ember-jquery-legacy'; function swapInPlace(items, a, b) { const aPos = items.indexOf(a); @@ -66,27 +67,28 @@ export default Service.extend({ }, draggingOver(event, emberObject) { + const normalizedEvent = normalizeEvent(event); const currentOffsetItem = this.get('currentOffsetItem'); - const pos = this.relativeClientPosition(emberObject.element, event); + const pos = this.relativeClientPosition(emberObject.element, normalizedEvent); const hasSameSortingScope = this.get('currentDragItem.sortingScope') === emberObject.get('sortingScope'); let moveDirection = false; if (!this.get('lastEvent')) { - this.set('lastEvent', event); + this.set('lastEvent', normalizedEvent); } - if (event.clientY < this.get('lastEvent').clientY) { + if (normalizedEvent.clientY < this.get('lastEvent').clientY) { moveDirection = 'up'; } - if (event.clientY > this.get('lastEvent').clientY) { + if (normalizedEvent.clientY > this.get('lastEvent').clientY) { moveDirection = 'down'; } - this.set('lastEvent', event); + this.set('lastEvent', normalizedEvent); if (!this.get('isMoving')) { - if (event.target !== this.get('currentDragEvent').target && hasSameSortingScope) { //if not dragging over self + if (normalizedEvent.target !== this.get('currentDragEvent').target && hasSameSortingScope) { //if not dragging over self if (currentOffsetItem !== emberObject) { if (pos.py > 0.33 && moveDirection === 'up' || pos.py > 0.33 && moveDirection === 'down') { diff --git a/package.json b/package.json index e9b506f..47f4f9f 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "ember-cli": "~3.3.0", "ember-cli-dependency-checker": "^2.0.0", "ember-cli-eslint": "^4.2.1", + "ember-cli-github-pages": "0.2.0", "ember-cli-htmlbars": "^2.0.1", "ember-cli-htmlbars-inline-precompile": "^1.0.0", "ember-cli-inject-live-reload": "^1.4.1", @@ -24,7 +25,6 @@ "ember-data": "^3.0.2", "ember-disable-prototype-extensions": "^1.1.2", "ember-export-application-global": "^2.0.0", - "ember-cli-github-pages": "0.2.0", "ember-load-initializers": "^1.1.0", "ember-maybe-import-regenerator": "^0.1.6", "ember-native-dom-helpers": "^0.4.1", @@ -51,7 +51,8 @@ "test": "tests" }, "dependencies": { - "ember-cli-babel": "^6.6.0" + "ember-cli-babel": "^6.6.0", + "ember-jquery-legacy": "^1.0.0" }, "ember-addon": { "configPath": "tests/dummy/config",