Skip to content

Commit

Permalink
Merge branch 'master' into use-is-equal-util
Browse files Browse the repository at this point in the history
  • Loading branch information
dgavey authored Nov 7, 2019
2 parents 8bca63a + 5b9f259 commit 4edfb2c
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 455 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Ember.Controller.extend({
}
});
```
You can check out an example of this is action [here](http://mharris717.github.io/ember-drag-drop/)
You can check out an example of this is action [here](https://mharris717.github.io/ember-drag-drop/)

## Sorting of objects

Expand All @@ -193,13 +193,13 @@ An Example:
{{/sortable-objects}}
```

On drop of an item in the list, the sortableObjectList is re-ordered and the sortEndAction is fired unless the optional parameter 'enableSort' is false. You can check out an example of this is action [here](http://mharris717.github.io/ember-drag-drop/)
On drop of an item in the list, the sortableObjectList is re-ordered and the sortEndAction is fired unless the optional parameter 'enableSort' is false. You can check out an example of this is action [here](https://mharris717.github.io/ember-drag-drop/)

`useSwap` defaults to true and is optional. If you set it to false, then the sort algorithm will cascade the swap of items, pushing the values down the list. [See Demo](http://mharris717.github.io/ember-drag-drop/horizontal)
`useSwap` defaults to true and is optional. If you set it to false, then the sort algorithm will cascade the swap of items, pushing the values down the list. [See Demo](https://mharris717.github.io/ember-drag-drop/#/horizontal)

`inPlace` defaults to false and is optional. If you set it to true, then the original list will be mutated instead of making a copy.

`sortingScope` is optional and only needed if you have multiple lists on the screen that you want to share dragging between. [See Demo](http://mharris717.github.io/ember-drag-drop/multiple)
`sortingScope` is optional and only needed if you have multiple lists on the screen that you want to share dragging between. [See Demo](https://mharris717.github.io/ember-drag-drop/#/multiple)

**Note: It's important that you add the isSortable=true to each draggable-object or else that item will be draggable, but will not change the order of any item. Also if you set a custom sortingScope they should be the same for the sortable-object and the draggable-objects it contains.**

Expand Down
7 changes: 3 additions & 4 deletions addon/components/draggable-object-target.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 @@ -45,21 +44,21 @@ export default Component.extend(Droppable, {
click(e) {
let onClick = this.get('onClick');
if (onClick) {
onClick(normalizeEvent(e));
onClick(e);
}
},

mouseDown(e) {
let mouseDown = this.get('onMouseDown');
if (mouseDown) {
mouseDown(normalizeEvent(e));
mouseDown(e);
}
},

mouseEnter(e) {
let mouseEnter = this.get('onMouseEnter');
if (mouseEnter) {
mouseEnter(normalizeEvent(e));
mouseEnter(e);
}
},

Expand Down
15 changes: 7 additions & 8 deletions addon/services/drag-coordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Service from '@ember/service';
import { alias } from '@ember/object/computed';
import { A } from '@ember/array';
import { isEqual } from '@ember/utils';
import { normalizeEvent } from 'ember-jquery-legacy';


function indexOf(items, a) {
return items.findIndex(function (element) {
Expand Down Expand Up @@ -74,28 +74,27 @@ export default Service.extend({
},

draggingOver(event, emberObject) {
const normalizedEvent = normalizeEvent(event);
const currentOffsetItem = this.get('currentOffsetItem');
const pos = this.relativeClientPosition(emberObject.element, normalizedEvent);
const pos = this.relativeClientPosition(emberObject.element, event);
const hasSameSortingScope = this.get('currentDragItem.sortingScope') === emberObject.get('sortingScope');
let moveDirection = false;

if (!this.get('lastEvent')) {
this.set('lastEvent', normalizedEvent);
this.set('lastEvent', event);
}

if (normalizedEvent.clientY < this.get('lastEvent').clientY) {
if (event.clientY < this.get('lastEvent').clientY) {
moveDirection = 'up';
}

if (normalizedEvent.clientY > this.get('lastEvent').clientY) {
if (event.clientY > this.get('lastEvent').clientY) {
moveDirection = 'down';
}

this.set('lastEvent', normalizedEvent);
this.set('lastEvent', event);

if (!this.get('isMoving') && this.get('currentDragEvent')) {
if (normalizedEvent.target !== this.get('currentDragEvent').target && hasSameSortingScope) { //if not dragging over self
if (event.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
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.1.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-native-dom-helpers": "^0.4.1",
"ember-resolver": "^4.0.0",
"ember-source": "~3.3.0",
"ember-source-channel-url": "^1.0.1",
Expand All @@ -51,8 +50,7 @@
"test": "tests"
},
"dependencies": {
"ember-cli-babel": "7.1.3",
"ember-jquery-legacy": "^1.0.0"
"ember-cli-babel": "^7.1.3"
},
"ember-addon": {
"configPath": "tests/dummy/config",
Expand Down
11 changes: 7 additions & 4 deletions test-support/helpers/drag-drop.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {find, triggerEvent} from 'ember-native-dom-helpers';
import {find, triggerEvent} from '@ember/test-helpers';
import MockEvent from './mock-event';

async function dragOver(dropSelector, moves) {
moves = moves || [[{ clientX: 1, clientY: 1 }, dropSelector]];
return moves.forEach(async ([position, selector]) => {
let event = new MockEvent(position);

for (const move of moves) {
const position = move[0] || false;
const selector = move[1] || false;
const event = new MockEvent(position);
await triggerEvent(selector || dropSelector, 'dragover', event);
});
}
}

async function drop(dragSelector, dragEvent, options) {
Expand Down
17 changes: 8 additions & 9 deletions test-support/helpers/ember-drag-drop.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/* global triggerEvent , andThen */
import { run } from '@ember/runloop';
import $ from 'jquery';
import MockDataTransfer from '../../tests/helpers/data-transfer';

function drop($dragHandle, dropCssPath, dragEvent) {
let $dropTarget = $(dropCssPath);
let dropTarget = document.querySelector(dropCssPath);

if ($dropTarget.length === 0) {
if (dropTarget.length === 0) {
throw(`There are no drop targets by the given selector: '${dropCssPath}'`);
}

run(() => {
triggerEvent($dropTarget, 'dragover', MockDataTransfer.makeMockEvent());
triggerEvent(dropTarget, 'dragover', MockDataTransfer.makeMockEvent());
});

run(() => {
triggerEvent($dropTarget, 'drop', MockDataTransfer.makeMockEvent(dragEvent.dataTransfer.get('data.payload')));
triggerEvent(dropTarget, 'drop', MockDataTransfer.makeMockEvent(dragEvent.dataTransfer.get('data.payload')));
});

run(() => {
Expand All @@ -25,14 +24,14 @@ function drop($dragHandle, dropCssPath, dragEvent) {

export function drag(cssPath, options={}) {
let dragEvent = MockDataTransfer.makeMockEvent();
let $dragHandle = $(cssPath);
let dragHandle = document.querySelector(cssPath);

run(() => {
triggerEvent($dragHandle, 'mouseover');
triggerEvent(dragHandle, 'mouseover');
});

run(() => {
triggerEvent($dragHandle, 'dragstart', dragEvent);
triggerEvent(dragHandle, 'dragstart', dragEvent);
});

andThen(function() {
Expand All @@ -43,7 +42,7 @@ export function drag(cssPath, options={}) {

andThen(function() {
if (options.drop) {
drop($dragHandle, options.drop, dragEvent);
drop(dragHandle, options.drop, dragEvent);
}
});
}
5 changes: 2 additions & 3 deletions tests/helpers/assertions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* global equal findWithAssert click */
import { registerAsyncHelper } from '@ember/test';
import $ from 'jquery';

var f = function() {
registerAsyncHelper('hasActivePage', function(app, num, context) {
var i = 0;
findWithAssert(".pagination li.page-number", context).each(function() {
var li = $(this);
var li = this.element;
var active = num - 1 === i;
equal(li.hasClass('active'), active, "Has active page");
equal(li.classList.contains('active'), active, "Has active page");
i += 1;
});
});
Expand Down
Loading

0 comments on commit 4edfb2c

Please sign in to comment.