Added new custom version of event.js. Added event listeners for shake, drag and orientation change.

Custom version available: https://github.com/rykerwilliams/Event.js
This commit is contained in:
rykerwilliams 2013-09-23 10:10:40 -04:00
parent 888f324e46
commit 88aa0df407
4 changed files with 43 additions and 1775 deletions

File diff suppressed because one or more lines are too long

View file

@ -42,10 +42,22 @@
_this.__onTransformGesture(e, s);
};
this._onDrag = function(e, s) {
_this.__onDrag(e, s);
};
this._onMouseWheel = function(e, s) {
_this.__onMouseWheel(e, s);
};
this._onOrientationChange = function(e,s) {
_this.__onOrientationChange(e,s);
};
this._onShake = function(e,s) {
_this.__onShake(e,s);
};
addListener(fabric.window, 'resize', this._onResize);
if (fabric.isTouchSupported) {
@ -54,6 +66,9 @@
if (typeof Event !== 'undefined' && 'add' in Event) {
Event.add(this.upperCanvasEl, 'gesture', this._onGesture);
Event.add(this.upperCanvasEl, 'drag', this._onDrag);
Event.add(this.upperCanvasEl, 'orientation', this._onOrientationChange);
Event.add(this.upperCanvasEl, 'shake', this._onShake);
}
}
else {

View file

@ -28,6 +28,26 @@
this.fire('touch:gesture', {target: target, e: e, self: self});
},
/**
* Method that defines actions when an Event.js drag is detected.
*
* @param e Event object by Event.js
* @param self Event proxy object by Event.js
*/
__onDrag: function(e, self) {
this.fire('touch:drag', {e: e, self: self});
},
/**
* Method that defines actions when an Event.js orientation event is detected.
*
* @param e Event object by Event.js
* @param self Event proxy object by Event.js
*/
__onOrientationChange: function(e, self) {
this.fire('touch:orientation', {e: e, self: self});
},
/**
* Scales an object by a factor
* @param s {Number} The scale factor to apply to the current scale level

View file

@ -978,17 +978,22 @@
if (!this.interactive) return this;
removeListener(fabric.window, 'resize', this._onResize);
if (fabric.isTouchSupported) {
removeListener(this.upperCanvasEl, 'touchstart', this._onMouseDown);
removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
if (typeof Event !== 'undefined' && 'remove' in Event) {
Event.remove(this.upperCanvasEl, 'gesture', this._onGesture);
Event.remove(this.upperCanvasEl, 'drag', this._onDrag);
Event.remove(this.upperCanvasEl, 'orientation', this._onOrientationChange);
Event.remove(this.upperCanvasEl, 'shake', this._onShake);
}
}
else {
removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
removeListener(fabric.window, 'resize', this._onResize);
removeListener(this.upperCanvasEl, 'mousewheel', this._onMouseWheel);
}
return this;
},