mock: three search tabs - stop code, place name, near me

- busStop.html: added the third tab (data-mode=near) and its own panel with
  the location button, hint and result area; removed the near button from the
  toolbar and deleted the old on-screen numpad markup
- busStop.search.js: MODE_NEAR in setMode, disables the other panels, hides
  the stop list while ranked results are shown, skips filtering in that mode,
  and removed the dead initNumpad code
- security gate: the tab is revealed only when isSecureContext and
  navigator.geolocation exist; otherwise it stays hidden and the mode is
  refused
- map.js: re-enable the button after a successful lookup
- i18n: stops.modeNear / nearCta / nearHint
- bump SW version to 2026.09.27.98

Verified on localhost:8090 - three tabs, near mode shows a map with 8 ranked
stops, button re-enables and works again, switching back restores the list;
with isSecureContext forced false the tab is hidden and unselectable.
This commit is contained in:
Bkk1234 committed 2026-10-24 00:11:56 +07:00
1 parent 74d605f1c4
commit 750b4a2ea8
25 files changed
+426 -180

No files matched your search

+28 -48
View File
@@ -13,6 +13,7 @@
var MODE_CODE = 'code';
var MODE_PLACE = 'place';
var MODE_NEAR = 'near'; /* หมวดที่ 3: ป้ายใกล้ฉัน (ต้องมี HTTPS) */
var state = {
mode: MODE_CODE,
@@ -90,6 +91,10 @@
}
function currentFilter() {
// โหมดใกล้ฉัน: ไม่กรองรายการ (ผลลัพธ์แสดงในโซนของตัวเอง)
if (state.mode === MODE_NEAR) {
return { fn: function () { return true; }, value: '' };
}
// โหมดรหัส: ถ้ายังไม่กรอกช่องไหนเลย → ไม่กรอง (แสดงทั้งหมด)
if (state.mode === MODE_CODE && !state.codeTouched) {
return { fn: function () { return true; }, value: '' };
@@ -206,23 +211,33 @@
/* ---------- สลับโหมด (หัวใจของการกันชน) ---------- */
function setMode(mode) {
if (mode !== MODE_CODE && mode !== MODE_PLACE) return;
if (mode !== MODE_CODE && mode !== MODE_PLACE && mode !== MODE_NEAR) return;
/* โหมดใกล้ฉันใช้ได้เฉพาะ secure context */
if (mode === MODE_NEAR && !(window.isSecureContext && navigator.geolocation)) return;
state.mode = mode;
var codeWrap = document.getElementById('stops-code-wrap');
var placeWrap = document.getElementById('stops-place-wrap');
var nearWrap = document.getElementById('stops-near-wrap');
var placeInput = document.getElementById('stops-place-input');
var suggest = document.getElementById('stops-suggest');
var pad = document.getElementById('stops-numpad');
var cells = codeCells();
var isCode = mode === MODE_CODE;
var isPlace = mode === MODE_PLACE;
var isNear = mode === MODE_NEAR;
// แสดง/ซ่อนช่องกรอก
// แสดง/ซ่อนช่องกรอก — เลือกได้ทีละโหมดเท่านั้น
if (codeWrap) codeWrap.hidden = !isCode;
if (placeWrap) placeWrap.hidden = isCode;
if (pad) pad.hidden = !isCode;
if (suggest) suggest.hidden = isCode;
if (placeWrap) placeWrap.hidden = !isPlace;
if (nearWrap) nearWrap.hidden = !isNear;
if (suggest) suggest.hidden = !isPlace;
// โหมดใกล้ฉัน: ซ่อนรายการป้ายทั้งหมด (ผลลัพธ์หลักคือการ์ดเรียงตามระยะ)
var stopList = document.getElementById('stops-list');
if (stopList) stopList.hidden = isNear;
var showAllBtn = document.getElementById('stops-show-all');
if (showAllBtn && isNear) showAllBtn.hidden = true;
// ปิดการใช้งานช่องของโหมดที่ไม่ได้เลือก + ล้างค่า → กันการค้น 2 ทางพร้อมกัน
Array.prototype.forEach.call(cells, function (c) {
@@ -236,8 +251,8 @@
updateCodeDisplay();
}
if (placeInput) {
placeInput.disabled = isCode;
if (isCode) { placeInput.value = ''; state.placeQuery = ''; }
placeInput.disabled = !isPlace;
if (!isPlace) { placeInput.value = ''; state.placeQuery = ''; }
}
// ไฮไลต์ปุ่ม toggle
@@ -249,7 +264,11 @@
// โฟกัสช่องที่เพิ่งเปิด
if (isCode) focusCell(0);
if (!isCode && placeInput) placeInput.focus();
if (isPlace && placeInput) placeInput.focus();
if (isNear) {
var nearBtn = document.getElementById('near-me-btn');
if (nearBtn) nearBtn.focus();
}
apply();
}
@@ -352,44 +371,6 @@
}
/* ---------- numpad (ใช้กับ 5 ช่อง) ---------- */
function initNumpad() {
var pad = document.getElementById('stops-numpad');
if (!pad) return;
pad.addEventListener('click', function (e) {
var key = e.target.closest('[data-key]');
if (!key) return;
e.preventDefault();
var k = key.getAttribute('data-key');
var cells = codeCells();
if (!cells.length) return;
/* ตำแหน่งเป้าหมาย = ช่องแรกที่ว่าง (ช่องท้ายสุดถ้าเต็มหมด) */
var idx = CODE_CELLS - 1;
for (var i = 0; i < CODE_CELLS; i++) {
if (!cells[i].value) { idx = i; break; }
}
if (k === 'back') {
// ถอยจากท้าย: ล้างช่องขวาสุดที่มีค่า แล้วเลื่อนเป้าไปช่องนั้น
var last = -1;
for (var j = CODE_CELLS - 1; j >= 0; j--) {
if (cells[j].value) { last = j; break; }
}
idx = last === -1 ? 0 : last;
cells[idx].value = '';
} else {
cells[idx].value = k;
}
syncCodeFromCells();
updateCodeDisplay();
apply();
// โฟกัสช่องถัดไป (ไม่ select — กันกด numpad แล้วทับค่าเดิม)
var next = Math.min(idx + (k === 'back' ? 0 : 1), CODE_CELLS - 1);
if (cells[next]) cells[next].focus();
});
}
/* ---------- init ---------- */
function init(stops) {
@@ -481,7 +462,6 @@
suggest.hidden = true;
});
initNumpad();
setMode(MODE_CODE); // เริ่มที่โหมดรหัส
}