forked from X-Genesis-Qhulut/alpha
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathediting.js
123 lines (98 loc) · 3.33 KB
/
editing.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
63
64
65
66
67
68
69
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
/*
Author: X'Genesis Qhulut <[email protected]>
Date: August 2022
See LICENSE for license details.
*/
// See: https://stackoverflow.com/a/22480938/
function isScrolledIntoView(el) {
var rect = el.getBoundingClientRect();
var elemTop = rect.top;
var elemBottom = rect.bottom;
// Only completely visible elements return true:
var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
// Partially visible elements return true:
//isVisible = elemTop < window.innerHeight && elemBottom >= 0;
return isVisible;
} // end of isScrolledIntoView
function onRowClick(event, id)
{
// Alt+Click to show an editing box
if (!event.altKey)
return
event.preventDefault()
// extract out the field name, which will start with "field_"
var field = id.match (/^field_(.+)$/)
if (!field)
return
// find the editing SQL box
var editingDiv = document.getElementById('editing_sql')
if (!editingDiv)
return
// alter the field name
document.getElementById('sql_field_name').innerHTML = field [1]
// make the editing box visible
editingDiv.style.display = 'block'
// scroll it into view if necessary
if (!isScrolledIntoView (editingDiv))
editingDiv.scrollIntoView()
} // end of onRowClick
// see: https://stackoverflow.com/questions/51805395/navigator-clipboard-is-undefined
// return a promise
function copyToClipboard(textToCopy) {
// navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
// navigator clipboard api method'
return navigator.clipboard.writeText(textToCopy);
} else {
// text area method
let textArea = document.createElement("textarea");
textArea.value = textToCopy;
// make the textarea out of viewport
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise((res, rej) => {
// here the magic happens
document.execCommand('copy') ? res() : rej();
textArea.remove();
});
}
} // end of copyToClipboard
// for copying a spawn point coordinates to the clipboard
function copyContents (event)
{
clickOnSpawnPoint (event, event.currentTarget.dataset.location)
return false
} // end of copyContents
// for switching model pages (out of a possible 4 variations)
function modelPage (event)
{
var page = event.currentTarget.dataset.page
var model_count = document.getElementById('caroussel-model').dataset.modelcount
for (i = 1; i <= model_count; i++)
{
document.getElementById('model' + i).style.display = 'none';
document.getElementById('model_navigate' + i).style.color = 'darkgray';
}
document.getElementById('model' + page).style.display = 'block';
document.getElementById('model_navigate' + page).style.color = 'whitesmoke';
event.preventDefault()
return false
} // end of modelPage
function goBack (pageType)
{
if (window.history.length > 1)
window.history.go(-1)
else
window.location.href = pageType
return false;
}
function clickOnSpawnPoint (event, location)
{
if (event.ctrlKey)
location = '.port ' + location;
copyToClipboard (location);
} // end of clickOnSpawnPoint