2024-01-15 16:13:46 +03:00
|
|
|
let sessionID = "0"
|
|
|
|
let windowFocus = true
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
window.onresize = function() {
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
|
2024-03-13 15:01:02 +03:00
|
|
|
window.onbeforeunload = function() {
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage( "session-close{session=" + sessionID +"}" );
|
|
|
|
}
|
|
|
|
|
2024-03-13 15:01:02 +03:00
|
|
|
window.onblur = function() {
|
2021-09-07 17:36:50 +03:00
|
|
|
windowFocus = false
|
|
|
|
sendMessage( "session-pause{session=" + sessionID +"}" );
|
|
|
|
}
|
|
|
|
|
2022-11-01 20:13:09 +03:00
|
|
|
function sessionInfo() {
|
|
|
|
|
|
|
|
const touch_screen = (('ontouchstart' in document.documentElement) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)) ? "1" : "0";
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "startSession{touch=" + touch_screen
|
2022-11-01 20:13:09 +03:00
|
|
|
|
|
|
|
const style = window.getComputedStyle(document.body);
|
|
|
|
if (style) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const direction = style.getPropertyValue('direction');
|
2022-11-01 20:13:09 +03:00
|
|
|
if (direction) {
|
|
|
|
message += ",direction=" + direction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const lang = window.navigator.language;
|
|
|
|
if (lang) {
|
|
|
|
message += ",language=\"" + lang + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
const langs = window.navigator.languages;
|
|
|
|
if (langs) {
|
|
|
|
message += ",languages=\"" + langs + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
const userAgent = window.navigator.userAgent
|
|
|
|
if (userAgent) {
|
|
|
|
message += ",user-agent=\"" + userAgent + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
|
|
if (darkThemeMq.matches) {
|
|
|
|
message += ",dark=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
const pixelRatio = window.devicePixelRatio;
|
|
|
|
if (pixelRatio) {
|
|
|
|
message += ",pixel-ratio=" + pixelRatio;
|
|
|
|
}
|
|
|
|
|
2022-12-18 18:22:58 +03:00
|
|
|
if (localStorage.length > 0) {
|
|
|
|
message += ",storage="
|
|
|
|
lead = "_{"
|
2024-01-15 16:13:46 +03:00
|
|
|
for (let i = 0; i < localStorage.length; i++) {
|
|
|
|
let key = localStorage.key(i)
|
|
|
|
let value = localStorage.getItem(key)
|
2022-12-18 18:22:58 +03:00
|
|
|
key = key.replaceAll(/\\/g, "\\\\")
|
|
|
|
key = key.replaceAll(/\"/g, "\\\"")
|
|
|
|
key = key.replaceAll(/\'/g, "\\\'")
|
|
|
|
value = value.replaceAll(/\\/g, "\\\\")
|
|
|
|
value = value.replaceAll(/\"/g, "\\\"")
|
|
|
|
value = value.replaceAll(/\'/g, "\\\'")
|
|
|
|
message += lead + "\"" + key + "\"=\"" + value + "\""
|
|
|
|
lead = ","
|
|
|
|
}
|
|
|
|
message += "}"
|
|
|
|
}
|
|
|
|
|
2022-11-01 20:13:09 +03:00
|
|
|
return message + "}";
|
|
|
|
}
|
|
|
|
|
2024-04-22 19:17:04 +03:00
|
|
|
function restartSession() {
|
|
|
|
sendMessage( sessionInfo() );
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function getIntAttribute(element, tag) {
|
|
|
|
let value = element.getAttribute(tag);
|
|
|
|
if (value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scanElementsSize() {
|
2024-01-15 16:13:46 +03:00
|
|
|
const rootView = document.getElementById("ruiRootView");
|
|
|
|
if (rootView) {
|
|
|
|
let rect = rootView.getBoundingClientRect();
|
|
|
|
let width = getIntAttribute(rootView, "data-width");
|
|
|
|
let height = getIntAttribute(rootView, "data-height");
|
2022-05-12 11:05:50 +03:00
|
|
|
if (rect.width > 0 && rect.height > 0 && (width != rect.width || height != rect.height)) {
|
2024-01-15 16:13:46 +03:00
|
|
|
rootView.setAttribute("data-width", rect.width);
|
|
|
|
rootView.setAttribute("data-height", rect.height);
|
2022-05-12 11:05:50 +03:00
|
|
|
sendMessage("root-size{session=" + sessionID + ",width=" + rect.width + ",height=" + rect.height +"}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const views = document.getElementsByClassName("ruiView");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (views) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "resize{session=" + sessionID + ",views=["
|
|
|
|
let count = 0
|
|
|
|
for (const view of views) {
|
|
|
|
let noresize = view.getAttribute("data-noresize");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (!noresize) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let rect = view.getBoundingClientRect();
|
|
|
|
let top = getIntAttribute(view, "data-top");
|
|
|
|
let left = getIntAttribute(view, "data-left");
|
|
|
|
let width = getIntAttribute(view, "data-width");
|
|
|
|
let height = getIntAttribute(view, "data-height");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (rect.width > 0 && rect.height > 0 &&
|
|
|
|
(width != rect.width || height != rect.height || left != rect.left || top != rect.top)) {
|
2024-01-15 16:13:46 +03:00
|
|
|
view.setAttribute("data-top", rect.top);
|
|
|
|
view.setAttribute("data-left", rect.left);
|
|
|
|
view.setAttribute("data-width", rect.width);
|
|
|
|
view.setAttribute("data-height", rect.height);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (count > 0) {
|
|
|
|
message += ",";
|
|
|
|
}
|
2024-01-15 16:13:46 +03:00
|
|
|
message += "view{id=" + view.id + ",x=" + rect.left + ",y=" + rect.top + ",width=" + rect.width + ",height=" + rect.height +
|
|
|
|
",scroll-x=" + view.scrollLeft + ",scroll-y=" + view.scrollTop + ",scroll-width=" + view.scrollWidth + ",scroll-height=" + view.scrollHeight + "}";
|
2021-09-07 17:36:50 +03:00
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
sendMessage(message + "]}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollEvent(element, event) {
|
|
|
|
sendMessage("scroll{session=" + sessionID + ",id=" + element.id + ",x=" + element.scrollLeft +
|
|
|
|
",y=" + element.scrollTop + ",width=" + element.scrollWidth + ",height=" + element.scrollHeight + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCSSRule(selector, ruleText) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const styleSheet = document.styleSheets[0];
|
|
|
|
const rules = styleSheet.cssRules ? styleSheet.cssRules : styleSheet.rules
|
2021-09-07 17:36:50 +03:00
|
|
|
selector = "." + selector
|
2024-01-15 16:13:46 +03:00
|
|
|
for (let i = 0; i < rules.length; i++) {
|
|
|
|
const rule = rules[i]
|
2021-09-07 17:36:50 +03:00
|
|
|
if (!rule.selectorText) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (rule.selectorText == selector) {
|
|
|
|
if (styleSheet.deleteRule) {
|
|
|
|
styleSheet.deleteRule(i)
|
|
|
|
} else if (styleSheet.removeRule) {
|
|
|
|
styleSheet.removeRule(i)
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (styleSheet.insertRule) {
|
|
|
|
styleSheet.insertRule(selector + " { " + ruleText + "}")
|
|
|
|
} else if (styleSheet.addRule) {
|
|
|
|
styleSheet.addRule(selector, ruleText, rules.length)
|
|
|
|
}
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCSSStyle(elementId, style) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.style = style;
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCSSProperty(elementId, property, value) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.style[property] = value;
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateProperty(elementId, property, value) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.setAttribute(property, value);
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 13:10:55 +03:00
|
|
|
function removeProperty(elementId, property) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element && element.hasAttribute(property)) {
|
|
|
|
element.removeAttribute(property);
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateInnerHTML(elementId, content) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.innerHTML = content;
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function appendToInnerHTML(elementId, content) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.innerHTML += content;
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDisabled(elementId, disabled) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
if ('disabled' in element) {
|
|
|
|
element.disabled = disabled
|
|
|
|
} else {
|
|
|
|
element.setAttribute("data-disabled", disabled ? "1" : "0");
|
|
|
|
}
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function focusEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
sendMessage("focus-event{session=" + sessionID + ",id=" + element.id + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function blurEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
sendMessage("lost-focus-event{session=" + sessionID + ",id=" + element.id + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function enterOrSpaceKeyClickEvent(event) {
|
|
|
|
if (event.key) {
|
|
|
|
return (event.key == " " || event.key == "Enter");
|
|
|
|
} else if (event.keyCode) {
|
|
|
|
return (event.keyCode == 32 || event.keyCode == 13);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function activateTab(layoutId, tabNumber) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(layoutId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentNumber = element.getAttribute("data-current");
|
2023-05-04 13:37:26 +03:00
|
|
|
if (currentNumber != tabNumber) {
|
|
|
|
function setTab(number, styleProperty, display) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const tab = document.getElementById(layoutId + '-' + number);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (tab) {
|
|
|
|
tab.className = element.getAttribute(styleProperty);
|
2024-01-15 16:13:46 +03:00
|
|
|
const page = document.getElementById(tab.getAttribute("data-view"));
|
2021-09-07 17:36:50 +03:00
|
|
|
if (page) {
|
|
|
|
page.style.display = display;
|
|
|
|
}
|
2023-05-04 13:37:26 +03:00
|
|
|
return
|
|
|
|
}
|
2024-01-15 16:13:46 +03:00
|
|
|
const page = document.getElementById(layoutId + "-page" + number);
|
2023-05-04 13:37:26 +03:00
|
|
|
if (page) {
|
|
|
|
page.style.display = display;
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
2023-05-04 13:37:26 +03:00
|
|
|
setTab(currentNumber, "data-inactiveTabStyle", "none")
|
|
|
|
setTab(tabNumber, "data-activeTabStyle", "");
|
|
|
|
element.setAttribute("data-current", tabNumber);
|
2021-09-07 17:36:50 +03:00
|
|
|
scanElementsSize()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
function tabClickEvent(tab, layoutId, tabNumber, event) {
|
2021-09-07 17:36:50 +03:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
activateTab(layoutId, tabNumber)
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
if (tab) {
|
|
|
|
tab.blur()
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage("tabClick{session=" + sessionID + ",id=" + layoutId + ",number=" + tabNumber + "}");
|
|
|
|
}
|
|
|
|
|
2021-11-21 18:16:22 +03:00
|
|
|
function tabKeyClickEvent(layoutId, tabNumber, event) {
|
|
|
|
if (enterOrSpaceKeyClickEvent(event)) {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
tabClickEvent(null, layoutId, tabNumber, event)
|
2021-11-21 18:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
function tabCloseClickEvent(button, layoutId, tabNumber, event) {
|
2021-11-17 12:32:37 +03:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
if (button) {
|
|
|
|
button.blur()
|
|
|
|
}
|
2021-11-17 12:32:37 +03:00
|
|
|
sendMessage("tabCloseClick{session=" + sessionID + ",id=" + layoutId + ",number=" + tabNumber + "}");
|
|
|
|
}
|
|
|
|
|
2021-11-21 18:16:22 +03:00
|
|
|
function tabCloseKeyClickEvent(layoutId, tabNumber, event) {
|
2021-09-07 17:36:50 +03:00
|
|
|
if (enterOrSpaceKeyClickEvent(event)) {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
tabCloseClickEvent(null, layoutId, tabNumber, event)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function keyEvent(element, event, tag) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = tag + "{session=" + sessionID + ",id=" + element.id;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (event.timeStamp) {
|
|
|
|
message += ",timeStamp=" + event.timeStamp;
|
|
|
|
}
|
|
|
|
if (event.key) {
|
|
|
|
message += ",key=\"" + event.key + "\"";
|
|
|
|
}
|
|
|
|
if (event.code) {
|
|
|
|
message += ",code=\"" + event.code + "\"";
|
|
|
|
}
|
|
|
|
if (event.repeat) {
|
|
|
|
message += ",repeat=1";
|
|
|
|
}
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
message += ",ctrlKey=1";
|
|
|
|
}
|
|
|
|
if (event.shiftKey) {
|
|
|
|
message += ",shiftKey=1";
|
|
|
|
}
|
|
|
|
if (event.altKey) {
|
|
|
|
message += ",altKey=1";
|
|
|
|
}
|
|
|
|
if (event.metaKey) {
|
|
|
|
message += ",metaKey=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
message += "}"
|
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function keyDownEvent(element, event) {
|
|
|
|
keyEvent(element, event, "key-down-event")
|
|
|
|
}
|
|
|
|
|
|
|
|
function keyUpEvent(element, event) {
|
|
|
|
keyEvent(element, event, "key-up-event")
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseEventData(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = ""
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
if (event.timeStamp) {
|
|
|
|
message += ",timeStamp=" + event.timeStamp;
|
|
|
|
}
|
|
|
|
if (event.button) {
|
|
|
|
message += ",button=" + event.button;
|
|
|
|
}
|
|
|
|
if (event.buttons) {
|
|
|
|
message += ",buttons=" + event.buttons;
|
|
|
|
}
|
|
|
|
if (event.clientX) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let x = event.clientX;
|
|
|
|
let el = element;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (el.parentElement) {
|
|
|
|
x += el.parentElement.scrollLeft;
|
|
|
|
}
|
|
|
|
while (el) {
|
|
|
|
x -= el.offsetLeft
|
|
|
|
el = el.parentElement
|
|
|
|
}
|
|
|
|
|
|
|
|
message += ",x=" + x + ",clientX=" + event.clientX;
|
|
|
|
}
|
|
|
|
if (event.clientY) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let y = event.clientY;
|
|
|
|
let el = element;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (el.parentElement) {
|
|
|
|
y += el.parentElement.scrollTop;
|
|
|
|
}
|
|
|
|
while (el) {
|
|
|
|
y -= el.offsetTop
|
|
|
|
el = el.parentElement
|
|
|
|
}
|
|
|
|
|
|
|
|
message += ",y=" + y + ",clientY=" + event.clientY;
|
|
|
|
}
|
|
|
|
if (event.screenX) {
|
|
|
|
message += ",screenX=" + event.screenX;
|
|
|
|
}
|
|
|
|
if (event.screenY) {
|
|
|
|
message += ",screenY=" + event.screenY;
|
|
|
|
}
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
message += ",ctrlKey=1";
|
|
|
|
}
|
|
|
|
if (event.shiftKey) {
|
|
|
|
message += ",shiftKey=1";
|
|
|
|
}
|
|
|
|
if (event.altKey) {
|
|
|
|
message += ",altKey=1";
|
|
|
|
}
|
|
|
|
if (event.metaKey) {
|
|
|
|
message += ",metaKey=1";
|
|
|
|
}
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseEvent(element, event, tag) {
|
|
|
|
event.stopPropagation();
|
|
|
|
//event.preventDefault()
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = tag + "{session=" + sessionID + ",id=" + element.id + mouseEventData(element, event) + "}";
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseDownEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "mouse-down")
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseUpEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "mouse-up")
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseMoveEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "mouse-move")
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseOverEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "mouse-over")
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseOutEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "mouse-out")
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "click-event")
|
|
|
|
event.preventDefault();
|
2023-01-03 14:56:57 +03:00
|
|
|
event.stopPropagation();
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function doubleClickEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "double-click-event")
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuEvent(element, event) {
|
|
|
|
mouseEvent(element, event, "context-menu-event")
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerEvent(element, event, tag) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = tag + "{session=" + sessionID + ",id=" + element.id + mouseEventData(element, event);
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
if (event.pointerId) {
|
|
|
|
message += ",pointerId=" + event.pointerId;
|
|
|
|
}
|
|
|
|
if (event.width) {
|
|
|
|
message += ",width=" + event.width;
|
|
|
|
}
|
|
|
|
if (event.height) {
|
|
|
|
message += ",height=" + event.height;
|
|
|
|
}
|
|
|
|
if (event.pressure) {
|
|
|
|
message += ",pressure=" + event.pressure;
|
|
|
|
}
|
|
|
|
if (event.tangentialPressure) {
|
|
|
|
message += ",tangentialPressure=" + event.tangentialPressure;
|
|
|
|
}
|
|
|
|
if (event.tiltX) {
|
|
|
|
message += ",tiltX=" + event.tiltX;
|
|
|
|
}
|
|
|
|
if (event.tiltY) {
|
|
|
|
message += ",tiltY=" + event.tiltY;
|
|
|
|
}
|
|
|
|
if (event.twist) {
|
|
|
|
message += ",twist=" + event.twist;
|
|
|
|
}
|
|
|
|
if (event.pointerType) {
|
|
|
|
message += ",pointerType=" + event.pointerType;
|
|
|
|
}
|
|
|
|
if (event.isPrimary) {
|
|
|
|
message += ",isPrimary=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
message += "}";
|
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerDownEvent(element, event) {
|
|
|
|
pointerEvent(element, event, "pointer-down")
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerUpEvent(element, event) {
|
|
|
|
pointerEvent(element, event, "pointer-up")
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerMoveEvent(element, event) {
|
|
|
|
pointerEvent(element, event, "pointer-move")
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerCancelEvent(element, event) {
|
|
|
|
pointerEvent(element, event, "pointer-cancel")
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerOverEvent(element, event) {
|
|
|
|
pointerEvent(element, event, "pointer-over")
|
|
|
|
}
|
|
|
|
|
|
|
|
function pointerOutEvent(element, event) {
|
|
|
|
pointerEvent(element, event, "pointer-out")
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchEvent(element, event, tag) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = tag + "{session=" + sessionID + ",id=" + element.id;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (event.timeStamp) {
|
|
|
|
message += ",timeStamp=" + event.timeStamp;
|
|
|
|
}
|
|
|
|
if (event.touches && event.touches.length > 0) {
|
|
|
|
message += ",touches=["
|
2024-01-15 16:13:46 +03:00
|
|
|
for (let i = 0; i < event.touches.length; i++) {
|
|
|
|
const touch = event.touches.item(i)
|
2021-09-07 17:36:50 +03:00
|
|
|
if (touch) {
|
|
|
|
if (i > 0) {
|
|
|
|
message += ","
|
|
|
|
}
|
|
|
|
message += "touch{identifier=" + touch.identifier;
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let x = touch.clientX;
|
|
|
|
let y = touch.clientY;
|
|
|
|
let el = element;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (el.parentElement) {
|
|
|
|
x += el.parentElement.scrollLeft;
|
|
|
|
y += el.parentElement.scrollTop;
|
|
|
|
}
|
|
|
|
while (el) {
|
|
|
|
x -= el.offsetLeft
|
|
|
|
y -= el.offsetTop
|
|
|
|
el = el.parentElement
|
|
|
|
}
|
|
|
|
|
|
|
|
message += ",x=" + x + ",y=" + y + ",clientX=" + touch.clientX + ",clientY=" + touch.clientY +
|
|
|
|
",screenX=" + touch.screenX + ",screenY=" + touch.screenY + ",radiusX=" + touch.radiusX +
|
|
|
|
",radiusY=" + touch.radiusY + ",rotationAngle=" + touch.rotationAngle + ",force=" + touch.force + "}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message += "]"
|
|
|
|
}
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
message += ",ctrlKey=1";
|
|
|
|
}
|
|
|
|
if (event.shiftKey) {
|
|
|
|
message += ",shiftKey=1";
|
|
|
|
}
|
|
|
|
if (event.altKey) {
|
|
|
|
message += ",altKey=1";
|
|
|
|
}
|
|
|
|
if (event.metaKey) {
|
|
|
|
message += ",metaKey=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
message += "}";
|
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchStartEvent(element, event) {
|
|
|
|
touchEvent(element, event, "touch-start")
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchEndEvent(element, event) {
|
|
|
|
touchEvent(element, event, "touch-end")
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchMoveEvent(element, event) {
|
|
|
|
touchEvent(element, event, "touch-move")
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchCancelEvent(element, event) {
|
|
|
|
touchEvent(element, event, "touch-cancel")
|
|
|
|
}
|
|
|
|
|
|
|
|
function dropDownListEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "itemSelected{session=" + sessionID + ",id=" + element.id + ",number=" + element.selectedIndex.toString() + "}"
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectDropDownListItem(elementId, number) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.selectedIndex = number;
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function listItemClickEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
2022-01-15 01:20:04 +03:00
|
|
|
|
2023-05-18 12:26:54 +03:00
|
|
|
if (element.getAttribute("data-disabled") == "1") {
|
2023-05-03 15:16:03 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let selected = false;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element.classList) {
|
2022-01-15 01:20:04 +03:00
|
|
|
const focusStyle = getListFocusedItemStyle(element);
|
|
|
|
const blurStyle = getListSelectedItemStyle(element);
|
|
|
|
selected = (element.classList.contains(focusStyle) || element.classList.contains(blurStyle));
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const list = element.parentNode.parentNode
|
2021-09-07 17:36:50 +03:00
|
|
|
if (list) {
|
|
|
|
if (!selected) {
|
|
|
|
selectListItem(list, element, true)
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "itemClick{session=" + sessionID + ",id=" + list.id + "}"
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getListItemNumber(itemId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const pos = itemId.indexOf("-")
|
2021-09-07 17:36:50 +03:00
|
|
|
if (pos >= 0) {
|
|
|
|
return parseInt(itemId.substring(pos+1))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
function getStyleAttribute(element, attr, defValue) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const result = element.getAttribute(attr);
|
2022-01-15 01:20:04 +03:00
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return defValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getListFocusedItemStyle(element) {
|
|
|
|
return getStyleAttribute(element, "data-focusitemstyle", "ruiListItemFocused");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getListSelectedItemStyle(element) {
|
|
|
|
return getStyleAttribute(element, "data-bluritemstyle", "ruiListItemSelected");
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function selectListItem(element, item, needSendMessage) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentId = element.getAttribute("data-current");
|
|
|
|
let message;
|
2022-01-15 01:20:04 +03:00
|
|
|
const focusStyle = getListFocusedItemStyle(element);
|
|
|
|
const blurStyle = getListSelectedItemStyle(element);
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
if (currentId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = document.getElementById(currentId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (current) {
|
|
|
|
if (current.classList) {
|
|
|
|
current.classList.remove(focusStyle, blurStyle);
|
|
|
|
}
|
|
|
|
if (sendMessage) {
|
|
|
|
message = "itemUnselected{session=" + sessionID + ",id=" + element.id + "}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
if (element === document.activeElement) {
|
|
|
|
if (item.classList) {
|
|
|
|
item.classList.add(focusStyle);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (item.classList) {
|
|
|
|
item.classList.add(blurStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
element.setAttribute("data-current", item.id);
|
|
|
|
if (sendMessage) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const number = getListItemNumber(item.id)
|
2021-09-07 17:36:50 +03:00
|
|
|
if (number != undefined) {
|
|
|
|
message = "itemSelected{session=" + sessionID + ",id=" + element.id + ",number=" + number + "}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 20:25:45 +03:00
|
|
|
if (item.scrollIntoViewIfNeeded) {
|
|
|
|
item.scrollIntoViewIfNeeded()
|
|
|
|
} else {
|
|
|
|
item.scrollIntoView({block: "nearest", inline: "nearest"});
|
|
|
|
}
|
|
|
|
/*
|
2024-01-15 16:13:46 +03:00
|
|
|
let left = item.offsetLeft - element.offsetLeft;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (left < element.scrollLeft) {
|
|
|
|
element.scrollLeft = left;
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let top = item.offsetTop - element.offsetTop;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (top < element.scrollTop) {
|
|
|
|
element.scrollTop = top;
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let right = left + item.offsetWidth;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (right > element.scrollLeft + element.clientWidth) {
|
|
|
|
element.scrollLeft = right - element.clientWidth;
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let bottom = top + item.offsetHeight
|
2021-09-07 17:36:50 +03:00
|
|
|
if (bottom > element.scrollTop + element.clientHeight) {
|
|
|
|
element.scrollTop = bottom - element.clientHeight;
|
2022-01-16 20:25:45 +03:00
|
|
|
}*/
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (needSendMessage && message != undefined) {
|
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
function findRightListItem(list, x, y) {
|
2021-11-11 13:23:41 +03:00
|
|
|
list = list.childNodes[0];
|
2024-01-15 16:13:46 +03:00
|
|
|
let result;
|
|
|
|
for (const item of list.childNodes) {
|
2023-05-03 15:16:03 +03:00
|
|
|
if (item.getAttribute("data-disabled") == "1") {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item.offsetLeft >= x) {
|
|
|
|
if (result) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const result_dy = Math.abs(result.offsetTop - y);
|
|
|
|
const item_dy = Math.abs(item.offsetTop - y);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item_dy < result_dy || (item_dy == result_dy && (item.offsetLeft - x) < (result.offsetLeft - x))) {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
function findLeftListItem(list, x, y) {
|
2021-11-11 13:23:41 +03:00
|
|
|
list = list.childNodes[0];
|
2024-01-15 16:13:46 +03:00
|
|
|
let result;
|
|
|
|
for (const item of list.childNodes) {
|
2023-05-03 15:16:03 +03:00
|
|
|
if (item.getAttribute("data-disabled") == "1") {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item.offsetLeft < x) {
|
|
|
|
if (result) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const result_dy = Math.abs(result.offsetTop - y);
|
|
|
|
const item_dy = Math.abs(item.offsetTop - y);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item_dy < result_dy || (item_dy == result_dy && (x - item.offsetLeft) < (x - result.offsetLeft))) {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
function findTopListItem(list, x, y) {
|
2021-11-11 13:23:41 +03:00
|
|
|
list = list.childNodes[0];
|
2024-01-15 16:13:46 +03:00
|
|
|
let result;
|
|
|
|
for (const item of list.childNodes) {
|
2023-05-03 15:16:03 +03:00
|
|
|
if (item.getAttribute("data-disabled") == "1") {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item.offsetTop < y) {
|
|
|
|
if (result) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const result_dx = Math.abs(result.offsetLeft - x);
|
|
|
|
const item_dx = Math.abs(item.offsetLeft - x);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item_dx < result_dx || (item_dx == result_dx && (y - item.offsetTop) < (y - result.offsetTop))) {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
function findBottomListItem(list, x, y) {
|
2021-11-11 13:23:41 +03:00
|
|
|
list = list.childNodes[0];
|
2024-01-15 16:13:46 +03:00
|
|
|
let result;
|
|
|
|
for (const item of list.childNodes) {
|
2023-05-03 15:16:03 +03:00
|
|
|
if (item.getAttribute("data-disabled") == "1") {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item.offsetTop >= y) {
|
|
|
|
if (result) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const result_dx = Math.abs(result.offsetLeft - x);
|
|
|
|
const item_dx = Math.abs(item.offsetLeft - x);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (item_dx < result_dx || (item_dx == result_dx && (item.offsetTop - y) < (result.offsetTop - y))) {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
function getKey(event) {
|
2021-09-07 17:36:50 +03:00
|
|
|
if (event.key) {
|
2022-01-15 01:20:04 +03:00
|
|
|
return event.key;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.keyCode) {
|
2021-09-07 17:36:50 +03:00
|
|
|
switch (event.keyCode) {
|
2022-01-15 01:20:04 +03:00
|
|
|
case 13: return "Enter";
|
|
|
|
case 32: return " ";
|
|
|
|
case 33: return "PageUp";
|
|
|
|
case 34: return "PageDown";
|
|
|
|
case 35: return "End";
|
|
|
|
case 36: return "Home";
|
|
|
|
case 37: return "ArrowLeft";
|
|
|
|
case 38: return "ArrowUp";
|
|
|
|
case 39: return "ArrowRight";
|
|
|
|
case 40: return "ArrowDown";
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function listViewKeyDownEvent(element, event) {
|
|
|
|
const key = getKey(event);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (key) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentId = element.getAttribute("data-current");
|
|
|
|
let current
|
2021-09-07 17:36:50 +03:00
|
|
|
if (currentId) {
|
|
|
|
current = document.getElementById(currentId);
|
|
|
|
//number = getListItemNumber(currentId);
|
|
|
|
}
|
|
|
|
if (current) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let item
|
2021-09-07 17:36:50 +03:00
|
|
|
switch (key) {
|
2023-05-03 15:16:03 +03:00
|
|
|
case " ":
|
|
|
|
case "Enter":
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "itemClick{session=" + sessionID + ",id=" + element.id + "}";
|
2023-05-03 15:16:03 +03:00
|
|
|
sendMessage(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowLeft":
|
|
|
|
item = findLeftListItem(element, current.offsetLeft, current.offsetTop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowRight":
|
|
|
|
item = findRightListItem(element, current.offsetLeft + current.offsetWidth, current.offsetTop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowDown":
|
|
|
|
item = findBottomListItem(element, current.offsetLeft, current.offsetTop + current.offsetHeight);
|
|
|
|
break;
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2023-05-03 15:16:03 +03:00
|
|
|
case "ArrowUp":
|
|
|
|
item = findTopListItem(element, current.offsetLeft, current.offsetTop);
|
|
|
|
break;
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2023-05-03 15:16:03 +03:00
|
|
|
case "Home":
|
|
|
|
item = element.childNodes[0];
|
|
|
|
break;
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2023-05-03 15:16:03 +03:00
|
|
|
case "End":
|
|
|
|
item = element.childNodes[element.childNodes.length - 1];
|
|
|
|
break;
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2023-05-03 15:16:03 +03:00
|
|
|
case "PageUp":
|
|
|
|
// TODO
|
|
|
|
break;
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2023-05-03 15:16:03 +03:00
|
|
|
case "PageDown":
|
|
|
|
// TODO
|
|
|
|
break;
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2023-05-03 15:16:03 +03:00
|
|
|
default:
|
|
|
|
return;
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
if (item && item !== current) {
|
|
|
|
selectListItem(element, item, true);
|
|
|
|
}
|
2023-05-03 15:16:03 +03:00
|
|
|
} else {
|
|
|
|
switch (key) {
|
|
|
|
case " ":
|
|
|
|
case "Enter":
|
|
|
|
case "ArrowLeft":
|
|
|
|
case "ArrowUp":
|
|
|
|
case "ArrowRight":
|
|
|
|
case "ArrowDown":
|
|
|
|
case "Home":
|
|
|
|
case "End":
|
|
|
|
case "PageUp":
|
|
|
|
case "PageDown":
|
2024-01-15 16:13:46 +03:00
|
|
|
const list = element.childNodes[0];
|
|
|
|
for (const item of list.childNodes) {
|
2023-05-03 15:16:03 +03:00
|
|
|
if (item.getAttribute("data-disabled") == "1") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
selectListItem(element, item, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function listViewFocusEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentId = element.getAttribute("data-current");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (currentId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = document.getElementById(currentId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (current) {
|
|
|
|
if (current.classList) {
|
2022-01-15 01:20:04 +03:00
|
|
|
current.classList.remove(getListSelectedItemStyle(element));
|
|
|
|
current.classList.add(getListFocusedItemStyle(element));
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function listViewBlurEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentId = element.getAttribute("data-current");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (currentId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = document.getElementById(currentId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (current) {
|
|
|
|
if (current.classList) {
|
2022-01-15 01:20:04 +03:00
|
|
|
current.classList.remove(getListFocusedItemStyle(element));
|
|
|
|
current.classList.add(getListSelectedItemStyle(element));
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectRadioButton(radioButtonId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(radioButtonId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const list = element.parentNode
|
2021-09-07 17:36:50 +03:00
|
|
|
if (list) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = list.getAttribute("data-current");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (current) {
|
|
|
|
if (current === radioButtonId) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const mark = document.getElementById(current + "mark");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (mark) {
|
|
|
|
//mark.hidden = true
|
|
|
|
mark.style.visibility = "hidden"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const mark = document.getElementById(radioButtonId + "mark");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (mark) {
|
|
|
|
//mark.hidden = false
|
|
|
|
mark.style.visibility = "visible"
|
|
|
|
}
|
|
|
|
list.setAttribute("data-current", radioButtonId);
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "radioButtonSelected{session=" + sessionID + ",id=" + list.id + ",radioButton=" + radioButtonId + "}"
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage(message);
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function unselectRadioButtons(radioButtonsId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const list = document.getElementById(radioButtonsId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (list) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = list.getAttribute("data-current");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (current) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const mark = document.getElementById(current + "mark");
|
2021-09-07 17:36:50 +03:00
|
|
|
if (mark) {
|
|
|
|
mark.style.visibility = "hidden"
|
|
|
|
}
|
|
|
|
|
|
|
|
list.removeAttribute("data-current");
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "radioButtonUnselected{session=" + sessionID + ",id=" + list.id + "}"
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage(message);
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function radioButtonClickEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
selectRadioButton(element.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
function radioButtonKeyClickEvent(element, event) {
|
|
|
|
if (enterOrSpaceKeyClickEvent(event)) {
|
|
|
|
radioButtonClickEvent(element, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editViewInputEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let text = element.value
|
2022-12-18 18:22:58 +03:00
|
|
|
text = text.replaceAll(/\\/g, "\\\\")
|
|
|
|
text = text.replaceAll(/\"/g, "\\\"")
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "textChanged{session=" + sessionID + ",id=" + element.id + ",text=\"" + text + "\"}"
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setInputValue(elementId, text) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.value = text;
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 14:59:25 +03:00
|
|
|
function fileSelectedEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const files = element.files;
|
2021-11-04 14:59:25 +03:00
|
|
|
if (files) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "fileSelected{session=" + sessionID + ",id=" + element.id + ",files=[";
|
|
|
|
for(let i = 0; i < files.length; i++) {
|
2021-11-04 14:59:25 +03:00
|
|
|
if (i > 0) {
|
|
|
|
message += ",";
|
|
|
|
}
|
|
|
|
message += "_{name=\"" + files[i].name +
|
|
|
|
"\",last-modified=" + files[i].lastModified +
|
|
|
|
",size=" + files[i].size +
|
|
|
|
",mime-type=\"" + files[i].type + "\"}";
|
|
|
|
}
|
|
|
|
sendMessage(message + "]}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadSelectedFile(elementId, index) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-11-04 14:59:25 +03:00
|
|
|
if (element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const files = element.files;
|
2021-11-04 14:59:25 +03:00
|
|
|
if (files && index >= 0 && index < files.length) {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function() {
|
|
|
|
sendMessage("fileLoaded{session=" + sessionID + ",id=" + element.id +
|
|
|
|
",index=" + index +
|
|
|
|
",name=\"" + files[index].name +
|
|
|
|
"\",last-modified=" + files[index].lastModified +
|
|
|
|
",size=" + files[index].size +
|
|
|
|
",mime-type=\"" + files[index].type +
|
|
|
|
"\",data=`" + reader.result + "`}");
|
|
|
|
}
|
|
|
|
reader.onerror = function(error) {
|
|
|
|
sendMessage("fileLoadingError{session=" + sessionID + ",id=" + element.id + ",index=" + index + ",error=`" + error + "`}");
|
|
|
|
}
|
|
|
|
reader.readAsDataURL(files[index]);
|
|
|
|
} else {
|
|
|
|
sendMessage("fileLoadingError{session=" + sessionID + ",id=" + element.id + ",index=" + index + ",error=`File not found`}");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendMessage("fileLoadingError{session=" + sessionID + ",id=" + element.id + ",index=" + index + ",error=`Invalid FilePicker id`}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function startResize(element, mx, my, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const view = element.parentNode;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let startX = event.clientX;
|
|
|
|
let startY = event.clientY;
|
|
|
|
let startWidth = view.offsetWidth
|
|
|
|
let startHeight = view.offsetHeight
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
document.addEventListener("mousemove", moveHandler, true);
|
|
|
|
document.addEventListener("mouseup", upHandler, true);
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
function moveHandler(e) {
|
|
|
|
if (mx != 0) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let width = startWidth + (e.clientX - startX) * mx;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (width <= 0) {
|
|
|
|
width = 1;
|
|
|
|
}
|
|
|
|
view.style.width = width + "px";
|
|
|
|
sendMessage("widthChanged{session=" + sessionID + ",id=" + view.id + ",width=" + view.style.width + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (my != 0) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let height = startHeight + (e.clientY - startY) * my;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (height <= 0) {
|
|
|
|
height = 1;
|
|
|
|
}
|
|
|
|
view.style.height = height + "px";
|
|
|
|
sendMessage("heightChanged{session=" + sessionID + ",id=" + view.id + ",height=" + view.style.height + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
scanElementsSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
function upHandler (e) {
|
|
|
|
document.removeEventListener("mouseup", upHandler, true);
|
|
|
|
document.removeEventListener("mousemove", moveHandler, true);
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 17:58:17 +03:00
|
|
|
function transitionStartEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "transition-start-event{session=" + sessionID + ",id=" + element.id;
|
2021-10-04 17:58:17 +03:00
|
|
|
if (event.propertyName) {
|
|
|
|
message += ",property=" + event.propertyName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function transitionRunEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "transition-run-event{session=" + sessionID + ",id=" + element.id;
|
2021-10-04 17:58:17 +03:00
|
|
|
if (event.propertyName) {
|
|
|
|
message += ",property=" + event.propertyName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function transitionEndEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "transition-end-event{session=" + sessionID + ",id=" + element.id;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (event.propertyName) {
|
|
|
|
message += ",property=" + event.propertyName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function transitionCancelEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "transition-cancel-event{session=" + sessionID + ",id=" + element.id;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (event.propertyName) {
|
|
|
|
message += ",property=" + event.propertyName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2021-10-04 17:58:17 +03:00
|
|
|
function animationStartEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "animation-start-event{session=" + sessionID + ",id=" + element.id;
|
2021-10-04 17:58:17 +03:00
|
|
|
if (event.animationName) {
|
|
|
|
message += ",name=" + event.animationName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function animationEndEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "animation-end-event{session=" + sessionID + ",id=" + element.id;
|
2021-10-04 17:58:17 +03:00
|
|
|
if (event.animationName) {
|
|
|
|
message += ",name=" + event.animationName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function animationCancelEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "animation-cancel-event{session=" + sessionID + ",id=" + element.id;
|
2021-10-04 17:58:17 +03:00
|
|
|
if (event.animationName) {
|
|
|
|
message += ",name=" + event.animationName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function animationIterationEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "animation-iteration-event{session=" + sessionID + ",id=" + element.id;
|
2021-10-04 17:58:17 +03:00
|
|
|
if (event.animationName) {
|
|
|
|
message += ",name=" + event.animationName
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function stackTransitionEndEvent(stackId, propertyName, event) {
|
2021-10-04 17:58:17 +03:00
|
|
|
sendMessage("transition-end-event{session=" + sessionID + ",id=" + stackId + ",property=" + propertyName + "}");
|
2021-09-07 17:36:50 +03:00
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const images = new Map();
|
2022-10-27 16:14:30 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function loadImage(url) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let img = images.get(url);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (img != undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
img = new Image();
|
|
|
|
img.addEventListener("load", function() {
|
|
|
|
images.set(url, img)
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "imageLoaded{session=" + sessionID + ",url=\"" + url + "\"";
|
2021-09-07 17:36:50 +03:00
|
|
|
if (img.naturalWidth) {
|
|
|
|
message += ",width=" + img.naturalWidth
|
|
|
|
}
|
|
|
|
if (img.naturalHeight) {
|
|
|
|
message += ",height=" + img.naturalHeight
|
|
|
|
}
|
|
|
|
sendMessage(message + "}")
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
img.addEventListener("error", function(event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "imageError{session=" + sessionID + ",url=\"" + url + "\"";
|
2021-09-07 17:36:50 +03:00
|
|
|
if (event && event.message) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const text = event.message.replaceAll(new RegExp("\"", 'g'), "\\\"")
|
2021-09-07 17:36:50 +03:00
|
|
|
message += ",message=\"" + text + "\"";
|
|
|
|
}
|
|
|
|
sendMessage(message + "}")
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
img.src = url;
|
|
|
|
}
|
|
|
|
|
2022-11-02 21:22:15 +03:00
|
|
|
function loadInlineImage(url, content) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let img = images.get(url);
|
2022-11-02 21:22:15 +03:00
|
|
|
if (img != undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
img = new Image();
|
|
|
|
img.addEventListener("load", function() {
|
|
|
|
images.set(url, img)
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "imageLoaded{session=" + sessionID + ",url=\"" + url + "\"";
|
2022-11-02 21:22:15 +03:00
|
|
|
if (img.naturalWidth) {
|
|
|
|
message += ",width=" + img.naturalWidth
|
|
|
|
}
|
|
|
|
if (img.naturalHeight) {
|
|
|
|
message += ",height=" + img.naturalHeight
|
|
|
|
}
|
|
|
|
sendMessage(message + "}")
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
img.addEventListener("error", function(event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "imageError{session=" + sessionID + ",url=\"" + url + "\"";
|
2022-11-02 21:22:15 +03:00
|
|
|
if (event && event.message) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const text = event.message.replaceAll(new RegExp("\"", 'g'), "\\\"")
|
2022-11-02 21:22:15 +03:00
|
|
|
message += ",message=\"" + text + "\"";
|
|
|
|
}
|
|
|
|
sendMessage(message + "}")
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
img.src = content;
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function clickClosePopup(element, e) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const popupId = element.getAttribute("data-popupId");
|
2021-09-07 17:36:50 +03:00
|
|
|
sendMessage("clickClosePopup{session=" + sessionID + ",id=" + popupId + "}")
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollTo(elementId, x, y) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.scrollTo(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToStart(elementId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToEnd(elementId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.scrollTo(0, element.scrollHeight - element.offsetHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function focus(elementId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
function blur(elementId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
if (element) {
|
|
|
|
element.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 20:16:40 +03:00
|
|
|
function blurCurrent() {
|
|
|
|
if (document.activeElement != document.body) {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
function playerEvent(element, tag) {
|
|
|
|
//event.stopPropagation();
|
|
|
|
sendMessage(tag + "{session=" + sessionID + ",id=" + element.id + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function playerTimeUpdatedEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "time-update-event{session=" + sessionID + ",id=" + element.id + ",value=";
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element.currentTime) {
|
|
|
|
message += element.currentTime;
|
|
|
|
} else {
|
|
|
|
message += "0";
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function playerDurationChangedEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "duration-changed-event{session=" + sessionID + ",id=" + element.id + ",value=";
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element.duration) {
|
|
|
|
message += element.duration;
|
|
|
|
} else {
|
|
|
|
message += "0";
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function playerVolumeChangedEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "volume-changed-event{session=" + sessionID + ",id=" + element.id + ",value=";
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element.volume && !element.muted) {
|
|
|
|
message += element.volume;
|
|
|
|
} else {
|
|
|
|
message += "0";
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function playerRateChangedEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "rate-changed-event{session=" + sessionID + ",id=" + element.id + ",value=";
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element.playbackRate) {
|
|
|
|
message += element.playbackRate;
|
|
|
|
} else {
|
|
|
|
message += "0";
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function playerErrorEvent(element) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let message = "player-error-event{session=" + sessionID + ",id=" + element.id;
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element.error) {
|
|
|
|
if (element.error.code) {
|
|
|
|
message += ",code=" + element.error.code;
|
|
|
|
}
|
|
|
|
if (element.error.message) {
|
|
|
|
message += ",message=`" + element.error.message + "`";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendMessage(message + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function setMediaMuted(elementId, value) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.muted = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mediaPlay(elementId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element && element.play) {
|
|
|
|
element.play()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mediaPause(elementId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element && element.pause) {
|
|
|
|
element.pause()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mediaSetSetCurrentTime(elementId, time) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.currentTime = time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mediaSetPlaybackRate(elementId, time) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.playbackRate = time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mediaSetVolume(elementId, volume) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById(elementId);
|
2021-09-07 17:36:50 +03:00
|
|
|
if (element) {
|
|
|
|
element.volume = volume
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 09:43:13 +03:00
|
|
|
|
2022-11-23 15:10:29 +03:00
|
|
|
function startDownload(url, filename) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const element = document.getElementById("ruiDownloader");
|
2021-11-07 09:43:13 +03:00
|
|
|
if (element) {
|
|
|
|
element.href = url;
|
|
|
|
element.setAttribute("download", filename);
|
|
|
|
element.click();
|
|
|
|
}
|
|
|
|
}
|
2021-11-10 16:26:19 +03:00
|
|
|
|
2022-11-01 20:13:09 +03:00
|
|
|
function setTitle(title) {
|
|
|
|
document.title = title;
|
|
|
|
}
|
|
|
|
|
2021-11-10 16:26:19 +03:00
|
|
|
function setTitleColor(color) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const metas = document.getElementsByTagName('meta');
|
2021-11-10 16:26:19 +03:00
|
|
|
if (metas) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const item = metas.namedItem('theme-color');
|
2021-11-10 16:26:19 +03:00
|
|
|
if (item) {
|
|
|
|
item.setAttribute('content', color)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const meta = document.createElement('meta');
|
2021-11-10 16:26:19 +03:00
|
|
|
meta.setAttribute('name', 'theme-color');
|
|
|
|
meta.setAttribute('content', color);
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(meta);
|
2021-11-20 16:53:45 +03:00
|
|
|
}
|
|
|
|
|
2022-11-01 20:13:09 +03:00
|
|
|
function openURL(url) {
|
|
|
|
window.open(url, "_blank");
|
|
|
|
}
|
|
|
|
|
2021-11-20 16:53:45 +03:00
|
|
|
function detailsEvent(element) {
|
|
|
|
sendMessage("details-open{session=" + sessionID + ",id=" + element.id + ",open=" + (element.open ? "1}" : "0}"));
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTableFocusedItemStyle(element) {
|
|
|
|
return getStyleAttribute(element, "data-focusitemstyle", "ruiCurrentTableCellFocused");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTableSelectedItemStyle(element) {
|
|
|
|
return getStyleAttribute(element, "data-bluritemstyle", "ruiCurrentTableCell");
|
|
|
|
}
|
|
|
|
|
|
|
|
function tableViewFocusEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentId = element.getAttribute("data-current");
|
2022-01-15 01:20:04 +03:00
|
|
|
if (currentId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = document.getElementById(currentId);
|
2022-01-15 01:20:04 +03:00
|
|
|
if (current) {
|
|
|
|
if (current.classList) {
|
|
|
|
current.classList.remove(getTableSelectedItemStyle(element));
|
|
|
|
current.classList.add(getTableFocusedItemStyle(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tableViewBlurEvent(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const currentId = element.getAttribute("data-current");
|
2022-01-15 01:20:04 +03:00
|
|
|
if (currentId) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const current = document.getElementById(currentId);
|
2022-01-15 01:20:04 +03:00
|
|
|
if (current && current.classList) {
|
|
|
|
current.classList.remove(getTableFocusedItemStyle(element));
|
|
|
|
current.classList.add(getTableSelectedItemStyle(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-07 19:26:02 +03:00
|
|
|
function setTableCellCursorByID(tableID, row, column) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const table = document.getElementById(tableID);
|
2023-05-07 19:26:02 +03:00
|
|
|
if (table) {
|
|
|
|
if (!setTableCellCursor(table, row, column)) {
|
|
|
|
const focusStyle = getTableFocusedItemStyle(table);
|
|
|
|
const oldCellID = table.getAttribute("data-current");
|
|
|
|
if (oldCellID) {
|
|
|
|
const oldCell = document.getElementById(oldCellID);
|
|
|
|
if (oldCell && oldCell.classList) {
|
|
|
|
oldCell.classList.remove(focusStyle);
|
|
|
|
oldCell.classList.remove(getTableSelectedItemStyle(table));
|
|
|
|
}
|
|
|
|
table.removeAttribute("data-current");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
function setTableCellCursor(element, row, column) {
|
|
|
|
const cellID = element.id + "-" + row + "-" + column;
|
2024-01-15 16:13:46 +03:00
|
|
|
const cell = document.getElementById(cellID);
|
2022-01-15 02:06:10 +03:00
|
|
|
if (!cell || cell.getAttribute("data-disabled")) {
|
2022-01-15 01:20:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const focusStyle = getTableFocusedItemStyle(element);
|
|
|
|
const oldCellID = element.getAttribute("data-current");
|
|
|
|
if (oldCellID) {
|
|
|
|
const oldCell = document.getElementById(oldCellID);
|
|
|
|
if (oldCell && oldCell.classList) {
|
|
|
|
oldCell.classList.remove(focusStyle);
|
|
|
|
oldCell.classList.remove(getTableSelectedItemStyle(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cell.classList.add(focusStyle);
|
|
|
|
element.setAttribute("data-current", cellID);
|
2022-01-16 20:25:45 +03:00
|
|
|
if (cell.scrollIntoViewIfNeeded) {
|
|
|
|
cell.scrollIntoViewIfNeeded()
|
|
|
|
} else {
|
|
|
|
cell.scrollIntoView({block: "nearest", inline: "nearest"});
|
|
|
|
}
|
2022-01-15 01:20:04 +03:00
|
|
|
|
|
|
|
sendMessage("currentCell{session=" + sessionID + ",id=" + element.id +
|
|
|
|
",row=" + row + ",column=" + column + "}");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveTableCellCursor(element, row, column, dr, dc) {
|
|
|
|
const rows = element.getAttribute("data-rows");
|
|
|
|
if (!rows) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const columns = element.getAttribute("data-columns");
|
|
|
|
if (!columns) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rowCount = parseInt(rows);
|
|
|
|
const columnCount = parseInt(columns);
|
|
|
|
|
|
|
|
row += dr;
|
|
|
|
column += dc;
|
|
|
|
while (row >= 0 && row < rowCount && column >= 0 && column < columnCount) {
|
|
|
|
if (setTableCellCursor(element, row, column)) {
|
|
|
|
return;
|
|
|
|
} else if (dr == 0) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let r2 = row - 1;
|
2022-01-15 01:20:04 +03:00
|
|
|
while (r2 >= 0) {
|
|
|
|
if (setTableCellCursor(element, r2, column)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
r2--;
|
|
|
|
}
|
|
|
|
} else if (dc == 0) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let c2 = column - 1;
|
2022-01-15 01:20:04 +03:00
|
|
|
while (c2 >= 0) {
|
|
|
|
if (setTableCellCursor(element, row, c2)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
c2--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
row += dr;
|
|
|
|
column += dc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tableViewCellKeyDownEvent(element, event) {
|
|
|
|
const key = getKey(event);
|
2022-01-16 20:25:45 +03:00
|
|
|
if (!key) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentId = element.getAttribute("data-current");
|
|
|
|
if (!currentId || currentId == "") {
|
|
|
|
switch (key) {
|
|
|
|
case "ArrowLeft":
|
|
|
|
case "ArrowRight":
|
|
|
|
case "ArrowDown":
|
|
|
|
case "ArrowUp":
|
|
|
|
case "Home":
|
|
|
|
case "End":
|
|
|
|
case "PageUp":
|
|
|
|
case "PageDown":
|
2023-05-04 13:37:26 +03:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2022-01-16 20:25:45 +03:00
|
|
|
const rows = element.getAttribute("data-rows");
|
|
|
|
const columns = element.getAttribute("data-columns");
|
|
|
|
if (rows && columns) {
|
|
|
|
const rowCount = parseInt(rows);
|
|
|
|
const columnCount = parseInt(rows);
|
2024-01-15 16:13:46 +03:00
|
|
|
let row = 0;
|
2022-01-16 20:25:45 +03:00
|
|
|
while (row < rowCount) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let column = 0;
|
2022-01-16 20:25:45 +03:00
|
|
|
while (columns < columnCount) {
|
|
|
|
if (setTableCellCursor(element, row, column)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
column++;
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
row++;
|
|
|
|
}
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
break;
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const elements = currentId.split("-");
|
|
|
|
if (elements.length >= 3) {
|
|
|
|
const row = parseInt(elements[1], 10)
|
|
|
|
const column = parseInt(elements[2], 10)
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
switch (key) {
|
2022-01-16 20:25:45 +03:00
|
|
|
case " ":
|
|
|
|
case "Enter":
|
|
|
|
sendMessage("cellClick{session=" + sessionID + ",id=" + element.id +
|
|
|
|
",row=" + row + ",column=" + column + "}");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowLeft":
|
|
|
|
moveTableCellCursor(element, row, column, 0, -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowRight":
|
|
|
|
moveTableCellCursor(element, row, column, 0, 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowDown":
|
|
|
|
moveTableCellCursor(element, row, column, 1, 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowUp":
|
|
|
|
moveTableCellCursor(element, row, column, -1, 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Home":
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "End":
|
2024-01-15 16:13:46 +03:00
|
|
|
/*
|
|
|
|
for (let newRow = rowCount-1; newRow > row; newRow--) {
|
2022-01-16 20:25:45 +03:00
|
|
|
if (setTableRowCursor(element, newRow)) {
|
|
|
|
break;
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
2024-01-15 16:13:46 +03:00
|
|
|
}
|
|
|
|
*/
|
2022-01-16 20:25:45 +03:00
|
|
|
// TODO
|
|
|
|
break;
|
2022-01-15 01:20:04 +03:00
|
|
|
|
2022-01-16 20:25:45 +03:00
|
|
|
case "PageUp":
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "PageDown":
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
|
2022-01-16 20:25:45 +03:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
} else {
|
|
|
|
element.setAttribute("data-current", "");
|
|
|
|
}
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
|
2023-05-07 19:26:02 +03:00
|
|
|
function setTableRowCursorByID(tableID, row) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const table = document.getElementById(tableID);
|
2023-05-07 19:26:02 +03:00
|
|
|
if (table) {
|
|
|
|
if (!setTableRowCursor(table, row)) {
|
|
|
|
const focusStyle = getTableFocusedItemStyle(table);
|
|
|
|
const oldRowID = table.getAttribute("data-current");
|
|
|
|
if (oldRowID) {
|
|
|
|
const oldRow = document.getElementById(oldRowID);
|
|
|
|
if (oldRow && oldRow.classList) {
|
|
|
|
oldRow.classList.remove(focusStyle);
|
|
|
|
oldRow.classList.remove(getTableSelectedItemStyle(table));
|
|
|
|
}
|
|
|
|
table.removeAttribute("data-current");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
function setTableRowCursor(element, row) {
|
|
|
|
const tableRowID = element.id + "-" + row;
|
2024-01-15 16:13:46 +03:00
|
|
|
const tableRow = document.getElementById(tableRowID);
|
2022-01-15 02:06:10 +03:00
|
|
|
if (!tableRow || tableRow.getAttribute("data-disabled")) {
|
2022-01-15 01:20:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const focusStyle = getTableFocusedItemStyle(element);
|
|
|
|
const oldRowID = element.getAttribute("data-current");
|
|
|
|
if (oldRowID) {
|
|
|
|
const oldRow = document.getElementById(oldRowID);
|
|
|
|
if (oldRow && oldRow.classList) {
|
|
|
|
oldRow.classList.remove(focusStyle);
|
|
|
|
oldRow.classList.remove(getTableSelectedItemStyle(element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tableRow.classList.add(focusStyle);
|
|
|
|
element.setAttribute("data-current", tableRowID);
|
2022-01-16 20:25:45 +03:00
|
|
|
if (tableRow.scrollIntoViewIfNeeded) {
|
|
|
|
tableRow.scrollIntoViewIfNeeded()
|
|
|
|
} else {
|
|
|
|
tableRow.scrollIntoView({block: "nearest", inline: "nearest"});
|
|
|
|
}
|
2022-01-15 01:20:04 +03:00
|
|
|
|
|
|
|
sendMessage("currentRow{session=" + sessionID + ",id=" + element.id + ",row=" + row + "}");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveTableRowCursor(element, row, dr) {
|
|
|
|
const rows = element.getAttribute("data-rows");
|
|
|
|
if (!rows) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rowCount = parseInt(rows);
|
|
|
|
row += dr;
|
|
|
|
while (row >= 0 && row < rowCount) {
|
|
|
|
if (setTableRowCursor(element, row)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
row += dr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tableViewRowKeyDownEvent(element, event) {
|
|
|
|
const key = getKey(event);
|
|
|
|
if (key) {
|
|
|
|
const currentId = element.getAttribute("data-current");
|
|
|
|
if (currentId) {
|
|
|
|
const elements = currentId.split("-");
|
|
|
|
if (elements.length >= 2) {
|
|
|
|
const row = parseInt(elements[1], 10);
|
|
|
|
switch (key) {
|
|
|
|
case " ":
|
|
|
|
case "Enter":
|
|
|
|
sendMessage("rowClick{session=" + sessionID + ",id=" + element.id + ",row=" + row + "}");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowDown":
|
|
|
|
moveTableRowCursor(element, row, 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ArrowUp":
|
|
|
|
moveTableRowCursor(element, row, -1)
|
|
|
|
break;
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
case "Home":
|
|
|
|
for (let newRow = 0; newRow < row; newRow++) {
|
2022-01-15 01:20:04 +03:00
|
|
|
if (setTableRowCursor(element, newRow)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2024-01-15 16:13:46 +03:00
|
|
|
|
|
|
|
case "End":
|
|
|
|
for (let newRow = rowCount-1; newRow > row; newRow--) {
|
2022-01-15 01:20:04 +03:00
|
|
|
if (setTableRowCursor(element, newRow)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2024-01-15 16:13:46 +03:00
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
case "PageUp":
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "PageDown":
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case "ArrowLeft":
|
|
|
|
case "ArrowRight":
|
|
|
|
case "ArrowDown":
|
|
|
|
case "ArrowUp":
|
|
|
|
case "Home":
|
|
|
|
case "End":
|
|
|
|
case "PageUp":
|
|
|
|
case "PageDown":
|
|
|
|
const rows = element.getAttribute("data-rows");
|
|
|
|
if (rows) {
|
|
|
|
const rowCount = parseInt(rows);
|
2024-01-15 16:13:46 +03:00
|
|
|
let row = 0;
|
2022-01-15 01:20:04 +03:00
|
|
|
while (row < rowCount) {
|
|
|
|
if (setTableRowCursor(element, row)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
function tableCellClickEvent(element, event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const elements = element.id.split("-");
|
|
|
|
if (elements.length < 3) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const tableID = elements[0];
|
|
|
|
const row = parseInt(elements[1], 10);
|
|
|
|
const column = parseInt(elements[2], 10);
|
|
|
|
const table = document.getElementById(tableID);
|
|
|
|
if (table) {
|
|
|
|
const selection = table.getAttribute("data-selection");
|
|
|
|
if (selection == "cell") {
|
|
|
|
const currentID = table.getAttribute("data-current");
|
|
|
|
if (!currentID || currentID != element.ID) {
|
|
|
|
setTableCellCursor(table, row, column)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage("cellClick{session=" + sessionID + ",id=" + tableID +
|
|
|
|
",row=" + row + ",column=" + column + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function tableRowClickEvent(element, event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const elements = element.id.split("-");
|
|
|
|
if (elements.length < 2) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const tableID = elements[0];
|
|
|
|
const row = parseInt(elements[1], 10);
|
|
|
|
const table = document.getElementById(tableID);
|
|
|
|
if (table) {
|
|
|
|
const selection = table.getAttribute("data-selection");
|
2022-04-14 12:05:45 +03:00
|
|
|
if (selection == "row") {
|
2022-01-15 01:20:04 +03:00
|
|
|
const currentID = table.getAttribute("data-current");
|
|
|
|
if (!currentID || currentID != element.ID) {
|
|
|
|
setTableRowCursor(table, row)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage("rowClick{session=" + sessionID + ",id=" + tableID + ",row=" + row + "}");
|
2022-04-15 15:41:44 +03:00
|
|
|
}
|
|
|
|
|
2022-07-08 13:16:42 +03:00
|
|
|
function imageLoaded(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "imageViewLoaded{session=" + sessionID + ",id=" + element.id +
|
2022-07-08 13:16:42 +03:00
|
|
|
",natural-width=" + element.naturalWidth +
|
|
|
|
",natural-height=" + element.naturalHeight +
|
|
|
|
",current-src=\"" + element.currentSrc + "\"}";
|
|
|
|
sendMessage(message);
|
2022-07-31 15:37:26 +03:00
|
|
|
scanElementsSize()
|
2022-07-08 13:16:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function imageError(element, event) {
|
2024-01-15 16:13:46 +03:00
|
|
|
const message = "imageViewError{session=" + sessionID + ",id=" + element.id + "}";
|
2022-07-08 13:16:42 +03:00
|
|
|
sendMessage(message);
|
|
|
|
}
|
2022-10-30 12:35:22 +03:00
|
|
|
|
2024-04-22 13:09:35 +03:00
|
|
|
let timers = new Map();
|
|
|
|
|
|
|
|
function startTimer(ms, timerID) {
|
|
|
|
let data = {
|
|
|
|
id: setInterval(timerFunc, ms, timerID),
|
|
|
|
ms: ms,
|
|
|
|
};
|
|
|
|
timers.set(timerID, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function timerFunc(timerID) {
|
|
|
|
sendMessage("timer{session=" + sessionID + ",timerID=" + timerID + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopTimer(timerID) {
|
|
|
|
let timer = timers.get(timerID);
|
|
|
|
if (timer) {
|
|
|
|
clearInterval(timer.id);
|
|
|
|
timers.delete(timerID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-30 12:35:22 +03:00
|
|
|
function canvasTextMetrics(answerID, elementId, font, text) {
|
2024-01-15 16:13:46 +03:00
|
|
|
let w = 0;
|
|
|
|
let ascent = 0;
|
|
|
|
let descent = 0;
|
|
|
|
let left = 0;
|
|
|
|
let right = 0;
|
2022-10-30 12:35:22 +03:00
|
|
|
|
|
|
|
const canvas = document.getElementById(elementId);
|
|
|
|
if (canvas) {
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
if (ctx) {
|
|
|
|
ctx.save()
|
|
|
|
const dpr = window.devicePixelRatio || 1;
|
|
|
|
ctx.scale(dpr, dpr);
|
|
|
|
ctx.font = font;
|
|
|
|
ctx.textBaseline = 'alphabetic';
|
|
|
|
ctx.textAlign = 'start';
|
2024-01-15 16:13:46 +03:00
|
|
|
const metrics = ctx.measureText(text)
|
2022-10-30 12:35:22 +03:00
|
|
|
w = metrics.width;
|
|
|
|
ascent = metrics.actualBoundingBoxAscent;
|
|
|
|
descent = metrics.actualBoundingBoxDescent;
|
|
|
|
left = metrics.actualBoundingBoxLeft;
|
|
|
|
right = metrics.actualBoundingBoxRight;
|
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage('answer{answerID=' + answerID + ', width=' + w + ', ascent=' + ascent +
|
|
|
|
', descent=' + descent + ', left=' + left + ', right=' + right + '}');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropertyValue(answerID, elementId, name) {
|
|
|
|
const element = document.getElementById(elementId);
|
|
|
|
if (element && element[name]) {
|
|
|
|
sendMessage('answer{answerID=' + answerID + ', value="' + element[name] + '"}')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage('answer{answerID=' + answerID + ', value=""}')
|
2022-11-01 20:13:09 +03:00
|
|
|
}
|
|
|
|
|
2024-03-12 19:32:22 +03:00
|
|
|
function setStyles(styles) {
|
|
|
|
document.querySelector('style').textContent = styles
|
|
|
|
}
|
|
|
|
|
2022-11-01 20:13:09 +03:00
|
|
|
function appendStyles(styles) {
|
|
|
|
document.querySelector('style').textContent += styles
|
2022-11-02 20:08:02 +03:00
|
|
|
}
|
|
|
|
|
2024-03-12 19:32:22 +03:00
|
|
|
function appendAnimationCSS(css) {
|
|
|
|
let styles = document.getElementById('ruiAnimations');
|
|
|
|
if (styles) {
|
|
|
|
styles.textContent += css;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAnimationCSS(css) {
|
|
|
|
let styles = document.getElementById('ruiAnimations');
|
|
|
|
if (styles) {
|
|
|
|
styles.textContent = css;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-02 20:08:02 +03:00
|
|
|
function getCanvasContext(elementId) {
|
|
|
|
const canvas = document.getElementById(elementId)
|
2022-11-02 21:05:55 +03:00
|
|
|
if (canvas) {
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
if (ctx) {
|
|
|
|
const dpr = window.devicePixelRatio || 1;
|
|
|
|
ctx.canvas.width = dpr * canvas.clientWidth;
|
|
|
|
ctx.canvas.height = dpr * canvas.clientHeight;
|
|
|
|
ctx.scale(dpr, dpr);
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2022-11-02 20:08:02 +03:00
|
|
|
}
|
2022-12-18 18:22:58 +03:00
|
|
|
|
|
|
|
function localStorageSet(key, value) {
|
|
|
|
try {
|
|
|
|
localStorage.setItem(key, value)
|
|
|
|
} catch (err) {
|
|
|
|
sendMessage("storageError{session=" + sessionID + ", error=`" + err + "`}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function localStorageClear() {
|
|
|
|
try {
|
|
|
|
localStorage.setItem(key, value)
|
|
|
|
} catch (err) {
|
|
|
|
sendMessage("storageError{session=" + sessionID + ", error=`" + err + "`}")
|
|
|
|
}
|
|
|
|
}
|
2023-04-25 17:20:47 +03:00
|
|
|
|
|
|
|
function showTooltip(element, tooltip) {
|
|
|
|
const layer = document.getElementById("ruiTooltipLayer");
|
|
|
|
if (!layer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.style.left = "0px";
|
|
|
|
layer.style.right = "0px";
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
const tooltipBox = document.getElementById("ruiTooltipText");
|
2023-04-25 17:20:47 +03:00
|
|
|
if (tooltipBox) {
|
|
|
|
tooltipBox.innerHTML = tooltip;
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:13:46 +03:00
|
|
|
let left = element.offsetLeft;
|
|
|
|
let top = element.offsetTop;
|
|
|
|
let width = element.offsetWidth;
|
|
|
|
let height = element.offsetHeight;
|
|
|
|
let parent = element.offsetParent;
|
2023-04-25 17:20:47 +03:00
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
left += parent.offsetLeft;
|
|
|
|
top += parent.offsetTop;
|
|
|
|
width = parent.offsetWidth;
|
|
|
|
height = parent.offsetHeight;
|
|
|
|
parent = parent.offsetParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element.offsetWidth >= tooltipBox.offsetWidth) {
|
|
|
|
layer.style.left = left + "px";
|
|
|
|
layer.style.justifyItems = "start";
|
|
|
|
} else {
|
|
|
|
const rightOff = width - (left + element.offsetWidth);
|
|
|
|
if (left > rightOff) {
|
|
|
|
if (width - left < tooltipBox.offsetWidth) {
|
|
|
|
layer.style.right = rightOff + "px";
|
|
|
|
layer.style.justifyItems = "end";
|
|
|
|
} else {
|
|
|
|
layer.style.left = (left - rightOff) + "px";
|
|
|
|
layer.style.right = "0px";
|
|
|
|
layer.style.justifyItems = "center";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (width - rightOff < tooltipBox.offsetWidth) {
|
|
|
|
layer.style.left = left + "px";
|
|
|
|
layer.style.justifyItems = "start";
|
|
|
|
} else {
|
|
|
|
layer.style.right = (rightOff - left) + "px";
|
|
|
|
layer.style.justifyItems = "center";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const bottomOff = height - (top + element.offsetHeight);
|
2024-01-15 16:13:46 +03:00
|
|
|
let arrow = document.getElementById("ruiTooltipTopArrow");
|
2023-04-25 17:20:47 +03:00
|
|
|
|
|
|
|
if (bottomOff < arrow.offsetHeight + tooltipBox.offsetHeight) {
|
|
|
|
if (arrow) {
|
|
|
|
arrow.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
|
|
|
|
arrow = document.getElementById("ruiTooltipBottomArrow");
|
|
|
|
if (arrow) {
|
|
|
|
arrow.style.visibility = "visible";
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.style.top = "0px";
|
|
|
|
layer.style.bottom = height - top - arrow.offsetHeight / 2 + "px";
|
|
|
|
layer.style.gridTemplateRows = "1fr auto auto"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (arrow) {
|
|
|
|
arrow.style.visibility = "visible";
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.style.top = top + element.offsetHeight - arrow.offsetHeight / 2 + "px";
|
|
|
|
layer.style.bottom = "0px";
|
|
|
|
layer.style.gridTemplateRows = "auto auto 1fr"
|
|
|
|
|
|
|
|
arrow = document.getElementById("ruiTooltipBottomArrow");
|
|
|
|
if (arrow) {
|
|
|
|
arrow.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.style.visibility = "visible";
|
|
|
|
layer.style.opacity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseEnterEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
let tooltip = element.getAttribute("data-tooltip");
|
|
|
|
if (tooltip) {
|
|
|
|
showTooltip(element, tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage("mouse-enter{session=" + sessionID + ",id=" + element.id + mouseEventData(element, event) + "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseLeaveEvent(element, event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
if (element.getAttribute("data-tooltip")) {
|
|
|
|
const layer = document.getElementById("ruiTooltipLayer");
|
|
|
|
if (layer) {
|
|
|
|
layer.style.opacity = 0;
|
|
|
|
layer.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage("mouse-leave{session=" + sessionID + ",id=" + element.id + mouseEventData(element, event) + "}");
|
|
|
|
}
|
|
|
|
|
2023-05-07 20:58:51 +03:00
|
|
|
function hideTooltip() {
|
|
|
|
const layer = document.getElementById("ruiTooltipLayer");
|
|
|
|
if (layer) {
|
|
|
|
layer.style.opacity = 0;
|
|
|
|
layer.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 18:58:57 +03:00
|
|
|
function stopEventPropagation(element, event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2023-04-25 17:20:47 +03:00
|
|
|
function setCssVar(tag, value) {
|
|
|
|
const root = document.querySelector(':root');
|
|
|
|
if (root) {
|
|
|
|
root.style.setProperty(tag, value);
|
|
|
|
}
|
|
|
|
}
|