46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
/**
|
|
* انجمن AnsPress — فیلتر chip و همگامسازی select
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
function initOrderSync() {
|
|
var form = document.querySelector('.hesabix2-ap-filters-form');
|
|
var select = document.getElementById('ap-order');
|
|
if (!form || !select) {
|
|
return;
|
|
}
|
|
document.querySelectorAll('.hesabix2-ap-chip').forEach(function (chip) {
|
|
chip.addEventListener('click', function () {
|
|
var url = new URL(chip.href, window.location.origin);
|
|
var order = url.searchParams.get('ap_order_by');
|
|
if (order) {
|
|
select.value = order;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function initAnswerPlaceholderKeyboard() {
|
|
var placeholders = document.querySelectorAll('.hesabix2-ap-answer-form .ap-dummy-placeholder[role="button"]');
|
|
placeholders.forEach(function (el) {
|
|
el.addEventListener('keydown', function (e) {
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
e.preventDefault();
|
|
el.click();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function init() {
|
|
initOrderSync();
|
|
initAnswerPlaceholderKeyboard();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|