94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
/**
|
|
* AKSRT Widget Set
|
|
*
|
|
* Handles widget-local interactions and floating QR widgets.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initWidgetTabs() {
|
|
document.querySelectorAll('.widget-tab-posts').forEach(function (widget) {
|
|
if (widget.dataset.aksrtWidgetTabsBound === '1') return;
|
|
widget.dataset.aksrtWidgetTabsBound = '1';
|
|
|
|
var tabs = widget.querySelectorAll('.widget-tab-posts__tab');
|
|
var panels = widget.querySelectorAll('.widget-tab-posts__panel');
|
|
if (!tabs.length || !panels.length) return;
|
|
|
|
tabs.forEach(function (tab) {
|
|
tab.addEventListener('click', function () {
|
|
var target = tab.getAttribute('data-tab');
|
|
|
|
tabs.forEach(function (item) {
|
|
var active = item === tab;
|
|
item.classList.toggle('active', active);
|
|
item.setAttribute('aria-selected', active ? 'true' : 'false');
|
|
});
|
|
|
|
panels.forEach(function (panel) {
|
|
var active = panel.getAttribute('data-tab-panel') === target;
|
|
panel.classList.toggle('active', active);
|
|
if (active) {
|
|
panel.removeAttribute('hidden');
|
|
} else {
|
|
panel.setAttribute('hidden', '');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function initFloatingQRCodes() {
|
|
var wrap = document.querySelector('.float-right');
|
|
if (!wrap) return;
|
|
|
|
wrap.querySelectorAll('.service-wechat .hover-show-con p, .service-qq .hover-show-con p').forEach(function (node) {
|
|
node.remove();
|
|
});
|
|
|
|
if (typeof window.kjua !== 'function') return;
|
|
|
|
wrap.querySelectorAll('.float-btn-qrcode').forEach(function (node) {
|
|
if (node.dataset.qrReady === '1') return;
|
|
|
|
var qrText = node.getAttribute('data-qr-text') || window.location.href;
|
|
var qrSize = parseInt(node.getAttribute('data-qr-size') || '120', 10);
|
|
if (!qrText || !qrSize) return;
|
|
|
|
try {
|
|
node.innerHTML = '';
|
|
node.appendChild(window.kjua({
|
|
render: 'svg',
|
|
text: qrText,
|
|
size: qrSize,
|
|
ecLevel: 'H',
|
|
fill: '#15171A',
|
|
back: '#FFFFFF',
|
|
quiet: 0,
|
|
crisp: true
|
|
}));
|
|
node.style.width = qrSize + 'px';
|
|
node.style.height = qrSize + 'px';
|
|
node.dataset.qrReady = '1';
|
|
} catch (error) {
|
|
node.dataset.qrReady = '0';
|
|
}
|
|
});
|
|
}
|
|
|
|
function init() {
|
|
initWidgetTabs();
|
|
initFloatingQRCodes();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|