ソースを参照

Make selector compatible with IE9

dev_h
Finn Krein 3年前
コミット
7802f0071b
3個のファイルの変更40行の追加39行の削除
  1. 3
    3
      client-data/js/board.js
  2. 5
    3
      client-data/js/intersect.js
  3. 32
    33
      client-data/tools/hand/hand.js

+ 3
- 3
client-data/js/board.js ファイルの表示

@@ -685,8 +685,8 @@ Tools.svg.height.baseVal.value = document.body.clientHeight;
685 685
 
686 686
 
687 687
 (function () {
688
-    let pos = {top: 0, scroll:0};
689
-    let menu = document.getElementById("menu");
688
+    var pos = {top: 0, scroll:0};
689
+    var menu = document.getElementById("menu");
690 690
     function menu_mousedown(evt) {
691 691
 	pos = {
692 692
 	    top: menu.scrollTop,
@@ -696,7 +696,7 @@ Tools.svg.height.baseVal.value = document.body.clientHeight;
696 696
 	document.addEventListener("mouseup", menu_mouseup);
697 697
     }
698 698
     function menu_mousemove(evt) {
699
-	const dy = evt.clientY - pos.scroll;
699
+	var dy = evt.clientY - pos.scroll;
700 700
 	menu.scrollTop = pos.top - dy;
701 701
     }
702 702
     function menu_mouseup(evt) {

+ 5
- 3
client-data/js/intersect.js ファイルの表示

@@ -28,7 +28,7 @@ if (!SVGGraphicsElement.prototype.transformedBBox || !SVGGraphicsElement.prototy
28 28
     [pointInTransformedBBox,
29 29
      transformedBBoxIntersects] = (function () {
30 30
 
31
-	let applyTransform = function (m,t) {
31
+	var applyTransform = function (m,t) {
32 32
 	    return [
33 33
 		m.a*t[0]+m.c*t[1],
34 34
 		m.b*t[0]+m.d*t[1]
@@ -60,7 +60,7 @@ if (!SVGGraphicsElement.prototype.transformedBBox || !SVGGraphicsElement.prototy
60 60
 	    }
61 61
 	}
62 62
 
63
-	let pointInTransformedBBox = function ([x,y],{r,a,b}) {
63
+	var pointInTransformedBBox = function ([x,y],{r,a,b}) {
64 64
 	    var d = [x-r[0],y-r[1]];
65 65
 	    var idet = (a[0]*b[1]-a[1]*b[0]);
66 66
 	    var c1 = (d[0]*b[1]-d[1]*b[0]) / idet;
@@ -79,7 +79,9 @@ if (!SVGGraphicsElement.prototype.transformedBBox || !SVGGraphicsElement.prototy
79 79
 		[bbox_b.r[0] + bbox_b.b[0], bbox_b.r[1] + bbox_b.b[1]],
80 80
 		[bbox_b.r[0] + bbox_b.a[0] + bbox_b.b[0], bbox_b.r[1] + bbox_b.a[1] + bbox_b.b[1]]
81 81
 	    ]
82
-	    return corners.every(corner=>pointInTransformedBBox(corner,bbox_a))
82
+	    return corners.every(function(corner) {
83
+				return pointInTransformedBBox(corner, bbox_a);
84
+			})
83 85
 	}
84 86
 
85 87
 	SVGGraphicsElement.prototype.transformedBBoxIntersects= function (bbox) {

+ 32
- 33
client-data/tools/hand/hand.js ファイルの表示

@@ -25,7 +25,7 @@
25 25
  */
26 26
 
27 27
 (function hand() { //Code isolation
28
-	const selectorStates = {
28
+	var selectorStates = {
29 29
 		pointing: 0,
30 30
 		selecting: 1,
31 31
 		moving: 2
@@ -46,11 +46,13 @@
46 46
 			els.unshift(a);
47 47
 			a = a.parentElement;
48 48
 		}
49
-		var parentMathematics = els.find(el => el.getAttribute("class") === "MathElement");
49
+		var parentMathematics = els.find(function(el) {
50
+				return el.getAttribute("class") === "MathElement";
51
+			});
50 52
 		if ((parentMathematics) && parentMathematics.tagName === "svg") {
51 53
 			target = parentMathematics;
52 54
 		}
53
-		return target ?? el;
55
+		return target || el;
54 56
 	}
55 57
 
56 58
 	function createSelectorRect() {
@@ -75,17 +77,15 @@
75 77
 		selectorState = selectorStates.moving;
76 78
 		selected = { x: x, y: y };
77 79
 		// Some of the selected elements could have been deleted
78
-		selected_els = selected_els.filter(el => {
79
-			return Tools.svg.getElementById(el.id) !== null
80
+		selected_els = selected_els.filter(function(el) {
81
+				return Tools.svg.getElementById(el.id) !== null;
82
+			});
83
+		translation_elements = selected_els.map(function(el) {
84
+			var tmatrix = get_translate_matrix(el);
85
+			return { x: tmatrix.e, y: tmatrix.f };
80 86
 		});
81
-		translation_elements = selected_els.map(el => {
82
-			let tmatrix = get_translate_matrix(el);
83
-			return { x: tmatrix.e, y: tmatrix.f }
84
-		});
85
-		{
86
-			let tmatrix = get_translate_matrix(selectionRect);
87
-			selectionRectTranslation = { x: tmatrix.e, y: tmatrix.f };
88
-		}
87
+		var tmatrix = get_translate_matrix(selectionRect);
88
+		selectionRectTranslation = { x: tmatrix.e, y: tmatrix.f };
89 89
 	}
90 90
 
91 91
 	function startSelector(x, y, evt) {
@@ -107,33 +107,32 @@
107 107
 	function calculateSelection() {
108 108
 		var scale = Tools.drawingArea.getCTM().a;
109 109
 		var selectionTBBox = selectionRect.transformedBBox(scale);
110
-		return Array.from(Tools.drawingArea.children).filter(el => {
111
-			return transformedBBoxIntersects(
112
-				selectionTBBox,
113
-				el.transformedBBox(scale)
114
-			)
115
-		});
110
+		var elements = Tools.drawingArea.children;
111
+		var selected = [];
112
+		for (var i=0; i < elements.length; i++) {
113
+			if (transformedBBoxIntersects(selectionTBBox, elements[i].transformedBBox(scale)))
114
+				selected.push(Tools.drawingArea.children[i]);
115
+		}
116
+		return selected;
116 117
 	}
117 118
 
118 119
 	function moveSelection(x, y) {
119 120
 		var dx = x - selected.x;
120 121
 		var dy = y - selected.y;
121
-		var msgs = selected_els.map((el, i) => {
122
-			return {
123
-				type: "update",
124
-				id: el.id,
125
-				deltax: dx + translation_elements[i].x,
126
-				deltay: dy + translation_elements[i].y
127
-			}
128
-		})
122
+		var msgs = selected_els.map(function(el, i) {
123
+				return {
124
+					type: "update",
125
+					id: el.id,
126
+					deltax: dx + translation_elements[i].x,
127
+					deltay: dy + translation_elements[i].y
128
+				};
129
+			})
129 130
 		var msg = {
130 131
 			_children: msgs
131 132
 		};
132
-		{
133
-			let tmatrix = get_translate_matrix(selectionRect);
134
-			tmatrix.e = dx + selectionRectTranslation.x;
135
-			tmatrix.f = dy + selectionRectTranslation.y;
136
-		}
133
+		var tmatrix = get_translate_matrix(selectionRect);
134
+		tmatrix.e = dx + selectionRectTranslation.x;
135
+		tmatrix.f = dy + selectionRectTranslation.y;
137 136
 		var now = performance.now();
138 137
 		if (now - last_sent > 70) {
139 138
 			last_sent = now;
@@ -190,7 +189,7 @@
190 189
 
191 190
 	function clickSelector(x, y, evt) {
192 191
 		var scale = Tools.drawingArea.getCTM().a
193
-		selectionRect = selectionRect ?? createSelectorRect();
192
+		selectionRect = selectionRect || createSelectorRect();
194 193
 		if (pointInTransformedBBox([x, y], selectionRect.transformedBBox(scale))) {
195 194
 			startMovingElements(x, y, evt);
196 195
 		} else if (Tools.drawingArea.contains(evt.target)) {

読み込み中…
キャンセル
保存