-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhui.js
More file actions
133 lines (102 loc) · 4.75 KB
/
hui.js
File metadata and controls
133 lines (102 loc) · 4.75 KB
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
124
125
126
127
128
129
130
131
132
133
R"htuijsstr(
//<script>
//////// HUI enhancements and fixes ////////
setTimeout(function(){
function all_elements () {
document.querySelectorAll("input[type='number']").forEach(input => { input.setAttribute("onmousewheel", ""); }); // allow changing vales of input type number using mousewheel (changing values using arrow keys works by default)
document.querySelectorAll("select").forEach(select => { select.onmousewheel= function(e) { // allow changing vales of select using mousewheel (changing values using arrow kes works by default)
if (this.hasFocus) {
return;
}
if (e.deltaY < 0) {
this.selectedIndex = Math.max(this.selectedIndex - 1, 0);
}
if (e.deltaY > 0) {
this.selectedIndex = Math.min(this.selectedIndex + 1, this.length - 1);
}
}; });
}
all_elements();
const observer = new MutationObserver(function(){ all_elements(); });
observer.observe(document.body, { childList: true, subtree: true });
}, 1000);
if (window.webkit) {
// disable pinch zoom in gtk webkit (because it doesnt respect css or meta tags)
window.addEventListener('touchstart', function (event) { if(event.scale !== 1 && event.touches.length === 2){event.preventDefault();} }, {passive: false});
window.addEventListener('touchmove', function (event) { if(event.scale !== 1 && event.touches.length === 2){event.preventDefault();} }, {passive: false});
// fix issue when drag'n dropping file onto the webview replaced the content with the dropped file (from <https://github.com/wailsapp/wails/issues/3686>)
window.addEventListener("drop", (event) => {
event.preventDefault();
});
window.addEventListener("dragover", (event) => {
event.preventDefault();
});
}
// disable right-click
document.addEventListener('contextmenu', event => event.preventDefault());
//////// HUI api ////////
// support forEach in webkit qt5
//if(!Array.prototype.forEach){Array.prototype.forEach=function(callback){if(this==null)throw new TypeError("Array.prototype.forEach called on null or undefined");var O=Object(this),len=O.length>>>0;if(typeof callback!=="function")throw new TypeError(callback+" is not a function");var T=arguments.length>1?arguments[1]:void 0;for(var i=0;i<len;i++){if(i in O){callback.call(T,O[i],i,O);}}};} if(window.NodeList && !NodeList.prototype.forEach){NodeList.prototype.forEach = Array.prototype.forEach;}
class _HUI {
/*_call_cpp (value){
// extended can have some datacolecting here
window.webkit.messageHandlers["sent2cpp"].postMessage(value);
}
_call_js (code){
// optionaly used (can impact performance but better use it)
// its better because we can pass multiple commands and will get return of the last one
return eval(code);
}*/
}
var HUI = new _HUI; // DEPRECAED JSERROR{duplicate}
HUI.html_element_create = function (query) {
const queryParts = query.split(/\s+(?![^\[]*\])/); // Split by space but ignore spaces inside attribute selectors
const elementQuery = queryParts.pop(); // The last part is the element to create
const parentQuery = queryParts.join(' '); // The remaining part is the parent query
const tag = elementQuery.match(/^[a-z0-9]+/i)?.[0] ?? 'div'; // Get the tag name, default to div if no tag name
const ids = elementQuery.match(/#([a-zA-Z0-9\-_]+)/); // Find ID
const classes = elementQuery.match(/\.[a-zA-Z0-9\-_]+/g); // Find all classes
const attributes = elementQuery.match(/\[([a-zA-Z\-]+)(?:=['"]?([a-zA-Z0-9\-_ ]*)['"]?)?\]/g);
const element = document.createElement(tag);
if (ids) {
element.id = ids[1];
}
if (classes) {
const classList = classes.map(cls => cls.substring(1)); // Remove the leading '.'
element.classList.add(...classList);
}
if (attributes) {
attributes.forEach(attr => {
const attrMatch = attr.match(/\[([a-zA-Z\-]+)(?:=['"]?([a-zA-Z0-9\-_ ]*)['"]?)?\]/);
const attrName = attrMatch[1]; // Attribute name
const attrValue = attrMatch[2] || ''; // Attribute value (default is empty string if not provided)
element.setAttribute(attrName, attrValue);
});
}
let parent = document.querySelector(parentQuery);
if (parent) {
parent.appendChild(element);
}
else {
//createElementFromQuery(parent);
console.error("<hui_error: invalid parent '"+parentQuery+"' of new element>");
}
return element;
}
/*class HUIbutton extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({mode: 'open'});
/.*<style>
span {}
span:hover, span:focus {}
span:disabled {}
</style>*./
shadow.appendChild( Object.assign(document.createElement("span"), {innerHTML:"Click me not?",tabindex:"0"}) );
//<div tabindex="0" contenteditable="true">abc</div>
// style: ::hover = ::focus
//shadow.appendChild()
}
}
customElements.define('hui-button', HUIbutton);*/
)htuijsstr"