window.MXOBJ = MXOBJ = window.MXOBJ||{};
MXOBJ.dialog=MXOBJ.dialog||{};
MXOBJ.attachEvent = MXOBJ.attachEvent || function(e,t,f) {if (e&&e.addEventListener)e.addEventListener(t, f, true); else e&&e.attachEvent('on'+t, f);};
if (!MXOBJ.setAttrs) MXOBJ.setAttrs = function(e, attrs) {if (!e||!attrs)return; let arr = attrs.split(";"); arr.forEach(function(s) {let colon = s.indexOf(":");if (colon>0) {let name = s.substring(0, colon).trim(), val = s.substring(colon+1, s.length).trim();e.setAttribute(name, val);}});};
MXOBJ.dialog.img_success = MXOBJ.moduleBaseUrl + '/images/mx/icons/24x24_Free_Application/ok.png';
MXOBJ.dialog.img_quest = MXOBJ.moduleBaseUrl + '/images/mx/icons/Super Mono_Jack Cai/question_balloon.png';
MXOBJ.dialog.img_info = MXOBJ.moduleBaseUrl + '/images/mx/icons/Oxygen_Oxygen_Team/document_properties.png';
MXOBJ.dialog.img_warn = MXOBJ.moduleBaseUrl + '/images/mx/icons/Oxygen-Refit_deviantdark/dialog_warning.png';
MXOBJ.dialog.img_error = MXOBJ.moduleBaseUrl + '/images/mx/icons/Free_Common_widepixel/exclamation5.png';
MXOBJ.dialog.staticOnShows = MXOBJ.dialog.staticOnShows||[];
MXOBJ.dialog.staticOnHides = MXOBJ.dialog.staticOnHides||[];
MXOBJ.dialog.styleSheetPath = 'styles/module_embed/embed_dialog.css';
// ATTENTION: if a modal popup is shown then event handlers not working
MXOBJ.dialog.create = function(showOkButton, showCancelButton, icon, color, onOk, onCancel, params) {
params=params||{};
let d = document.createElement('div');
document.body.appendChild(d);
let id = 'dial_' + Math.random();
d.setAttribute('id', id);
d.setAttribute('class', 'mx_dialogue');
d.params = params;
d.onShows = [];
d.onHides = [];
d.onOkValidators = [];
d.onStyleSheetLoadeds = [];
d.showing = d.animing = d.hiding = d.shown = false;
d.animTop = params['anim_top'] || MXOBJ.dialog.defAnim==='anim_top';
d.animOpacity = params['anim_opacity'] || MXOBJ.dialog.defAnim==='anim_opacity';
d.hasAnim = d.animTop || d.animOpacity;
d.animSec = params['anim_sec'] ? params['anim_sec'] : 0.5;
d.setAttribute('style', 'display:block;position:fixed;z-index:10001;box-shadow:1px 1px 35px #999');
MXOBJ.setAttrs(d, params.attrs);
MXOBJ.dialog.loadStyleSheet(d);
color=color||'lightblue';
MXOBJ.attachEvent(d, 'transitionend', function(evt){MXOBJ.dialog.onTransitionend(d, evt);});
d.eByCl = function(c) {let n=d.getElementsByClassName(c);return n.length===0?null:n[0];};
let innerHtml = '
';
if (!params['hide_head']) {
innerHtml += '' +
'' +
'' +
(icon ? ' ' : '') +
' ' +
' ' +
'' +
'' +
' | ' +
'
';
}
innerHtml += '' +
'' +
'' +
' | ' +
'
';
if (!params['hide_foot']) {
innerHtml += '';
}
innerHtml += '
';
d.innerHTML = innerHtml;
d.style.top = (-window.innerHeight*2) + 'px';
d.headTR = d.eByCl('mx_dial_head_tr');
d.headSpan = d.eByCl('mx_dial_head_span');
d.headPanel = d.eByCl('mx_dial_head_panel');
d.contentTD = d.eByCl('mx_dial_content_td');
d.footTR = d.eByCl('mx_dial_foot_tr');
d.buttonPanel = d.eByCl('mx_dial_button_panel');
d.okButton = d.eByCl('mx_dial_okButton');
d.cancelButton = d.eByCl('mx_dial_cancelButton');
d.closeSign = d.eByCl('mx_dial_close_sign');
d.glass = document.createElement('div');
d.glass.setAttribute('style', 'width:' + window.innerWidth + 'px;height:' + window.innerHeight + 'px');
d.glass.setAttribute('class', 'mx_dial_glass');
d.setTitle = function(html) {d.headSpan.innerHTML = html};
MXOBJ.attachEvent(d.okButton, 'click', function(){
for (let i=0;i window.innerHeight) {top = relTo.getBoundingClientRect().top - d.offsetHeight}
if (left + d.offsetWidth > window.innerWidth) {left = relTo.getBoundingClientRect().right - d.offsetWidth}
if (top<0) {top=0} if (left<0) {left=0}
d.style.top = top + 'px';
d.style.left = left + 'px';
};
MXOBJ.dialog.dialByVar = function(v) {return (typeof v)==='string' ? document.getElementById(v) : v;};
MXOBJ.dialog.noLoadStyleSheet = function() {return MXOBJ.noLoadStyleSheets&&MXOBJ.noLoadStyleSheets.indexOf(MXOBJ.dialog.styleSheetPath)>-1};
MXOBJ.dialog.loadStyleSheet = function(d) {
if (MXOBJ.dialog.styleSheet || MXOBJ.dialog.styleSheetLoaded) {return;}
if (MXOBJ.dialog.noLoadStyleSheet()) {MXOBJ.dialog.onStyleSheetLoaded(d);return;}
MXOBJ.dialog.styleSheet = document.createElement('link');
MXOBJ.dialog.styleSheet.setAttribute('rel', 'stylesheet');
MXOBJ.dialog.styleSheet.setAttribute('type', 'text/css');
MXOBJ.dialog.styleSheet.setAttribute('href', MXOBJ.moduleBaseUrl + MXOBJ.dialog.styleSheetPath + '?' + 'minify=yui,1');
document.head.appendChild(MXOBJ.dialog.styleSheet);
MXOBJ.attachEvent(MXOBJ.dialog.styleSheet, 'load', function() {MXOBJ.dialog.onStyleSheetLoaded(d);});
};
MXOBJ.dialog.onStyleSheetLoaded = function(d) {
MXOBJ.dialog.styleSheetLoaded=true;
d.onStyleSheetLoadeds.forEach(function(f) {f(d);});
};
MXOBJ.dialog.showWithStyleSheetLoaded = function(d, contentHtml, titleHtml, center, relTo, x, y, w, h, fullScr) {
if (!MXOBJ.dialog.styleSheetLoaded && !MXOBJ.dialog.noLoadStyleSheet()) {
d.onStyleSheetLoadeds.push(function(d) {MXOBJ.dialog.showWithStyleSheetLoaded(d, contentHtml, titleHtml, center, relTo, x, y, w, h, fullScr)});
//setTimeout(function() {MXOBJ.dialog.showWithStyleSheetLoaded(d, contentHtml, titleHtml, center, relTo, x, y, w, h, fullScr)}, 300);
return;
}
if (w>0) {d.style.width = w+'px';} else if (w===0) {d.style.width = (d.offsetWidth+2)+'px';} else {d.style.width = 'auto';d.style.marginRight = '5px';}
if (h>0) {d.style.height = h+'px';} else if (h===0) {d.style.height = (d.offsetHeight+20)+'px';} else {d.style.height = 'auto'}
if (center) {MXOBJ.dialog.center(d);}
else if (relTo) {MXOBJ.dialog.showRelTo(d, relTo);}
else if (x&&y&&x>-1&&y>-1) {
if (d.params['set_right']) {d.style.right=x+'px'} else {d.style.left=x+'px'}
if (d.params['set_bottom']) {d.style.bottom=y+'px'} else {d.style.top=y+'px'}
}
else if (fullScr) {d.style.width=(window.innerWidth-50)+'px'; d.style.height=(window.innerHeight-20)+'px'; MXOBJ.dialog.center(d);}
d.style.opacity = 1;
d.showing = true;
d.animing = true;
};
MXOBJ.dialog.attachOkCancelKeyEvents = function(d, e) {
MXOBJ.attachEvent(e, 'keyup', function(evt) {evt=evt||window.event;if (evt.keyCode===13) {d.okButton.click()} if (evt.keyCode===27) {d.cancelButton.click()}});
};
// default type: 'alert'
MXOBJ.dialog.popup = function(type, msg, titleHtml, initValue, w, h, color, scroll, callback, params) {
let d, fullScr = !w&&!h;
if (scroll) {
let sc = document.createElement('div');
sc.style.width = (window.innerWidth/1.1) + 'px';
sc.style.height = (window.innerHeight/1.5) + 'px';
sc.style.overflow = 'auto';
MXOBJ.dialog.setInnerOrAppend(sc, msg);
msg=sc;
}
if (type==='success') {
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Sikeres', true, false, 'success', color, true, null, null, null, w, h, fullScr, function(){d.hide();if (callback) {callback()}}, null, params);
} else if (type==='quest') {
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Kérdés', true, true, 'quest', color, true, null, null, null, w, h, fullScr, function(){d.hide();if (callback) {callback('1')}}, function(){callback(null)}, params);
} else if (type==='info') {
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Info', true, false, 'info', color, true, null, null, null, w, h, fullScr, function(){d.hide();if (callback) {callback()}}, null, params);
} else if (!type||type==='alert') {
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Figyelmeztetés', true, false, 'warn', color, true, null, null, null, w, h, fullScr, function(){d.hide();if (callback) {callback()}}, null, params);
} else if (type==='confirm') {
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Jóváhagyás', true, true, 'warn', color, true, null, null, null, w, h, fullScr, function(){d.hide();callback&&callback(true)}, function(){callback&&callback(false)}, params);
d.headTR.setAttribute('tabindex', '0');
d.headTR.focus();
MXOBJ.dialog.attachOkCancelKeyEvents(d, d.headTR);
} else if (type==='prompt') {
msg=(msg||'') + '
';
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Bevitel', true, true, 'quest', color, true, null, null, null, w, h, fullScr, function(){d.hide();if (callback) {callback(d.eByCl('mx_dial_textinput').value)}}, function(){callback(null)}, params);
let inpBox = d.eByCl('mx_dial_textinput');
inpBox.value = initValue;
inpBox.focus();
inpBox.select();
MXOBJ.dialog.attachOkCancelKeyEvents(d, inpBox);
} else if (type==='error') {
d = MXOBJ.dialog.createAndShow(msg, titleHtml||'Hiba', true, false, 'error', color, true, null, null, null, w, h, fullScr, function(){d.hide();if (callback) {callback()}}, null, params);
}
return d;
};