Skip to content

Commit

Permalink
Merge pull request #148 from nlfurniss/normalize-event
Browse files Browse the repository at this point in the history
Use normalizeEvent so that addon works if app uses jQuery
  • Loading branch information
dgavey authored Nov 30, 2018
2 parents a1cbc34 + 7f3a5de commit 6e6b3af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
7 changes: 4 additions & 3 deletions addon/components/draggable-object-target.js
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down Expand Up @@ -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));
}
},

Expand Down
14 changes: 8 additions & 6 deletions addon/services/drag-coordinator.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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') {

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 6e6b3af

Please sign in to comment.