Updating OHIF draggable utility to use CSS3 translate
This commit is contained in:
1 parent
a7d6cb4fea
commit
edba1052da
8 files changed
+196
-137
No files matched your search
@@ -2,7 +2,6 @@ import { Template } from 'meteor/templating';
|
||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||
import { Session } from 'meteor/session';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import { Random } from 'meteor/random';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
https://github.com/swederik/dragula/blob/ccc15d75186f5168e7abadbe3077cf12dab09f8b/styleProperty.js
|
||||
*/
|
||||
'use strict';
|
||||
var browserProps = {};
|
||||
|
||||
function eachVendor(prop, fn) {
|
||||
var prefixes = ['Webkit', 'Moz', 'ms', 'O'];
|
||||
var i = 0;
|
||||
var l = prefixes.length;
|
||||
fn(prop);
|
||||
for (; i < l; i++) {
|
||||
fn(prefixes[i] + prop.charAt(0).toUpperCase() + prop.slice(1));
|
||||
}
|
||||
}
|
||||
|
||||
function check(property, testValue) {
|
||||
var sandbox = document.createElement('iframe');
|
||||
var el = document.createElement('p');
|
||||
var support;
|
||||
|
||||
document.body.appendChild(sandbox);
|
||||
sandbox.contentDocument.body.appendChild(el);
|
||||
support = set(el, property, testValue);
|
||||
|
||||
// We have to do this because remove() is not supported by IE11 and below
|
||||
sandbox.parentElement.removeChild(sandbox);
|
||||
return support;
|
||||
}
|
||||
|
||||
function checkComputed(el, prop) {
|
||||
var computed = window.getComputedStyle(el).getPropertyValue(prop);
|
||||
return ((computed !== void 0) && computed.length > 0 && computed !== 'none');
|
||||
}
|
||||
|
||||
function set(el, prop, value) {
|
||||
var match = false;
|
||||
if (browserProps[prop] === void 0) {
|
||||
eachVendor(prop, function(vendorProp) {
|
||||
if (el.style[vendorProp] !== void 0 && match === false) {
|
||||
el.style[vendorProp] = value;
|
||||
if (checkComputed(el, vendorProp)) {
|
||||
match = true;
|
||||
browserProps[prop] = vendorProp;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
el.style[browserProps[prop]] = value;
|
||||
return true;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
const styleProperty = {
|
||||
check,
|
||||
set,
|
||||
};
|
||||
|
||||
export { styleProperty };
|
||||
@@ -1,6 +1,5 @@
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { styleProperty } from './styleProperty'
|
||||
|
||||
const cloneElement = (element, targetId) => {
|
||||
// Clone the DOM element
|
||||
@@ -32,7 +31,7 @@ const thumbnailDragStartHandler = (event, data) => {
|
||||
|
||||
// Force to hardware acceleration to move element
|
||||
// if browser supports translate property
|
||||
const useTransform = styleProperty.check('transform', 'translate(1px, 1px)');
|
||||
const useTransform = OHIF.ui.styleProperty.check('transform', 'translate(1px, 1px)');
|
||||
|
||||
// Clone the image thumbnail
|
||||
const targetId = 'DragClone';
|
||||
@@ -55,8 +54,7 @@ const thumbnailDragStartHandler = (event, data) => {
|
||||
if (event.type === 'touchstart') {
|
||||
cursorX = event.originalEvent.touches[0].pageX;
|
||||
cursorY = event.originalEvent.touches[0].pageY;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cursorX = event.pageX;
|
||||
cursorY = event.pageY;
|
||||
|
||||
@@ -97,7 +95,7 @@ const thumbnailDragStartHandler = (event, data) => {
|
||||
top: cursorY - diff.y,
|
||||
});
|
||||
} else {
|
||||
const viewerHeight= $('#viewer').height();
|
||||
const viewerHeight = $('#viewer').height();
|
||||
const headerHeight = $('.header').outerHeight();
|
||||
const heightDiff = viewerHeight + headerHeight;
|
||||
|
||||
@@ -108,7 +106,7 @@ const thumbnailDragStartHandler = (event, data) => {
|
||||
const positionY = cursorY - diff.y - heightDiff;
|
||||
|
||||
const translation = `translate(${positionX}px, ${positionY}px)`;
|
||||
styleProperty.set($clone.get(0), 'transform', translation);
|
||||
OHIF.ui.styleProperty.set($clone.get(0), 'transform', translation);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,8 +117,7 @@ const thumbnailDragHandler = event => {
|
||||
if (event.type === 'touchmove') {
|
||||
cursorX = event.originalEvent.changedTouches[0].pageX;
|
||||
cursorY = event.originalEvent.changedTouches[0].pageY;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cursorX = event.pageX;
|
||||
cursorY = event.pageY;
|
||||
}
|
||||
@@ -131,7 +128,7 @@ const thumbnailDragHandler = event => {
|
||||
|
||||
// Force to hardware acceleration to move element
|
||||
// if browser supports translate property
|
||||
const useTransform = styleProperty.check('transform', 'translate(1px, 1px)');
|
||||
const useTransform = OHIF.ui.styleProperty.check('transform', 'translate(1px, 1px)');
|
||||
|
||||
$clone.css({
|
||||
visibility: 'visible',
|
||||
@@ -152,7 +149,7 @@ const thumbnailDragHandler = event => {
|
||||
const positionY = cursorY - diff.y - heightDiff;
|
||||
|
||||
const translation = `translate(${positionX}px, ${positionY}px)`;
|
||||
styleProperty.set($clone.get(0), 'transform', translation);
|
||||
OHIF.ui.styleProperty.set($clone.get(0), 'transform', translation);
|
||||
}
|
||||
|
||||
// Identify the element below the current cursor position
|
||||
@@ -172,12 +169,10 @@ const thumbnailDragHandler = event => {
|
||||
// If we're dragging over a non-empty viewport, fade it and change the cursor style
|
||||
$viewportsDraggedOver.find('canvas').not('.magnifyTool').addClass('faded');
|
||||
document.body.style.cursor = 'copy';
|
||||
}
|
||||
else if (elemBelow.classList.contains('imageViewerViewport') && elemBelow.classList.contains('empty')) {
|
||||
} else if (elemBelow.classList.contains('imageViewerViewport') && elemBelow.classList.contains('empty')) {
|
||||
// If we're dragging over an empty viewport, just change the cursor style
|
||||
document.body.style.cursor = 'copy';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Otherwise, keep the cursor as no-drop style
|
||||
document.body.style.cursor = 'no-drop';
|
||||
}
|
||||
@@ -224,17 +219,15 @@ const thumbnailDragEndHandler = (event, data, handlers) => {
|
||||
|
||||
let element;
|
||||
const $viewportsDraggedOver = $(elemBelow).closest('.imageViewerViewport');
|
||||
|
||||
|
||||
if ($viewportsDraggedOver.length) {
|
||||
// If we're dragging over a non-empty viewport, retrieve it
|
||||
element = $viewportsDraggedOver.get(0);
|
||||
}
|
||||
else if (elemBelow.classList.contains('imageViewerViewport') &&
|
||||
} else if (elemBelow.classList.contains('imageViewerViewport') &&
|
||||
elemBelow.classList.contains('empty')) {
|
||||
// If we're dragging over an empty viewport, retrieve that instead
|
||||
element = elemBelow;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Otherwise, stop here
|
||||
return false;
|
||||
}
|
||||
@@ -259,4 +252,4 @@ const thumbnailDragHandlers = {
|
||||
thumbnailDragHandler
|
||||
};
|
||||
|
||||
export { thumbnailDragHandlers };
|
||||
export { thumbnailDragHandlers };
|
||||
Reference in new issue
Block a user