mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:35:38 +03:00
208 lines
6.7 KiB
JavaScript
208 lines
6.7 KiB
JavaScript
var timerId;
|
||
var mouseOverImg;
|
||
|
||
var unityDivID = "";
|
||
|
||
Start();
|
||
|
||
function showTooltip(evt, text) {
|
||
let tooltip = document.getElementById("tooltip");
|
||
tooltip.innerHTML = text;
|
||
tooltip.style.display = "block";
|
||
|
||
if(evt.pageX > 3*window.innerWidth/4) {
|
||
tooltip.style.left = evt.pageX - tooltip.offsetWidth - 10 + 'px';
|
||
tooltip.style.top = evt.pageY + 10 + 'px';
|
||
tooltip.style.maxWidth = window.innerWidth/2 + 'px';
|
||
} else {
|
||
tooltip.style.left = evt.pageX + 10 + 'px';
|
||
tooltip.style.top = evt.pageY + 10 + 'px';
|
||
tooltip.style.maxWidth = window.innerWidth/2 + 'px';
|
||
if(evt.pageX + window.innerWidth/2 > window.innerWidth-10)
|
||
tooltip.style.maxWidth = window.innerWidth - evt.pageX - 10 + 'px';
|
||
}
|
||
}
|
||
|
||
function hideTooltip() {
|
||
var tooltip = document.getElementById("tooltip");
|
||
tooltip.style.display = "none";
|
||
}
|
||
|
||
function showTooltipImg(evt, filename, title="") {
|
||
let tooltip = document.getElementById("tooltipImg");
|
||
var imgHTML = "";
|
||
if(title != "")
|
||
imgHTML += "<div style='text-align: center;'><h3>" + title + "</h3></div>";
|
||
imgHTML += "<img src='"+filename+"' align='center' style='max-width: 500px;'>"
|
||
tooltip.innerHTML = imgHTML;
|
||
tooltip.style.display = "block";
|
||
tooltip.style.left = evt.pageX + 'px';
|
||
tooltip.style.top = evt.pageY + 'px';
|
||
if (evt.clientX < document.documentElement.clientWidth/2) {
|
||
if(evt.clientY < document.documentElement.clientHeight/2)
|
||
tooltip.style.transform = "translate(10px, 10px)";
|
||
else
|
||
tooltip.style.transform = "translate(10px, -10px) translate(0, -100%)";
|
||
}
|
||
else {
|
||
if(evt.clientY < document.documentElement.clientHeight/2)
|
||
tooltip.style.transform = "translate(-10px, 10px) translate(-100%, 0)";
|
||
else
|
||
tooltip.style.transform = "translate(-10px, -10px) translate(-100%, -100%)";
|
||
}
|
||
clearTimeout(timerId); timerID = null;
|
||
}
|
||
|
||
function hideTooltipImg() {
|
||
timerId = setTimeout(
|
||
() => {
|
||
var tooltip = document.getElementById("tooltipImg");
|
||
tooltip.style.display = "none";
|
||
}, 100
|
||
);
|
||
}
|
||
|
||
function showZoomImg(evt, text) {
|
||
if(evt.currentTarget.offsetWidth < 300 && evt.currentTarget.offsetHeight < 300)
|
||
return;
|
||
mouseOverImg = text;
|
||
let tooltip = document.getElementById("zoom");
|
||
evt = evt || window.event;
|
||
x = evt.clientX; y = evt.clientY;
|
||
img = document.elementFromPoint(x,y);
|
||
|
||
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
||
var rect = img.getBoundingClientRect();
|
||
|
||
tooltip.style.display = "block";
|
||
tooltip.style.left = (rect.right+scrollLeft-32-7)+'px';
|
||
tooltip.style.top = (rect.top+scrollTop+3)+'px';
|
||
}
|
||
|
||
function doZoomImg() {
|
||
viewer.show(mouseOverImg);
|
||
}
|
||
|
||
// ----------------------------------------------------------------------------------------
|
||
|
||
const scList = new Map();
|
||
const divList = new Map();
|
||
var quitCurUnity = null;
|
||
var isClicked = false;
|
||
|
||
function Start() {
|
||
const url = new URL(document.URL);
|
||
//var divID = url.searchParams.get('scenario');
|
||
var savedPage = window.sessionStorage.getItem('curScenarioPage');
|
||
var divID = window.sessionStorage.getItem('scenarioID');
|
||
if(savedPage == location.href && divID != null && divID != "")
|
||
unityDivID = divID;
|
||
//console.log("Start ", unityDivID);
|
||
window.addEventListener('resize', onResize);
|
||
}
|
||
|
||
function scRegister(scName, scTitle, divID, iframeSrc) {
|
||
var curSc = window.sessionStorage.getItem(scName);
|
||
if(curSc != '~done~') {
|
||
scList.set(scName, scTitle);
|
||
window.sessionStorage.setItem(scName, scTitle);
|
||
}
|
||
divList.set(divID, iframeSrc);
|
||
if(divID == unityDivID)
|
||
{
|
||
setDivToIFrame(divID);
|
||
var elem = document.getElementById(divID);
|
||
elem.scrollIntoView();
|
||
}
|
||
else
|
||
setDivToBanner(divID);
|
||
}
|
||
function scFinished(scName, scTitle) {
|
||
window.sessionStorage.setItem(scName, '~done~');
|
||
scList.delete(scName);
|
||
}
|
||
function setDivToBanner(divID) {
|
||
var elem = document.getElementById(divID);
|
||
if(elem != null) {
|
||
if(elem.firstChild != null)
|
||
elem.removeChild(elem.firstChild);
|
||
elem.innerHTML = "<img src='app/dinamika/banner.png' align='center' height='80px' style='border:1px solid #7C2529; box-shadow: 5px 5px 10px rgba(124,37,41,0.5); padding: 10px; cursor:pointer' onclick='onBannerClick(\""+divID+"\")'>";
|
||
}
|
||
}
|
||
|
||
function onBannerClick(divID) {
|
||
if(isClicked) return;
|
||
if(unityDivID == null)
|
||
isClicked = true;
|
||
unityDivID = divID;
|
||
if(quitCurUnity != null)
|
||
quitCurUnity();
|
||
else
|
||
setDivToIFrame(divID);
|
||
}
|
||
function afterUnityQuit() {
|
||
quitCurUnity = null;
|
||
//const url = new URL(document.URL);
|
||
//url.searchParams.delete('scenario');
|
||
//url.searchParams.append('scenario', unityDivID);
|
||
window.sessionStorage.setItem('scenarioID', unityDivID);
|
||
window.sessionStorage.setItem('curScenarioPage', location.href);
|
||
document.location.replace(location.href); //url.href
|
||
}
|
||
function setDivToIFrame(divID) {
|
||
var elem = document.getElementById(divID);
|
||
if(elem != null)
|
||
elem.innerHTML = "<iframe src='"+divList.get(divID)+"' width='938px' height='532px' align='center' frameBorder='0' style='text-indent: 0px;'>Узел <b>iframe</b> не поддерживается браузером</iframe>";
|
||
}
|
||
|
||
// ----------------------------------------------------------------------------------------
|
||
|
||
function onLearnedButton() {
|
||
if(scList.size == 0){
|
||
learnResult();
|
||
let btn = document.getElementById('learnedButton');
|
||
btn.style.display = 'none';
|
||
} else {
|
||
var msgStr;
|
||
msgStr = '<p>Не изучены сценарии интерактивной модели ВС:</p><br/>';
|
||
for (let sc of scList.values())
|
||
msgStr += " - "+sc+"<br/>";
|
||
$("#dialog").html(msgStr);
|
||
$( function() {
|
||
$( "#dialog" ).dialog();
|
||
$('#dialog').dialog("option", "width", "auto"); $('#dialog').dialog("option", "height", "auto");
|
||
} );
|
||
|
||
}
|
||
}
|
||
|
||
function onLoadFunction() {
|
||
var H = document.getElementById('container_text').offsetHeight;
|
||
window.sessionStorage.setItem('contentsHeight', H);
|
||
window.sessionStorage.setItem('scrollY', window.scrollY);
|
||
//console.log('din.js scrollY = ',window.scrollY);
|
||
window.scrollTo({ top: 0, behavior: 'auto' });
|
||
if(typeof window.parent.objectHTMLLoaded !== "undefined")
|
||
window.parent.objectHTMLLoaded();
|
||
|
||
let timerId = setInterval(() => {
|
||
var h = document.getElementById('container_text').offsetHeight;
|
||
if(h != H) {
|
||
H = h;
|
||
window.sessionStorage.setItem('contentsHeight', H);
|
||
window.sessionStorage.setItem('scrollY', window.scrollY);
|
||
//console.log('din.js scrollY = ',window.scrollY);
|
||
|
||
if(typeof window.parent.updateDocHeight !== "undefined")
|
||
window.parent.updateDocHeight();
|
||
}
|
||
}, 50);
|
||
setTimeout(() => { clearInterval(timerId); }, 1000);
|
||
}
|
||
function onResize() {
|
||
var H = document.getElementById('container_text').offsetHeight;
|
||
window.sessionStorage.setItem('contentsHeight', H);
|
||
if(typeof window.parent.updateDocHeight !== "undefined")
|
||
window.parent.updateDocHeight();
|
||
} |