Skip to content

Commit

Permalink
🔥 Remove legacy customisability from browser-spring
Browse files Browse the repository at this point in the history
  • Loading branch information
kierandrewett committed Jan 12, 2024
1 parent cfdbe10 commit 11f7a45
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 116 deletions.
8 changes: 0 additions & 8 deletions components/widgets/content/browser-spring.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@ browser-spring {
justify-content: center;
align-items: center;
user-select: none;
}

browser-spring[customising] {
display: flex;
-moz-window-dragging: no-drag;
outline: 2px dashed;
outline-offset: -6px;
border-radius: 8px;
}
109 changes: 1 addition & 108 deletions components/widgets/content/browser-spring.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

class BrowserSpring extends MozHTMLElement {
_customising = false;

/**
* Determines the current customising state for the spring
*/
get customising() {
return this._customising;
}

set customising(val) {
this.toggleAttribute("customising", val);
this._customising = val;

if (!val) {
this.textContent = "";
this.removeAttribute("title");
} else {
this.updateLabel();
}
}

_startX = 0;
_startWidth = 0;

canResize = false;

_previousWidth = 0;

get grip() {
const val = parseFloat(this.style.getPropertyValue("--spring-grip"));
return isNaN(val) ? this.getBoundingClientRect().width + 4 : val;
}

updateLabel() {
if (this.grip && this.grip <= this.getBoundingClientRect().width + 3) {
const { width } = this.getBoundingClientRect();

this.textContent = width.toFixed(0);
this.style.fontSize = Math.min(width / 3, 14) + "px";
} else if (this.getBoundingClientRect().width >= 20) {
this.textContent = "Auto";
}

this.setAttribute("title", this.textContent);
}

/**
* Handles mouse movements when resizing springs
* @param {MouseEvent} event
*/
onMouseMove(event) {
if (!this.customising || !this.canResize) return;

const newWidth = this._startWidth + event.clientX - this._startX;

if (newWidth <= 10 || this.grip >= this.getBoundingClientRect().width + 6) return;

this.style.setProperty("--spring-grip", newWidth.toFixed(0) + "px");

this.updateLabel();

document.documentElement.classList.add("auxiliary-resizing");
}

/**
* Handles incoming events to the element
* @param {Event} event
*/
handleEvent(event) {
switch (event.type) {
case "keydown":
case "keyup":
this.customising = /** @type {KeyboardEvent} */ (event).ctrlKey;
document.documentElement.classList.remove("auxiliary-resizing");
if (this.canResize) {
this.canResize = false;
}
break;
case "mousedown":
this._startWidth = this.getBoundingClientRect().width;
this._startX = /** @type {MouseEvent} */ (event).clientX;
this.canResize = true;
break;
case "mousemove":
this.onMouseMove(/** @type {MouseEvent} */ (event));
break;
case "mouseup":
document.documentElement.classList.remove("auxiliary-resizing");
this.canResize = false;
break;
}
}

connectedCallback() {
if (this.delayConnectedCallback()) return;

document.addEventListener("keydown", this);
document.addEventListener("keyup", this);
this.addEventListener("mousedown", this);
document.addEventListener("mousemove", this);
document.addEventListener("mouseup", this);
}

disconnectedCallback() {
if (this.delayConnectedCallback()) return;
}
}
class BrowserSpring extends MozHTMLElement {}

customElements.define("browser-spring", BrowserSpring);

0 comments on commit 11f7a45

Please sign in to comment.