Skip to content

Commit

Permalink
Merge pull request #1 from kvas-damian/Fix-touch-devices
Browse files Browse the repository at this point in the history
Fix touch devices
  • Loading branch information
Damian Jóźwiak committed Jan 15, 2016
2 parents 1bb4772 + a520b68 commit 5061b3d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
7 changes: 4 additions & 3 deletions addon/system/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ var Target = Ember.Object.extend(Ember.Evented, {
focusout: bind(this, 'blur'),
mouseenter: bind(this, 'mouseEnter'),
mouseleave: bind(this, 'mouseLeave'),
mousedown: bind(this, 'mouseDown')
mousedown: bind(this, 'mouseDown'),
touchstart: bind(this, 'mouseDown')
};

if (get(target, 'element')) {
Expand Down Expand Up @@ -267,7 +268,7 @@ var Target = Ember.Object.extend(Ember.Evented, {

var eventManager = this.eventManager;
eventManager.mouseup = bind(this, 'mouseUp');
$(document).on('mouseup', eventManager.mouseup);
$(document).on('mouseup touchend', eventManager.mouseup);

evt.preventDefault();
}
Expand All @@ -279,7 +280,7 @@ var Target = Ember.Object.extend(Ember.Evented, {
mouseUp: function (evt) {
// Remove mouseup event
var eventManager = this.eventManager;
$(document).off('mouseup', eventManager.mouseup);
$(document).off('mouseup touchend', eventManager.mouseup);
eventManager.mouseup = null;

var label = labelForEvent(evt);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-pop-over",
"version": "0.1.30",
"version": "0.1.31",
"description": "A constraint-based pop-over component for ember apps",
"directories": {
"doc": "doc",
Expand Down Expand Up @@ -47,4 +47,4 @@
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
}
45 changes: 43 additions & 2 deletions tests/acceptance/events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import startApp from '../helpers/start-app';
import mouseUp from '../helpers/mouse-up';
import simpleClick from '../helpers/simple-click';
import mouseDown from '../helpers/mouse-down';
import touchStart from '../helpers/touch-start';
import touchEnd from '../helpers/touch-end';
import mouseEnter from '../helpers/mouse-enter';
import mouseLeave from '../helpers/mouse-leave';
import focus from '../helpers/focus';
Expand All @@ -21,7 +23,7 @@ module('Acceptance: Events', {
});

test('on="click"', function() {
expect(6);
expect(9);
visit('/');

simpleClick("#click");
Expand Down Expand Up @@ -59,10 +61,33 @@ test('on="click"', function() {
andThen(function () {
ok(find(".pop-over-container:visible").length === 1);
});

simpleClick("#click");
andThen(function () {
ok(find(".pop-over-container:visible").length === 0);
});

touchStart("#click");
andThen(function () {
ok(find(".pop-over-container:visible").length === 1);
});

andThen(function () {
var defer = Ember.RSVP.defer();
later(defer, 'resolve', 400);
return defer.promise;
});

touchEnd("#click");
andThen(function () {
ok(find(".pop-over-container:visible").length === 1);
});


});

test('on="click hold"', function() {
expect(4);
expect(6);
visit('/');

mouseDown("#click-hold");
Expand All @@ -81,6 +106,22 @@ test('on="click hold"', function() {
ok(find(".pop-over-container:visible").length === 0);
});

touchStart("#click-hold");
andThen(function () {
ok(find(".pop-over-container:visible").length === 1);
});

andThen(function () {
var defer = Ember.RSVP.defer();
later(defer, 'resolve', 400);
return defer.promise;
});

touchStop("#click-hold");
andThen(function () {
ok(find(".pop-over-container:visible").length === 0);
});

simpleClick("#click-hold");
andThen(function () {
ok(find(".pop-over-container:visible").length === 1);
Expand Down
3 changes: 3 additions & 0 deletions tests/helpers/touch-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function (selector) {
triggerEvent(selector, "touchend");
}
3 changes: 3 additions & 0 deletions tests/helpers/touch-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function (selector) {
triggerEvent(selector, "touchstart");
}

0 comments on commit 5061b3d

Please sign in to comment.