2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-10 17:26:30 +08:00

prettierjs formatting

This commit is contained in:
Jeff Wong 2018-06-29 10:02:28 -07:00
parent d79b54de6c
commit f4d77037d0
2 changed files with 38 additions and 34 deletions

View file

@ -112,20 +112,20 @@ export default Ember.Component.extend(PanEvents, {
},
_panOpenClose(offset, velocity, direction) {
const $timelineContainer = $(".timeline-container");
const maxOffset = parseInt($timelineContainer.css("height"));
direction === "close" ? offset += velocity : offset -= velocity;
direction === "close" ? (offset += velocity) : (offset -= velocity);
$timelineContainer.css("bottom", -offset);
if(offset > maxOffset) {
if (offset > maxOffset) {
this._collapseFullscreen();
}
else if(offset <= 0) {
} else if (offset <= 0) {
$timelineContainer.css("bottom", "");
}
else {
Ember.run.later(() => this._panOpenClose(offset, velocity, direction), 20);
} else {
Ember.run.later(
() => this._panOpenClose(offset, velocity, direction),
20
);
}
},
@ -138,27 +138,25 @@ export default Ember.Component.extend(PanEvents, {
const $centeredElement = $(document.elementFromPoint(center.x, center.y));
if ($centeredElement.parents(".timeline-scrollarea-wrapper").length) {
this.set("isPanning", false);
}
else {
} else {
this.set("isPanning", true);
}
},
panEnd(e) {
if(!this.get("isPanning")) {
if (!this.get("isPanning")) {
return;
}
this.set("isPanning", false);
if(this._shouldPanClose(e)) {
if (this._shouldPanClose(e)) {
this._panOpenClose(e.deltaY, 40, "close");
}
else {
} else {
this._panOpenClose(e.deltaY, 40, "open");
}
},
panMove(e) {
if(!this.get("isPanning")) {
if (!this.get("isPanning")) {
return;
}
$(".timeline-container").css("bottom", Math.min(0, -e.deltaY));

View file

@ -1,45 +1,50 @@
export default Ember.Mixin.create({
//velocity is pixels per ms
_panState: null,
didInsertElement() {
this.$().on("pointerdown", (e) => this._panStart(e))
.on("pointermove", (e) => this._panMove(e))
.on("pointerup", (e) => this._panMove(e))
.on("pointercancel", (e) => this._panMove(e));
this.$()
.on("pointerdown", e => this._panStart(e))
.on("pointermove", e => this._panMove(e))
.on("pointerup", e => this._panMove(e))
.on("pointercancel", e => this._panMove(e));
},
willDestroyElement() {
this.$().off("pointerdown")
this.$()
.off("pointerdown")
.off("pointerup")
.off("pointermove")
.off("pointercancel");
},
_calculateNewPanState(oldState, e) {
if(e.type === "pointerup" || e.type === "pointercancel") {
if (e.type === "pointerup" || e.type === "pointercancel") {
return oldState;
}
const newTimestamp = new Date().getTime();
const timeDiffSeconds = (newTimestamp - oldState.timestamp);
const timeDiffSeconds = newTimestamp - oldState.timestamp;
//calculate delta x, y, distance from START location
const deltaX = Math.round(e.clientX) - oldState.startLocation.x;
const deltaY = Math.round(e.clientY) - oldState.startLocation.y;
const distance = Math.round(Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)));
const distance = Math.round(
Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2))
);
//calculate velocity from previous event center location
const eventDeltaX = e.clientX - oldState.center.x;
const eventDeltaY = e.clientY - oldState.center.y;
const velocityX = eventDeltaX / timeDiffSeconds;
const velocityY = eventDeltaY / timeDiffSeconds;
const deltaDistance = Math.sqrt(Math.pow(eventDeltaX, 2) + Math.pow(eventDeltaY, 2));
const deltaDistance = Math.sqrt(
Math.pow(eventDeltaX, 2) + Math.pow(eventDeltaY, 2)
);
const velocity = deltaDistance / timeDiffSeconds;
return {
startLocation: oldState.startLocation,
center: {x: Math.round(e.clientX), y: Math.round(e.clientY)},
center: { x: Math.round(e.clientX), y: Math.round(e.clientY) },
velocity,
velocityX,
velocityY,
@ -53,8 +58,8 @@ export default Ember.Mixin.create({
_panStart(e) {
const newState = {
center: {x: Math.round(e.clientX), y: Math.round(e.clientY)},
startLocation: {x: Math.round(e.clientX), y: Math.round(e.clientY)},
center: { x: Math.round(e.clientX), y: Math.round(e.clientY) },
startLocation: { x: Math.round(e.clientX), y: Math.round(e.clientY) },
velocity: 0,
velocityX: 0,
velocityY: 0,
@ -71,14 +76,15 @@ export default Ember.Mixin.create({
const previousState = this.get("_panState");
const newState = this._calculateNewPanState(previousState, e);
this.set("_panState", newState);
if(previousState.start && "panStart" in this) {
if (previousState.start && "panStart" in this) {
this.panStart(newState);
}
else if((e.type === "pointerup" || e.type === "pointercancel") && "panEnd" in this) {
} else if (
(e.type === "pointerup" || e.type === "pointercancel") &&
"panEnd" in this
) {
this.panEnd(newState);
}
else if(e.type === "pointermove" && "panMove" in this) {
} else if (e.type === "pointermove" && "panMove" in this) {
this.panMove(newState);
}
},
}
});