Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Merge pull request #189 from fivetanley/fix-link-to-click-events
Browse files Browse the repository at this point in the history
fix click events re-propogation on mobile
  • Loading branch information
stefanpenner committed Jan 19, 2015
2 parents ef838a7 + 519301c commit e726084
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/list-view/lib/virtual_list_scroller_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function synthesizeClick(e) {
var point = e.changedTouches[0],
target = point.target,
ev;
if (target && fieldRegex.test(target.tagName)) {
if (target && !fieldRegex.test(target.tagName)) {
ev = document.createEvent('MouseEvents');
ev.initMouseEvent('click', true, true, e.view, 1, point.screenX, point.screenY, point.clientX, point.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, null);
return target.dispatchEvent(ev);
Expand Down
51 changes: 40 additions & 11 deletions packages/list-view/tests/virtual_list_view_scrollerstart_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var css, view, helper, nextTopPosition;
helper = window.helper;
nextTopPosition = 0;

var hasTouch = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch;


function appendView() {
Ember.run(function() {
Expand All @@ -10,19 +12,19 @@ function appendView() {
}

function fireEvent(type, target) {
var hasTouch = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch,
events = hasTouch ? {
start: 'touchstart',
move: 'touchmove',
end: 'touchend'
} : {
start: 'mousedown',
move: 'mousemove',
end: 'mouseend'
},
e = document.createEvent('Event');
var events = hasTouch ? {
start: 'touchstart',
move: 'touchmove',
end: 'touchend'
} : {
start: 'mousedown',
move: 'mousemove',
end: 'mouseend'
};
var e = document.createEvent('Event');
if (hasTouch) {
e.touches = [{target: target}];
e.changedTouches = [{target: target}];
} else {
e.which = 1;
}
Expand Down Expand Up @@ -189,3 +191,30 @@ test("When pulling below zero, still fire a scrollerstart event", function() {
Ember.$(document).off("scrollerstart");
});

test("triggers a click event when no scroll happened", function(){
expect(1);

view = Ember.VirtualListView.create({
content: helper.generateContent(10),
height: 150,
rowHeight: 50
});

appendView();
var $childElement = view.$('.ember-list-item-view');
var childElement = $childElement[0];

$childElement.one('click', function(e){
ok(hasTouch, "click event synthesized for touch device only");
});

Ember.run(function(){
fireEvent('start', childElement);
fireEvent('end', childElement);
});

if (!hasTouch) {
ok(true, "click event not synthesized for non-touch device");
}
});

0 comments on commit e726084

Please sign in to comment.