Unified · Split
| @@ -1,81 +1,66 @@ | ||
| 1 | −// TODO: This file was created by bulk-decaffeinate. | |
| 2 | −// Sanity-check the conversion and remove this comment. | |
| 3 | −/* | |
| 4 | − * decaffeinate suggestions: | |
| 5 | − * DS102: Remove unnecessary code created because of implicit returns | |
| 6 | − * DS206: Consider reworking classes to avoid initClass | |
| 7 | − * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md | |
| 8 | − */ | |
| 9 | −(function () { | |
| 10 | − let MIN = undefined; | |
| 11 | − let MAX = undefined; | |
| 12 | − app.views.Resizer = class Resizer extends app.View { | |
| 13 | − static initClass() { | |
| 14 | − this.className = "_resizer"; | |
| 1 | +app.views.Resizer = class Resizer extends app.View { | |
| 2 | + static className = "_resizer"; | |
| 15 | 3 | |
| 16 | − this.events = { | |
| 17 | − dragstart: "onDragStart", | |
| 18 | − dragend: "onDragEnd", | |
| 19 | − }; | |
| 4 | + static events = { | |
| 5 | + dragstart: "onDragStart", | |
| 6 | + dragend: "onDragEnd", | |
| 7 | + }; | |
| 20 | 8 | |
| 21 | − MIN = 260; | |
| 22 | − MAX = 600; | |
| 23 | − } | |
| 9 | + static MIN = 260; | |
| 10 | + static MAX = 600; | |
| 24 | 11 | |
| 25 | − static isSupported() { | |
| 26 | − return "ondragstart" in document.createElement("div") && !app.isMobile(); | |
| 27 | − } | |
| 12 | + static isSupported() { | |
| 13 | + return "ondragstart" in document.createElement("div") && !app.isMobile(); | |
| 14 | + } | |
| 28 | 15 | |
| 29 | − init() { | |
| 30 | − this.el.setAttribute("draggable", "true"); | |
| 31 | − this.appendTo($("._app")); | |
| 32 | − } | |
| 16 | + init() { | |
| 17 | + this.el.setAttribute("draggable", "true"); | |
| 18 | + this.appendTo($("._app")); | |
| 19 | + } | |
| 33 | 20 | |
| 34 | − resize(value, save) { | |
| 35 | − value -= app.el.offsetLeft; | |
| 36 | − if (!(value > 0)) { | |
| 37 | − return; | |
| 38 | − } | |
| 39 | − value = Math.min(Math.max(Math.round(value), MIN), MAX); | |
| 40 | − const newSize = `${value}px`; | |
| 41 | − document.documentElement.style.setProperty("--sidebarWidth", newSize); | |
| 42 | − if (save) { | |
| 43 | − app.settings.setSize(value); | |
| 44 | − } | |
| 21 | + resize(value, save) { | |
| 22 | + value -= app.el.offsetLeft; | |
| 23 | + if (!(value > 0)) { | |
| 24 | + return; | |
| 45 | 25 | } |
| 46 | − | |
| 47 | − onDragStart(event) { | |
| 48 | − event.dataTransfer.effectAllowed = "link"; | |
| 49 | − event.dataTransfer.setData("Text", ""); | |
| 50 | − $.on(window, "dragover", this.onDrag); | |
| 26 | + value = Math.min(Math.max(Math.round(value), Resizer.MIN), Resizer.MAX); | |
| 27 | + const newSize = `${value}px`; | |
| 28 | + document.documentElement.style.setProperty("--sidebarWidth", newSize); | |
| 29 | + if (save) { | |
| 30 | + app.settings.setSize(value); | |
| 51 | 31 | } |
| 32 | + } | |
| 33 | + | |
| 34 | + onDragStart(event) { | |
| 35 | + event.dataTransfer.effectAllowed = "link"; | |
| 36 | + event.dataTransfer.setData("Text", ""); | |
| 37 | + this.onDrag = this.onDrag.bind(this); | |
| 38 | + $.on(window, "dragover", this.onDrag); | |
| 39 | + } | |
| 52 | 40 | |
| 53 | − onDrag(event) { | |
| 54 | − const value = event.pageX; | |
| 55 | − if (!(value > 0)) { | |
| 56 | − return; | |
| 57 | − } | |
| 58 | − this.lastDragValue = value; | |
| 59 | − if (this.lastDrag && this.lastDrag > Date.now() - 50) { | |
| 60 | − return; | |
| 61 | − } | |
| 62 | − this.lastDrag = Date.now(); | |
| 63 | − this.resize(value, false); | |
| 41 | + onDrag(event) { | |
| 42 | + const value = event.pageX; | |
| 43 | + if (!(value > 0)) { | |
| 44 | + return; | |
| 64 | 45 | } |
| 46 | + this.lastDragValue = value; | |
| 47 | + if (this.lastDrag && this.lastDrag > Date.now() - 50) { | |
| 48 | + return; | |
| 49 | + } | |
| 50 | + this.lastDrag = Date.now(); | |
| 51 | + this.resize(value, false); | |
| 52 | + } | |
| 65 | 53 | |
| 66 | − onDragEnd(event) { | |
| 67 | − $.off(window, "dragover", this.onDrag); | |
| 68 | − let value = event.pageX || event.screenX - window.screenX; | |
| 69 | − if ( | |
| 70 | − this.lastDragValue && | |
| 71 | − !(this.lastDragValue - 5 < value && value < this.lastDragValue + 5) | |
| 72 | − ) { | |
| 73 | − // https://github.com/freeCodeCamp/devdocs/issues/265 | |
| 74 | − value = this.lastDragValue; | |
| 75 | − } | |
| 76 | − this.resize(value, true); | |
| 54 | + onDragEnd(event) { | |
| 55 | + $.off(window, "dragover", this.onDrag); | |
| 56 | + let value = event.pageX || event.screenX - window.screenX; | |
| 57 | + if ( | |
| 58 | + this.lastDragValue && | |
| 59 | + !(this.lastDragValue - 5 < value && value < this.lastDragValue + 5) | |
| 60 | + ) { | |
| 61 | + // https://github.com/freeCodeCamp/devdocs/issues/265 | |
| 62 | + value = this.lastDragValue; | |
| 77 | 63 | } |
| 78 | − }; | |
| 79 | − app.views.Resizer.initClass(); | |
| 80 | − return app.views.Resizer; | |
| 81 | −})(); | |
| 64 | + this.resize(value, true); | |
| 65 | + } | |
| 66 | +}; | |