(function () {
"use strict";
// שנה/י אם צריך: מזהה הפופאפ של אלמנטור (מומלץ להגדיר)
// אם לא יודע/ת, אפשר להשאיר null וזה יעבוד בכל פופאפ
var POPUP_ID = null; // לדוגמה: 1234
// בוחרים את שדות החיפוש של Ajax Search Lite
var INPUT_SELECTOR = ".asl_w input[type='search'], .asl_w input[type='text']";
var lastInput = null;
var lockUntil = 0;
function now() {
return Date.now();
}
function isInsideTargetPopup(el) {
if (!el) return false;
var popup = el.closest(".elementor-popup-modal");
if (!popup) return false;
if (!POPUP_ID) return true;
return popup.querySelector(".elementor[data-elementor-id='" + POPUP_ID + "']") !== null;
}
function safeFocus(input) {
if (!input) return;
try {
input.focus({ preventScroll: true });
} catch (e) {
input.focus();
}
}
// כשמקבלים פוקוס על שדה החיפוש, שומרים אותו כ"אחרון פעיל"
document.addEventListener(
"focusin",
function (e) {
if (!e.target || !e.target.matches) return;
if (!e.target.matches(INPUT_SELECTOR)) return;
if (!isInsideTargetPopup(e.target)) return;
lastInput = e.target;
},
true
);
// בזמן הקלדה: מונעים איבוד פוקוס לכמה מאות מילישניות קדימה
document.addEventListener(
"input",
function (e) {
if (!e.target || !e.target.matches) return;
if (!e.target.matches(INPUT_SELECTOR)) return;
if (!isInsideTargetPopup(e.target)) return;
lastInput = e.target;
lockUntil = now() + 1200; // חלון "נעילה" סביב החיפוש האוטומטי
},
true
);
// אם משהו עושה blur בזמן הנעילה, נחזיר פוקוס
document.addEventListener(
"focusout",
function (e) {
if (!lastInput) return;
if (now() > lockUntil) return;
if (!isInsideTargetPopup(lastInput)) return;
// אם עבר פוקוס לאלמנט אחר, נמתין רגע ונחזיר אותו
setTimeout(function () {
if (now() > lockUntil) return;
if (document.activeElement !== lastInput) safeFocus(lastInput);
}, 50);
},
true
);
// MutationObserver: כשתוצאות מתעדכנות והרינדור משתנה, להחזיר פוקוס אם נפל
var mo = new MutationObserver(function () {
if (!lastInput) return;
if (now() > lockUntil) return;
if (!isInsideTargetPopup(lastInput)) return;
if (document.activeElement !== lastInput) {
setTimeout(function () {
if (now() > lockUntil) return;
if (document.activeElement !== lastInput) safeFocus(lastInput);
}, 60);
}
});
mo.observe(document.documentElement, { childList: true, subtree: true });
// בונוס: בפופאפ, לפעמים touchstart על התוצאות "גונב" פוקוס
document.addEventListener(
"touchstart",
function (e) {
if (!lastInput) return;
if (now() > lockUntil) return;
var t = e.target;
if (!t || !t.closest) return;
if (!t.closest(".asl_w, .asl_results, .asl_r")) return;
if (!isInsideTargetPopup(t)) return;
// לא חוסמים את הפעולה, רק מוודאים שהפוקוס נשאר על השדה
setTimeout(function () {
if (now() > lockUntil) return;
safeFocus(lastInput);
}, 0);
},
{ passive: true, capture: true }
);
})();
באתר נעשה שימוש בעוגיות (Cookies) וכלים דומים לשיפור חוויית הגלישה, התאמת תוכן אישי וביצוע ניתוחים סטטיסטיים.