mirror of https://github.com/freeCodeCamp/devdocs
parent
46d8d85ee2
commit
415a68b793
@ -1,81 +1,66 @@
|
|||||||
// TODO: This file was created by bulk-decaffeinate.
|
app.views.Resizer = class Resizer extends app.View {
|
||||||
// Sanity-check the conversion and remove this comment.
|
static className = "_resizer";
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS206: Consider reworking classes to avoid initClass
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
(function () {
|
|
||||||
let MIN = undefined;
|
|
||||||
let MAX = undefined;
|
|
||||||
app.views.Resizer = class Resizer extends app.View {
|
|
||||||
static initClass() {
|
|
||||||
this.className = "_resizer";
|
|
||||||
|
|
||||||
this.events = {
|
static events = {
|
||||||
dragstart: "onDragStart",
|
dragstart: "onDragStart",
|
||||||
dragend: "onDragEnd",
|
dragend: "onDragEnd",
|
||||||
};
|
};
|
||||||
|
|
||||||
MIN = 260;
|
static MIN = 260;
|
||||||
MAX = 600;
|
static MAX = 600;
|
||||||
}
|
|
||||||
|
|
||||||
static isSupported() {
|
static isSupported() {
|
||||||
return "ondragstart" in document.createElement("div") && !app.isMobile();
|
return "ondragstart" in document.createElement("div") && !app.isMobile();
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.el.setAttribute("draggable", "true");
|
this.el.setAttribute("draggable", "true");
|
||||||
this.appendTo($("._app"));
|
this.appendTo($("._app"));
|
||||||
}
|
}
|
||||||
|
|
||||||
resize(value, save) {
|
resize(value, save) {
|
||||||
value -= app.el.offsetLeft;
|
value -= app.el.offsetLeft;
|
||||||
if (!(value > 0)) {
|
if (!(value > 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
value = Math.min(Math.max(Math.round(value), MIN), MAX);
|
|
||||||
const newSize = `${value}px`;
|
|
||||||
document.documentElement.style.setProperty("--sidebarWidth", newSize);
|
|
||||||
if (save) {
|
|
||||||
app.settings.setSize(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
value = Math.min(Math.max(Math.round(value), Resizer.MIN), Resizer.MAX);
|
||||||
onDragStart(event) {
|
const newSize = `${value}px`;
|
||||||
event.dataTransfer.effectAllowed = "link";
|
document.documentElement.style.setProperty("--sidebarWidth", newSize);
|
||||||
event.dataTransfer.setData("Text", "");
|
if (save) {
|
||||||
$.on(window, "dragover", this.onDrag);
|
app.settings.setSize(value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onDragStart(event) {
|
||||||
|
event.dataTransfer.effectAllowed = "link";
|
||||||
|
event.dataTransfer.setData("Text", "");
|
||||||
|
this.onDrag = this.onDrag.bind(this);
|
||||||
|
$.on(window, "dragover", this.onDrag);
|
||||||
|
}
|
||||||
|
|
||||||
onDrag(event) {
|
onDrag(event) {
|
||||||
const value = event.pageX;
|
const value = event.pageX;
|
||||||
if (!(value > 0)) {
|
if (!(value > 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
this.lastDragValue = value;
|
|
||||||
if (this.lastDrag && this.lastDrag > Date.now() - 50) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.lastDrag = Date.now();
|
|
||||||
this.resize(value, false);
|
|
||||||
}
|
}
|
||||||
|
this.lastDragValue = value;
|
||||||
|
if (this.lastDrag && this.lastDrag > Date.now() - 50) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastDrag = Date.now();
|
||||||
|
this.resize(value, false);
|
||||||
|
}
|
||||||
|
|
||||||
onDragEnd(event) {
|
onDragEnd(event) {
|
||||||
$.off(window, "dragover", this.onDrag);
|
$.off(window, "dragover", this.onDrag);
|
||||||
let value = event.pageX || event.screenX - window.screenX;
|
let value = event.pageX || event.screenX - window.screenX;
|
||||||
if (
|
if (
|
||||||
this.lastDragValue &&
|
this.lastDragValue &&
|
||||||
!(this.lastDragValue - 5 < value && value < this.lastDragValue + 5)
|
!(this.lastDragValue - 5 < value && value < this.lastDragValue + 5)
|
||||||
) {
|
) {
|
||||||
// https://github.com/freeCodeCamp/devdocs/issues/265
|
// https://github.com/freeCodeCamp/devdocs/issues/265
|
||||||
value = this.lastDragValue;
|
value = this.lastDragValue;
|
||||||
}
|
|
||||||
this.resize(value, true);
|
|
||||||
}
|
}
|
||||||
};
|
this.resize(value, true);
|
||||||
app.views.Resizer.initClass();
|
}
|
||||||
return app.views.Resizer;
|
};
|
||||||
})();
|
|
||||||
|
Loading…
Reference in new issue