Skip to content

Commit

Permalink
fix and simplify drag position calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Dec 4, 2016
1 parent db314ef commit e8f9a18
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ chrome.extension.sendMessage({}, function(response) {
// Ignore keydown event if typing in an input box
if ((document.activeElement.nodeName === 'INPUT'
&& document.activeElement.getAttribute('type') === 'text')
|| document.activeElement.nodeName === 'TEXTAREA'
|| document.activeElement.nodeName === 'TEXTAREA'
|| document.activeElement.isContentEditable) {
return false;
}
Expand Down Expand Up @@ -311,21 +311,15 @@ chrome.extension.sendMessage({}, function(response) {

function handleDrag(video, controller) {
const parentElement = controller.parentElement,
boundRect = parentElement.getBoundingClientRect(),
shadowController = controller.shadowRoot.querySelector('#controller'),
drag = shadowController.querySelector('.draggable'),
offsetLeft = boundRect.left + drag.offsetLeft + drag.offsetWidth,
offsetTop = boundRect.top + drag.offsetTop + drag.offsetHeight;
shadowController = controller.shadowRoot.querySelector('#controller');

video.classList.add('vcs-dragging');
shadowController.classList.add('dragging');

const startDragging = (e) => {
let newLeft = Math.max(0, e.clientX - offsetLeft);
let newTop = Math.max(0, e.clientY - offsetTop);

shadowController.style.left = newLeft + 'px';
shadowController.style.top = newTop + 'px';
let style = shadowController.style;
style.left = parseInt(style.left) + e.movementX + 'px';
style.top = parseInt(style.top) + e.movementY + 'px';
}

const stopDragging = () => {
Expand Down

0 comments on commit e8f9a18

Please sign in to comment.