From 9043966295ee44223fb60b5ebf84f12696fcef88 Mon Sep 17 00:00:00 2001
From: Abdullah Ahmed <abdullah_ahmed@brown.edu>
Date: Mon, 1 Jul 2019 09:55:21 -0400
Subject: draggable

---
 src/client/util/TooltipTextMenu.tsx | 41 +++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

(limited to 'src/client/util/TooltipTextMenu.tsx')

diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx
index a96615488..4ef76ee50 100644
--- a/src/client/util/TooltipTextMenu.tsx
+++ b/src/client/util/TooltipTextMenu.tsx
@@ -72,6 +72,7 @@ export class TooltipTextMenu {
         this.editorProps = editorProps;
         this.tooltip = document.createElement("div");
         this.tooltip.className = "tooltipMenu";
+        this.dragElement(this.tooltip);
 
         // this.createCollapse();
         // if (this._collapseBtn) {
@@ -185,6 +186,46 @@ export class TooltipTextMenu {
         this.fontSizeDom = newfontSizeDom;
     }
 
+    // Make the DIV element draggable:
+
+    dragElement(elmnt: HTMLElement) {
+        var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
+        if (elmnt) {
+            // if present, the header is where you move the DIV from:
+            elmnt.onmousedown = dragMouseDown;
+        }
+
+        function dragMouseDown(e: any) {
+            e = e || window.event;
+            e.preventDefault();
+            // get the mouse cursor position at startup:
+            pos3 = e.clientX;
+            pos4 = e.clientY;
+            document.onmouseup = closeDragElement;
+            // call a function whenever the cursor moves:
+            document.onmousemove = elementDrag;
+        }
+
+        function elementDrag(e: any) {
+            e = e || window.event;
+            e.preventDefault();
+            // calculate the new cursor position:
+            pos1 = pos3 - e.clientX;
+            pos2 = pos4 - e.clientY;
+            pos3 = e.clientX;
+            pos4 = e.clientY;
+            // set the element's new position:
+            elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
+            elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
+        }
+
+        function closeDragElement() {
+            // stop moving when mouse button is released:
+            document.onmouseup = null;
+            document.onmousemove = null;
+        }
+    }
+
     //label of dropdown will change to given label
     updateFontStyleDropdown(label: string) {
         //filtering function - might be unecessary
-- 
cgit v1.2.3-70-g09d2

