Newer
Older
Björn Eßwein
committed
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Scroll View</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
[dropzone] {
background-color: grey;
}
.lagacySlot {
width: 100px;
height: 100px;
margin: 50px;
border-width: 1px;
Björn Eßwein
committed
}
#rectangle {
width: 10px;
height: 10px;
position: absolute;
background-color: red;
}
</style>
</head>
<body>
<div id="scrollContainer">
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<math>
<mi>E</mi>
<mo>=</mo>
<mfenced>
<mtable>
<mtr>
<mtd>
<mi dropzone="copy" data-allowed-types="PointFact,AngleFact" data-slot-id="http://mathhub.info/FrameIT/frameworld?Example?A">a</mi>
</mtd>
<mtd>
<mi dropzone="copy" data-slot-id="http://mathhub.info/FrameIT/frameworld?Example?B">b</mi>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
</math>
</div>
Björn Eßwein
committed
<button type="button" title="Apply the scroll" onclick="applyScroll('')">Magic</button><br>
<p>Right click on a slot to get a hint.</p>
Björn Eßwein
committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
</body>
<script>
/**
* @typedef Point
* @type {object}
* @property {number} x
* @property {number} y
* @property {number} z
*/
/**
* @property {Point} point
* @property {Point} normal
* @property {string} s_type
* @property {string} label
* @property {string|null} _CustomLabel
* @property {boolean} hasCustomLabel
* @property {number} labelId
*/
class Fact {
/** @property {string} id Fact id */
id = ""
/** @property {string} s_type Fact type */
s_type = ""
/** @property {string} label used in unity */
label = ""
/** @property {string | null} _CustomLabel Custom label */
_CustomLabel = null
/** @property {boolean} hasCustomLabel */
hasCustomLabel = false
/** @property {number} labelId */
labelId = 0
}
class Point {
/** @property {number} x */
x = 0
/** @property {number} y */
y = 0
/** @property {number} z */
z = 0
}
/**
s_type: PointFact,
label: A,
_CustomLabel: null,
hasCustomLabel: false,
labelId: 0,
point: {x: -1.66086578, y: -0.00494432449, z: -2.17682648},
normal: {x: 0, y: 1, z: 0}
*/
class PointFact extends Fact {
s_type = "PointFact";
/** @property {Point} point */
point = new Point()
/** @property {Point} normal */
normal = new Point()
}
/**
* pid1: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact252,
pid2: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact254,
pid3: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256,
s_type: AngleFact,
label: ∠BDF,
_CustomLabel: null,
is_right_angle: false,
hasCustomLabel: false,
labelId: 0
*/
class AngleFact extends Fact {
s_type = "AngleFact";
pid1 = "";
pid2 = "";
pid3 = "";
is_right_angle = false;
}
/**
* s_type: LineFact,
pid1: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact255,
pid2: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256,
dir: [object Object],
label: [EF],
_CustomLabel: null,
hasCustomLabel: false,
labelId: 0
*/
class LineFact extends Fact {
s_type = "LineFact";
pid1 = "";
pid2 = "";
dir = new Point();
}
/**
* s_type: RayFact,
pid1: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact256,
pid2: http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact252,
dir: [object Object],
label: FB,
_CustomLabel: null,
hasCustomLabel: false,
labelId: 0
*/
class RayFact extends Fact {
s_type = "RayFact";
pid1 = "";
pid2 = "";
dir = new Point();
}
/** @param {DragEvent} event */
function dropHandler(event) {
Björn Eßwein
committed
event.preventDefault()
console.log("dropHandler", event)
const data = event.dataTransfer.getData("application/json")
//const data = event.dataTransfer.getData("text/plain")
console.log(`Droped data: '${event.dataTransfer.types}'`, event.dataTransfer.types)
/** @type {Fact} */
const fact = JSON.parse(data)
console.warn(`Droped Fact '${fact.label}':`, fact)
/** @type {HTMLElement} */
const element = event.target
if (element.hasAttribute("data-allowed-types")) {
//const allowedTypesStr = element.dataset["allowed-types"]
const allowedTypesStr = element.getAttribute("data-allowed-types")
const allowedTypes = allowedTypesStr.split(",")
if (!allowedTypes.includes(fact.s_type)) {
console.warn(`The drop target data-type '${fact.s_type}' is not a member of the allowed types '${allowedTypesStr}'`)
return
Björn Eßwein
committed
}
Björn Eßwein
committed
}
element.innerHTML = fact.label
element.fact = fact
element.dataset.factId = fact.id
Björn Eßwein
committed
}
Björn Eßwein
committed
/** @param {MouseEvent} event */
function clickHandler(event) {
event.preventDefault()
console.log("clickHandler")
console.log("clickHandler", event)
switch (event.button) {
case 0:
console.log("Left button clicked")
event.target.fact = null
event.target.dataset.factId = null
break
case 1:
console.log("Middle button clicked")
break
case 2:
console.log("Right button clicked")
getHint(event.target.dataset.slotId)
break
default:
console.log("Unknown button clicked")
}
Björn Eßwein
committed
}
Björn Eßwein
committed
Björn Eßwein
committed
/*
* register the drag event listeners
*/
//document.addEventListener("dragstart", ev => printHandler(ev, "DragStartEvent"))
//document.addEventListener("dragenter", ev => printHandler(ev, "DragEnterEvent"))
//document.addEventListener("drag", ev => printHandler(ev, "DragEvent"))
document.addEventListener("dragover", ev => ev.preventDefault())
//document.addEventListener("dragover", ev => printPreventDefaultHandler(ev, "DragOverEvent"))
//document.addEventListener("dragleave", ev => printHandler(ev, "DragLeaveEvent"))
//document.addEventListener("dragend", ev => printHandler(ev, "DragEndEvent"))
// select all dropzones and add drop event listeners
Björn Eßwein
committed
//let dropZones = document.querySelectorAll('[dropzone="copy"]')
//dropZones.forEach( dropZone => dropZone.addEventListener("drop", ev => dropHandler(ev, "DropEvent")) )
/** select all dropzones and add drop event listeners */
function addDropZoneEventListeners() {
console.log("addDropZoneEventListeners")
document.querySelectorAll('[dropzone="copy"]')
.forEach( dropZone => {
dropZone.removeEventListener("drop", dropHandler)
dropZone.removeEventListener("click", clickHandler)
dropZone.removeEventListener("contextmenu", clickHandler)
//dropZone.addEventListener("dragover", ev => ev.preventDefault())
dropZone.addEventListener("drop", dropHandler)
dropZone.addEventListener("click", clickHandler)
dropZone.addEventListener("contextmenu", clickHandler)
})
}
//addDropZoneEventListeners()
Björn Eßwein
committed
</script>
Björn Eßwein
committed
Björn Eßwein
committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!--<script src="visualiseCursor.mjs" defer type="module"></script>-->
<!--<script>
/* mouse and pointer event handling */
const rectangle = document.createElement("div");
rectangle.id = "rectangle";
console.log("appendChild to", document.body)
document.body.appendChild(rectangle);
function followCursor(event) {
const cursorX = event.clientX;
const cursorY = event.clientY +5;
//console.log(`MouseEvent X: ${cursorX}, Y: ${cursorY}, Event type: ${event.type}`, event);
rectangle.style.left = `${cursorX}px`;
rectangle.style.top = `${cursorY}px`;
}
document.addEventListener("mousemove", followCursor);
document.addEventListener("pointermove", followCursor);
document.addEventListener("mouseover", followCursor);
document.addEventListener("pointerover", followCursor);
document.addEventListener("mouseout", followCursor);
document.addEventListener("pointerout", followCursor);
</script>-->
</html>