82 lines
2 KiB
JavaScript
82 lines
2 KiB
JavaScript
/**
|
|
* دیالوگ راهنمای ثبت کالا در شبکه تأمین
|
|
*
|
|
* @package Hesabix2
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var dialog = document.getElementById('hx-st-supplier-dialog');
|
|
if (!dialog) {
|
|
return;
|
|
}
|
|
|
|
var OPEN_CLASS = 'is-open';
|
|
var BODY_CLASS = 'hx-st-supplier-dialog-open';
|
|
var lastTrigger = null;
|
|
|
|
function openDialog(trigger) {
|
|
lastTrigger = trigger || null;
|
|
dialog.setAttribute('aria-hidden', 'false');
|
|
dialog.classList.add(OPEN_CLASS);
|
|
document.documentElement.classList.add(BODY_CLASS);
|
|
document.body.classList.add(BODY_CLASS);
|
|
var panel = dialog.querySelector('.hx-st-supplier-dialog__panel');
|
|
if (panel) {
|
|
panel.focus();
|
|
}
|
|
}
|
|
|
|
function closeDialog() {
|
|
dialog.setAttribute('aria-hidden', 'true');
|
|
dialog.classList.remove(OPEN_CLASS);
|
|
document.documentElement.classList.remove(BODY_CLASS);
|
|
document.body.classList.remove(BODY_CLASS);
|
|
if (lastTrigger && typeof lastTrigger.focus === 'function') {
|
|
lastTrigger.focus();
|
|
}
|
|
lastTrigger = null;
|
|
}
|
|
|
|
function bindTriggers() {
|
|
document.addEventListener('click', function (e) {
|
|
var trigger = e.target.closest('[data-st-supplier-dialog-open]');
|
|
if (!trigger) {
|
|
return;
|
|
}
|
|
e.preventDefault();
|
|
openDialog(trigger);
|
|
});
|
|
|
|
document.addEventListener('keydown', function (e) {
|
|
var trigger = e.target.closest('[data-st-supplier-dialog-open]');
|
|
if (!trigger || (e.key !== 'Enter' && e.key !== ' ')) {
|
|
return;
|
|
}
|
|
e.preventDefault();
|
|
openDialog(trigger);
|
|
});
|
|
}
|
|
|
|
function bindDialog() {
|
|
dialog.querySelectorAll('[data-hx-st-supplier-close]').forEach(function (el) {
|
|
el.addEventListener('click', closeDialog);
|
|
});
|
|
|
|
document.addEventListener('keydown', function (e) {
|
|
if (e.key === 'Escape' && dialog.classList.contains(OPEN_CLASS)) {
|
|
closeDialog();
|
|
}
|
|
});
|
|
|
|
var arcBtn = dialog.querySelector('[data-hesabix-entry]');
|
|
if (arcBtn) {
|
|
arcBtn.addEventListener('click', function () {
|
|
closeDialog();
|
|
});
|
|
}
|
|
}
|
|
|
|
bindTriggers();
|
|
bindDialog();
|
|
})();
|