Skip to content

Commit

Permalink
Fixes TouchEvent problem in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
rlamana committed Feb 13, 2015
1 parent ab37c4b commit c9caf69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/ventus/tpl/window.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 12 additions & 16 deletions src/ventus/wm/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ define([
function(Emitter, Promise, View, WindowTemplate) {
'use strict';

function isTouchEvent(e) {
return !!window.TouchEvent && (e.originalEvent instanceof window.TouchEvent);
}

function convertMoveEvent(e) {
return isTouchEvent(e) ? e.originalEvent.changedTouches[0] : e.originalEvent;
}

var Window = function (options) {
this.signals = new Emitter();

Expand Down Expand Up @@ -92,11 +100,7 @@ function(Emitter, Promise, View, WindowTemplate) {

slots: {
move: function(e) {
/* global TouchEvent */
var isTouchEvent = (e.originalEvent instanceof TouchEvent),
event = isTouchEvent ?
e.originalEvent.changedTouches[0] :
e.originalEvent;
var event = convertMoveEvent(e);

if(!this.enabled || !this.movable) {
return;
Expand Down Expand Up @@ -178,11 +182,7 @@ function(Emitter, Promise, View, WindowTemplate) {
},

'button.wm-resize mousedown': function(e) {
/* global TouchEvent */
var isTouchEvent = (e.originalEvent instanceof TouchEvent),
event = isTouchEvent ?
e.originalEvent.changedTouches[0] :
e.originalEvent;
var event = convertMoveEvent(e);

if(!this.enabled || !this.resizable) {
return;
Expand All @@ -201,14 +201,10 @@ function(Emitter, Promise, View, WindowTemplate) {

space: {
'mousemove': function(e) {
/* global TouchEvent */
var isTouchEvent = (e.originalEvent instanceof TouchEvent),
event = isTouchEvent ?
e.originalEvent.changedTouches[0] :
e.originalEvent;
var event = convertMoveEvent(e);

// Fix #20. Mousemove outside browser
if (!isTouchEvent && e.which !== 1) {
if (!isTouchEvent(e) && e.which !== 1) {
this._moving && this._stopMove();
this._resizing && this._stopResize();
}
Expand Down

0 comments on commit c9caf69

Please sign in to comment.