mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 23:39:59 +02:00
Add drag function for Zen Sidebar
This commit is contained in:
parent
b48e947798
commit
b6a9df7ebc
1 changed files with 43 additions and 1 deletions
|
@ -108,10 +108,45 @@ var gZenBrowserManagerSidebar = {
|
|||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.panelHeader.addEventListener('mousedown', this.handleDragPanel.bind(this));
|
||||
this.handleEvent();
|
||||
},
|
||||
|
||||
handleDragPanel(mouseDownEvent) {
|
||||
if (mouseDownEvent.target !== this.panelHeader) return;
|
||||
this._isDragging = true;
|
||||
const sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||
const wrapper = document.getElementById('zen-sidebar-web-panel-wrapper');
|
||||
const startTop = sidebar.style.top?.match(/\d+/)?.[0] || 0;
|
||||
const startLeft = sidebar.style.left?.match(/\d+/)?.[0] || 0;
|
||||
|
||||
|
||||
const sidebarBBox = sidebar.getBoundingClientRect();
|
||||
const sideBarHeight = sidebarBBox.height;
|
||||
const sideBarWidth = sidebarBBox.width;
|
||||
|
||||
const topMouseOffset = startTop - mouseDownEvent.screenY;
|
||||
const leftMouseOffset = startLeft - mouseDownEvent.screenX;
|
||||
const moveListener = (mouseMoveEvent) => {
|
||||
let top = mouseMoveEvent.screenY + topMouseOffset;
|
||||
let left = mouseMoveEvent.screenX + leftMouseOffset;
|
||||
|
||||
const wrapperBounds = wrapper.getBoundingClientRect();
|
||||
top = Math.max(0, Math.min(top, wrapperBounds.height - sideBarHeight));
|
||||
left = Math.max(0, Math.min(left, wrapperBounds.width - sideBarWidth));
|
||||
|
||||
sidebar.style.top = top + "px";
|
||||
sidebar.style.left = left + "px";
|
||||
};
|
||||
|
||||
|
||||
document.addEventListener('mousemove', moveListener);
|
||||
document.addEventListener('mouseup', () => {
|
||||
document.removeEventListener('mousemove', moveListener);
|
||||
this._isDragging = false;
|
||||
}, {once: true});
|
||||
},
|
||||
|
||||
get isFloating() {
|
||||
return document.getElementById('zen-sidebar-web-panel').hasAttribute('pinned');
|
||||
},
|
||||
|
@ -508,6 +543,13 @@ var gZenBrowserManagerSidebar = {
|
|||
return this._hSplitterElement;
|
||||
},
|
||||
|
||||
get panelHeader() {
|
||||
if (!this._header) {
|
||||
return document.getElementById('zen-sidebar-web-header');
|
||||
}
|
||||
return this._header;
|
||||
},
|
||||
|
||||
// Context menu
|
||||
|
||||
updateContextMenu(aPopupMenu) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue