-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprismatic-editor.js
62 lines (52 loc) · 1.61 KB
/
prismatic-editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
function copyToClipboard(text) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
document.addEventListener("DOMContentLoaded", function () {
var videoElement = document.getElementsByClassName('editor')[0];
var emptyObj = {
"leftX": 0,
"topY": 0,
"rightX": 0,
"bottomY": 0
};
var currentObj = emptyObj;
var phaseCount = 0;
videoElement.addEventListener('mousedown', function (event) {
var buttonNames = { 0: 'left', 1: 'middle', 2: 'right' };
switch (buttonNames[event.button]) {
case 'left':
if (phaseCount === 0) {
currentObj.leftX = event.clientX;
currentObj.topY = event.clientY;
++phaseCount;
} else if (phaseCount === 1) {
currentObj.rightX = event.clientX;
currentObj.bottomY = event.clientY;
var obj = {
"name": "",
"type": "click",
"action": {
"jumpTo": 0
},
"coord": {}
};
Object.assign(obj.coord, currentObj);
copyToClipboard(JSON.stringify(obj));
currentObj = emptyObj;
phaseCount = 0;
console.log('Current edition object has been cleared');
}
break;
case 'middle':
var rect = videoElement.getBoundingClientRect();
var obj = { "baseData": { "baseWidth": rect.width, "baseHeight": rect.height } };
copyToClipboard(JSON.stringify(obj));
break;
case 'right':
break;
default:
console.log('Unhandled click type');
}
});
console.log('prismatic-editor load and ready !');
});