Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
hthetiot committed Sep 19, 2017
2 parents d35c9d5 + 68a189d commit 70e06b5
Show file tree
Hide file tree
Showing 186 changed files with 4,451 additions and 3,201 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ log.txt

## Build
/dist
montage.dist.js
montage.min.js

## jsdoc
/doc
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# MontageJS

[![npm version](https://img.shields.io/npm/v/montage.svg?style=flat)](https://www.npmjs.com/package/montage)

[![Build Status](https://travis-ci.org/montagejs/montage.svg?branch=master)](http://travis-ci.org/montagejs/montage)

[![Analytics](https://ga-beacon.appspot.com/UA-35717912-2/montagejs/montage)](https://github.com/montagejs/montage)
Expand Down
16 changes: 15 additions & 1 deletion composer/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* @module montage/composer/composer
* @requires montage/core/target
*/
var Target = require("../core/target").Target;
var Target = require("../core/target").Target,
defaultEventManager = require("../core/event/event-manager").defaultEventManager;

/**
* The `Composer` helps to keep event normalization and calculation out of
Expand Down Expand Up @@ -69,6 +70,19 @@ exports.Composer = Target.specialize( /** @lends Composer# */ {
}
},

_shawdowRoot: {
value: null
},

shawdowRoot: {
get: function () {
if (!this._shawdowRoot) {
this._shawdowRoot = defaultEventManager.shawdowRootFromNode(this.element);
}
return this._shawdowRoot;
}
},


/**
* This property controls when the component will call this composer's
Expand Down
59 changes: 59 additions & 0 deletions composer/press-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,17 +693,35 @@ var PressComposer = exports.PressComposer = Composer.specialize(/** @lends Press
_addEventListeners: {
value: function () {
if (window.PointerEvent) {
if (this.shawdowRoot) {
this.shawdowRoot.addEventListener("pointerup", this, false);
this.shawdowRoot.addEventListener("pointermove", this, false);
this.shawdowRoot.addEventListener("pointercancel", this, false);
}

document.addEventListener("pointerup", this, false);
document.addEventListener("pointermove", this, false);
document.addEventListener("pointercancel", this, false);

} else if (window.MSPointerEvent && window.navigator.msPointerEnabled) {
if (this.shawdowRoot) {
this.shawdowRoot.addEventListener("MSPointerUp", this, false);
this.shawdowRoot.addEventListener("MSPointerMove", this, false);
this.shawdowRoot.addEventListener("MSPointerCancel", this, false);
}

document.addEventListener("MSPointerUp", this, false);
document.addEventListener("MSPointerMove", this, false);
document.addEventListener("MSPointerCancel", this, false);

} else {
if (this._observedPointer === "mouse") {
if (this.shawdowRoot) {
this.shawdowRoot.addEventListener("mouseup", this, false);
this.shawdowRoot.addEventListener("mousemove", this, false);
this.shawdowRoot.addEventListener("dragstart", this, false);
}

document.addEventListener("mouseup", this, false);
document.addEventListener("mousemove", this, false);

Expand All @@ -713,6 +731,12 @@ var PressComposer = exports.PressComposer = Composer.specialize(/** @lends Press
this._element.addEventListener("dragstart", this, false);

} else {
if (this.shawdowRoot) {
this.shawdowRoot.addEventListener("touchend", this, false);
this.shawdowRoot.addEventListener("touchcancel", this, false);
this.shawdowRoot.addEventListener("touchmove", this, false);
}

document.addEventListener("touchend", this, false);
document.addEventListener("touchcancel", this, false);
document.addEventListener("touchmove", this, false);
Expand All @@ -721,6 +745,11 @@ var PressComposer = exports.PressComposer = Composer.specialize(/** @lends Press

var wheelEventName = typeof window.onwheel !== "undefined" || typeof window.WheelEvent !== "undefined" ?
"wheel" : "mousewheel";

if (this.shawdowRoot) {
this.shawdowRoot.addEventListener(wheelEventName, this, true);
this.shawdowRoot.addEventListener("scroll", this, true);
}

document.addEventListener(wheelEventName, this, true);
document.addEventListener("scroll", this, true);
Expand All @@ -730,26 +759,51 @@ var PressComposer = exports.PressComposer = Composer.specialize(/** @lends Press
_removeEventListeners: {
value: function () {
if (window.PointerEvent) {
if (this.shawdowRoot) {
this.shawdowRoot.removeEventListener("pointerup", this, false);
this.shawdowRoot.removeEventListener("pointermove", this, false);
this.shawdowRoot.removeEventListener("pointercancel", this, false);
}

document.removeEventListener("pointerup", this, false);
document.removeEventListener("pointermove", this, false);
document.removeEventListener("pointercancel", this, false);

} else if (window.MSPointerEvent && window.navigator.msPointerEnabled) {
if (this.shawdowRoot) {
this.shawdowRoot.removeEventListener("MSPointerUp", this, false);
this.shawdowRoot.removeEventListener("MSPointerMove", this, false);
this.shawdowRoot.removeEventListener("MSPointerCancel", this, false);
}

document.removeEventListener("MSPointerUp", this, false);
document.removeEventListener("MSPointerMove", this, false);
document.removeEventListener("MSPointerCancel", this, false);

} else {
if (this._observedPointer === "mouse") {
if (this.shawdowRoot) {
this.shawdowRoot.removeEventListener("mouseup", this, false);
this.shawdowRoot.removeEventListener("mousemove", this, false);
this.shawdowRoot.removeEventListener("dragstart", this, false);
}

document.removeEventListener("mouseup", this, false);
document.removeEventListener("mousemove", this, false);

// Needed to cancel the press because once a drag is started
// no mouse events are fired
// http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#initiate-the-drag-and-drop-operation
this._element.removeEventListener("dragstart", this, false);


} else {
if (this.shawdowRoot) {
this.shawdowRoot.removeEventListener("touchend", this, false);
this.shawdowRoot.removeEventListener("touchcancel", this, false);
this.shawdowRoot.removeEventListener("touchmove", this, false);
}

document.removeEventListener("touchend", this, false);
document.removeEventListener("touchcancel", this, false);
document.removeEventListener("touchmove", this, false);
Expand All @@ -758,6 +812,11 @@ var PressComposer = exports.PressComposer = Composer.specialize(/** @lends Press

var wheelEventName = typeof window.onwheel !== "undefined" || typeof window.WheelEvent !== "undefined" ?
"wheel" : "mousewheel";

if (this.shawdowRoot) {
this.shawdowRoot.removeEventListener(wheelEventName, this, true);
this.shawdowRoot.removeEventListener("scroll", this, true);
}

document.removeEventListener(wheelEventName, this, true);
document.removeEventListener("scroll", this, true);
Expand Down
214 changes: 214 additions & 0 deletions composer/rotation-composer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/**
* @module ./rotation-composer.reel
* @requires montage/composer/composer
*/
var Composer = require("./composer").Composer,
TranslateComposer = require("./translate-composer").TranslateComposer;

/**
* @class RotationComposer
* @extends Composer
*/
exports.RotationComposer = Composer.specialize(/** @lends RotationComposer# */ {

/**
Dispatched when a rotation is started
@event rotationStart
@memberof RotationComposer
@param {RotationEvent} event
*/

/**
Dispatched when a rotation changes
@event rotation
@memberof RotationComposer
@param {RotationEvent} event
*/


/**
Unit for dispatched angles. Options: radians and degrees
Radians are the default as it is the standard in angular measures
To think about: should it accept "deg" as degrees to be equivalent to CSS notation?
*/
_unit: {
value: "radians"
},

unit: {
get: function () {
return this._unit;
},
set: function (value) {
if (value === "degrees") {
this._unit = "degrees";
} else {
this._unit = "radians";
}
}
},

constructor: {
value: function RotationComposer() {
this.super();
this._translateComposer = new TranslateComposer();
this._translateComposer.hasMomentum = false;
this._translateComposer.hasBouncing = false;
}
},

// Load/unload

load: {
value: function() {
this.component.addComposerForElement(this._translateComposer, this.element);
this._translateComposer.load();
this._translateComposer.addEventListener("translateStart", this, false);
this._translateComposer.addEventListener("translateEnd", this, false);
this._translateComposer.addEventListener("translate", this, false);
}
},

unload: {
value: function() {
}
},

handleTranslateStart: {
value: function() {
var start = this._translateComposer.pointerStartEventPosition,
deltaX = start.pageX - this.center.pageX,
deltaY = start.pageY - this.center.pageY;

this._translateComposer.translateX = start.pageX;
this._translateComposer.translateY = start.pageY;
this._previousAngle = Math.atan2(deltaY, deltaX);
this._deltaAngle = 0;
this._dispatchRotateStart();
}
},

handleTranslateEnd: {
value: function() {
this._dispatchRotateEnd();
}
},

handleTranslate: {
value: function(event) {
var deltaX = event.translateX - this.center.pageX,
deltaY = event.translateY - this.center.pageY,
currentAngle = Math.atan2(deltaY, deltaX),
deltaAngle = currentAngle - this._previousAngle;

if (deltaAngle > Math.PI) {
deltaAngle -= Math.PI * 2;
} else {
if (deltaAngle < -Math.PI) {
deltaAngle += Math.PI * 2;
}
}
this.angleInRadians += deltaAngle;
this._deltaAngle = deltaAngle;
this._previousAngle = currentAngle;
this._dispatchRotate();
}
},

angleInRadians: {
value: 0
},

_deltaAngle: {
value: 0
},

_dispatchRotateStart: {
value: function() {
var event = document.createEvent("CustomEvent");

event.initCustomEvent("rotateStart", true, true, null);
event.unit = this._unit;
if (this._unit === "radians") {
event.rotation = this.angleInRadians;
event.deltaRotation = this._deltaAngle;
} else {
event.rotation = (this.angleInRadians * 180) / Math.PI;
event.deltaRotation = (this._deltaAngle * 180) / Math.PI;
}
this.dispatchEvent(event);
}
},

_dispatchRotate: {
value: function() {
var event = document.createEvent("CustomEvent");

event.initCustomEvent("rotate", true, true, null);
event.unit = this._unit;
if (this._unit === "radians") {
event.rotation = this.angleInRadians;
event.deltaRotation = this._deltaAngle;
} else {
event.rotation = (this.angleInRadians * 180) / Math.PI;
event.deltaRotation = (this._deltaAngle * 180) / Math.PI;
}
this.dispatchEvent(event);
}
},

_dispatchRotateEnd: {
value: function() {
var event = document.createEvent("CustomEvent");

event.initCustomEvent("rotateEnd", true, true, null);
event.unit = this._unit;
event.deltaRotation = 0;
if (this._unit === "radians") {
event.rotation = this.angleInRadians;
} else {
event.rotation = (this.angleInRadians * 180) / Math.PI;
}
this.dispatchEvent(event);
}
},

// To review: I would call this axisCoordinates or similar
center: {
value: null
},

_start: {
value: null
},

_translateComposer: {
value: null
},

animateMomentum: {
get: function () {
return this._translateComposer.animateMomentum;
},
set: function (value) {
this._translateComposer.animateMomentum = !!value;
}
},

/**
* Whether to keep translating after the user has releases the cursor.
* @type {boolean}
* @default true
*/
hasMomentum: {
get: function () {
return this._translateComposer.hasMomentum;
},
set: function (value) {
this._translateComposer.hasMomentum = !!value;
}
}

});
Loading

0 comments on commit 70e06b5

Please sign in to comment.