mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-22 02:18:45 -04:00
fix and simplify drag position calculation
This commit is contained in:
16
inject.js
16
inject.js
@@ -193,7 +193,7 @@ chrome.extension.sendMessage({}, function(response) {
|
|||||||
// Ignore keydown event if typing in an input box
|
// Ignore keydown event if typing in an input box
|
||||||
if ((document.activeElement.nodeName === 'INPUT'
|
if ((document.activeElement.nodeName === 'INPUT'
|
||||||
&& document.activeElement.getAttribute('type') === 'text')
|
&& document.activeElement.getAttribute('type') === 'text')
|
||||||
|| document.activeElement.nodeName === 'TEXTAREA'
|
|| document.activeElement.nodeName === 'TEXTAREA'
|
||||||
|| document.activeElement.isContentEditable) {
|
|| document.activeElement.isContentEditable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -311,21 +311,15 @@ chrome.extension.sendMessage({}, function(response) {
|
|||||||
|
|
||||||
function handleDrag(video, controller) {
|
function handleDrag(video, controller) {
|
||||||
const parentElement = controller.parentElement,
|
const parentElement = controller.parentElement,
|
||||||
boundRect = parentElement.getBoundingClientRect(),
|
shadowController = controller.shadowRoot.querySelector('#controller');
|
||||||
shadowController = controller.shadowRoot.querySelector('#controller'),
|
|
||||||
drag = shadowController.querySelector('.draggable'),
|
|
||||||
offsetLeft = boundRect.left + drag.offsetLeft + drag.offsetWidth,
|
|
||||||
offsetTop = boundRect.top + drag.offsetTop + drag.offsetHeight;
|
|
||||||
|
|
||||||
video.classList.add('vcs-dragging');
|
video.classList.add('vcs-dragging');
|
||||||
shadowController.classList.add('dragging');
|
shadowController.classList.add('dragging');
|
||||||
|
|
||||||
const startDragging = (e) => {
|
const startDragging = (e) => {
|
||||||
let newLeft = Math.max(0, e.clientX - offsetLeft);
|
let style = shadowController.style;
|
||||||
let newTop = Math.max(0, e.clientY - offsetTop);
|
style.left = parseInt(style.left) + e.movementX + 'px';
|
||||||
|
style.top = parseInt(style.top) + e.movementY + 'px';
|
||||||
shadowController.style.left = newLeft + 'px';
|
|
||||||
shadowController.style.top = newTop + 'px';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopDragging = () => {
|
const stopDragging = () => {
|
||||||
|
Reference in New Issue
Block a user