Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
bb7d8af290
469 files changed
+26426
No files matched your search
@@ -0,0 +1,46 @@
|
||||
(function () {
|
||||
function config() {
|
||||
try {
|
||||
return JSON.parse(document.getElementById('vino-config').textContent) || {};
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function arm(guard) {
|
||||
var cfg = config();
|
||||
if (!guard || !cfg.altcha) return;
|
||||
if (!document.querySelector('script[data-altcha]')) {
|
||||
var script = document.createElement('script');
|
||||
script.type = 'module';
|
||||
script.src = cfg.altcha;
|
||||
script.setAttribute('data-altcha', '');
|
||||
document.head.appendChild(script);
|
||||
return;
|
||||
}
|
||||
if (typeof guard.getState === 'function' && ['verified', 'verifying'].indexOf(guard.getState()) < 0) guard.verify();
|
||||
}
|
||||
|
||||
function armed(guard) {
|
||||
return new Promise(function (resolve) {
|
||||
var tick = 0;
|
||||
(function poll() {
|
||||
var state = guard && typeof guard.getState === 'function' ? guard.getState() : '';
|
||||
if (state === 'verified') return resolve(true);
|
||||
var failed = state === 'error' || state === 'expired';
|
||||
var idle = state === 'unverified' && tick >= 30;
|
||||
if ((failed || idle) && tick % 30 === 0) guard.verify();
|
||||
if (++tick > 150) return resolve(false);
|
||||
setTimeout(poll, 100);
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
function reset(guard) {
|
||||
if (!guard) return;
|
||||
if (typeof guard.reset === 'function') guard.reset();
|
||||
if (typeof guard.verify === 'function') guard.verify();
|
||||
}
|
||||
|
||||
window.VinoAltcha = { arm: arm, armed: armed, reset: reset };
|
||||
})();
|
||||
Reference in new issue
Block a user