1// Google Mapså´ã®ã³ã¼ã«ããã¯(callback=initMap)㯠async 屿§ã®é¢ä¿ã§ 2// DOMContentLoaded ããå ã«çºç«ãããã¨ãããããã 3// ã¹ã¯ãªããèªã¿è¾¼ã¿ç´å¾ããå¼ã³åºããç¶æ ã«ãã¦ãã 4window.initMap = function() { 5 window.__googleMapsReady = true; 6 if (typeof window.__runInitMap === 'function') { 7 window.__runInitMap(); 8 } 9}; 10 11document.addEventListener('DOMContentLoaded', function() { 12 13 const apiStoresUrl = '/wp-json/bsportal/v1/stores'; 14 const apiCitiesUrl = '/wp-json/bsportal/v1/cities'; 15 16 const prefSelect = document.getElementById('pref-select'); 17 const citySelect = document.getElementById('city-select'); 18 const moreBtn = document.querySelector('.js-store-more-btn'); 19 const mapBox = document.querySelector('.p-store-purchase__result_map'); 20 21 const jsPref = document.querySelector('.js-pref'); 22 const jsCity = document.querySelector('.js-city'); 23 const jsNearby = document.querySelector('.js-nearby'); 24 25 let currentPage = 1; 26 let currentLat = null; 27 let currentLng = null; 28 let currentSearchType = 'area'; 29 30 let cachedTemplateHTML = ''; 31 let cachedMapTemplateHTML = ''; 32 33 const templateElement = document.getElementById('template_list'); 34 const mapTemplateElement = document.getElementById('template_map'); 35 36 const isTaxonomyPage = window.location.pathname.includes('/store-area/'); 37 38 if (templateElement) { 39 cachedTemplateHTML = templateElement.innerHTML; 40 templateElement.remove(); 41 } 42 if (mapTemplateElement) { 43 cachedMapTemplateHTML = mapTemplateElement.innerHTML; 44 mapTemplateElement.remove(); 45 } 46 47 // é½éåºç鏿æã®å¦ç 48 if (prefSelect && !isTaxonomyPage) { 49 prefSelect.addEventListener('change', function() { 50 const pref = this.value; 51 52 // å¸åºçºæã»ã¬ã¯ããåæå 53 if (citySelect) { 54 citySelect.innerHTML = '<option value="">å¸åºçºæã鏿</option>'; 55 citySelect.disabled = true; 56 } 57 58 if (!pref) { 59 // é½éåºçã空ã®å ´åã¯å ¨ä»¶è¡¨ç¤ºçã§æ´æ° 60 currentPage = 1; 61 currentLat = null; 62 currentLng = null; 63 currentSearchType = 'area'; 64 fetchStoreList({ 65 searchType: currentSearchType, 66 pref: '', 67 city: '', 68 page: currentPage, 69 isAppend: false 70 }); 71 return; 72 } 73 74 // å¸åºçºæã®åå¾ãªã¯ã¨ã¹ã (REST API) 75 const formData = new FormData(); 76 formData.append('pref', pref); 77 78 fetch(apiCitiesUrl, { 79 method: 'POST', 80 body: formData 81 }) 82 .then(response => response.json()) 83 .then(data => { 84 if (data.success && data.data.length > 0 && citySelect) { 85 data.data.forEach(city => { 86 const option = document.createElement('option'); 87 option.value = city; 88 option.textContent = city; 89 citySelect.appendChild(option); 90 }); 91 citySelect.disabled = false; 92 } 93 }) 94 .catch(error => console.error('Error fetching cities:', error)); 95 96 // é½éåºçã夿´ãããã¿ã¤ãã³ã°ã§åºèä¸è¦§ãæ´æ° 97 currentPage = 1; 98 currentLat = null; 99 currentLng = null; 100 currentSearchType = 'area'; 101 fetchStoreList({ 102 searchType: currentSearchType, 103 pref: pref, 104 city: '', 105 page: currentPage, 106 isAppend: false 107 }); 108 }); 109 } 110 111 // å¸åºçºæé¸ææã®å¦ç 112 if (citySelect) { 113 citySelect.addEventListener('change', function() { 114 const pref = prefSelect ? prefSelect.value : ''; 115 const city = this.value; 116 currentPage = 1; 117 currentLat = null; 118 currentLng = null; 119 currentSearchType = 'area'; 120 fetchStoreList({ 121 searchType: currentSearchType, 122 pref: pref, 123 city: city, 124 page: currentPage, 125 isAppend: false 126 }); 127 }); 128 } 129 130 // æ°ãããã¶ã¤ã³ç¨ã®åºèãªã¹ããREST APIã§åå¾ãããã¼ã¹é¢æ° 131 function fetchStoreList(params) { 132 const { 133 searchType = 'area', 134 pref = '', 135 city = '', 136 page = 1, 137 isAppend = false, 138 lat = null, 139 lng = null, 140 bounds = null, // { swLat, swLng, neLat, neLng }
140 å°å³ã®è¡¨ç¤ºç¯å²ï¼ç¾å¨å°æ¤ç´¢ã§ã®ãã©ãã°ï¼ãºã¼ã åæ¤ç´¢ç¨ï¼ 141 mapOnly = false // true ã®å ´åãå°å³ã¨ãã®ä¸ã®ã«ã¼ãã ããæ´æ°ããä¸è¦§ã¿ãã»ä»¶æ°ã»æ¤ç´¢æ¡ä»¶è¡¨ç¤ºã¯å¤æ´ããªã 142 } = params; 143 144 if (mapBox) { 145 const hasSearched = searchType === 'nearby' || !!pref || !!city; 146 mapBox.classList.toggle('is-searched', hasSearched); 147 } 148 149 if (!isAppend && !mapOnly) { 150 if (jsPref && jsCity && jsNearby) { 151 if (searchType === 'nearby') { 152 jsPref.style.display = 'none'; 153 jsCity.style.display = 'none'; 154 jsNearby.style.display = ''; 155 } else { 156 jsNearby.style.display = 'none'; 157 if (pref || city) { 158 const formDataSlug = new FormData(); 159 if (pref) formDataSlug.append('pref', pref); 160 if (city) formDataSlug.append('city', city); 161 fetch('/wp-json/bsportal/v1/area-slug', { 162 method: 'POST', 163 body: formDataSlug 164 }) 165 .then(res => res.json()) 166 .then(slugData => { 167 if (slugData.success) { 168 const prefSlug = slugData.data.pref_slug; 169 const citySlug = slugData.data.city_slug; 170 if (pref) { 171 jsPref.innerHTML = prefSlug ? `<a href="/store-area/${prefSlug}/">${pref}</a>` : pref; 172 jsPref.style.display = ''; 173 } else { 174 jsPref.textContent = 'ãªã'; 175 jsPref.style.display = ''; 176 } 177 if (city) { 178 jsCity.innerHTML = `/ ${city}`; 179 jsCity.style.display = ''; 180 } else { 181 jsCity.style.display = 'none'; 182 } 183 } 184 }) 185 .catch(error => console.error('Error fetching area slug:', error)); 186 } else { 187 jsPref.textContent = 'ãªã'; 188 jsPref.style.display = ''; 189 jsCity.style.display = 'none'; 190 } 191 } 192 } 193 } 194 195 const formData = new FormData(); 196 formData.append('search_type', searchType); 197 formData.append('page', page); 198 199 if (searchType === 'area') { 200 formData.append('pref', pref); 201 formData.append('city', city); 202 } else if (searchType === 'nearby' && lat !== null && lng !== null) { 203 formData.append('lat', lat); 204 formData.append('lng', lng); 205 } 206 207 if (bounds) { 208 formData.append('sw_lat', bounds.swLat); 209 formData.append('sw_lng', bounds.swLng); 210 formData.append('ne_lat', bounds.neLat); 211 formData.append('ne_lng', bounds.neLng); 212 } 213 214 fetch(apiStoresUrl, { 215 method: 'POST', 216 body: formData 217 }) 218 .then(response => response.json()) 219 .then(data => { 220 if (data.success) { 221 222 // åºèæ°(.js-store-count) 223 if (!mapOnly) { 224 const countElements = document.querySelectorAll('.js-store-count'); 225 countElements.forEach(el => { 226 el.textContent = data.data.total_count || 0; 227 }); 228 } 229 230 const target = document.getElementById('js_store_result'); 231 const mapTarget = document.getElementById('js_store_map'); 232 const MAP_LIST_LIMIT = 10; // ãããç¨ãªã¹ãã®æå¤§è¡¨ç¤ºä»¶æ° 233 let currentMapListCount = 0; 234 235 // ååã®æ¤ç´¢çµæãã¯ãªã¢ 236 if (target && !isAppend && !mapOnly) { 237 target.innerHTML = ''; 238 } 239 if (mapTarget && !isAppend) { 240 if (window.jQuery && $(mapTarget).hasClass('slick-initialized')) { 241 $(mapTarget).slick('unslick'); 242 } 243 mapTarget.innerHTML = ''; 244 } else if (mapTarget && isAppend) { 245 if (window.jQuery && $(mapTarget).hasClass('slick-initialized')) { 246 currentMapListCount = $(mapTarget).slick('getSlick').slideCount; 247 } else { 248 currentMapListCount = mapTarget.children.length; 249 } 250 } 251 252 if (cachedTemplateHTML && target && data.data && data.data.list.length > 0) {
253 const templateHTML = cachedTemplateHTML; 254 const mapTemplateHTML = cachedMapTemplateHTML; 255 let combinedHTML = ''; 256 let combinedMapHTML = ''; 257 258 259 // å¤ã空ã ã£ãå ´åã«ã¿ã°ãã¨åé¤ãããã¼ã®é å 260 const removeIfEmptyKeys = ['store_km', 'store_post_tel']; 261 262 const processTemplate = (html, store) => { 263 let itemHTML = html; 264 265 // å¤ãç¡ããã°ç®å°ãã¤ãã¦ããï¼å¾ã®DOMæä½ã§ã¿ã°ãã¨åé¤ããããï¼ 266 removeIfEmptyKeys.forEach(key => { 267 if (!store[key]) { 268 const regex = new RegExp(`{{${key}}}`, 'g'); 269 itemHTML = itemHTML.replace(regex, `{{REMOVE_${key.toUpperCase()}}}`); 270 } 271 }); 272 273 // ãã³ãã¬ã¼ãå ã® {{key}} ã store ãªãã¸ã§ã¯ãã®å¤ã§ç½®æ 274 for (const key in store) { 275 const regex = new RegExp(`{{${key}}}`, 'g'); 276 let value = store[key]; 277 278 // {{store_rate_***}} ã空ãªããã¤ãã³ã« 279 if (key.startsWith('store_rate_') && !value) { 280 value = '-'; 281 } 282 283 itemHTML = itemHTML.replace(regex, value || ''); 284 } 285 286 // store_service ã®é åå ã®ãã©ã°ã§trueãªã {{store_service_***}} ãis-activeã«ç½®æ 287 const serviceMatches = itemHTML.match(/{{store_service_([^}]+)}}/g); 288 if (serviceMatches) { 289 const uniqueMatches = [...new Set(serviceMatches)]; // éè¤ãæé¤ 290 uniqueMatches.forEach(placeholder => { 291 const serviceName = placeholder.replace('{{store_service_', '').replace('}}', ''); 292 if (Array.isArray(store.store_service) && store.store_service.includes(serviceName)) { 293 itemHTML = itemHTML.split(placeholder).join('is-active'); 294 } else { 295 itemHTML = itemHTML.split(placeholder).join(''); 296 } 297 }); 298 } 299 300 // æååãDOMã«å¤æãã¦æä½ãããããã 301 const tempDiv = document.createElement('div'); 302 tempDiv.innerHTML = itemHTML; 303 304 305 const detailWrap = tempDiv.querySelector('.p-store-purchase__result_item_rating_detail'); 306 307 const serviceItem = 308 detailWrap?.children[0]; 309 310 const atmosphereItem = 311 detailWrap?.children[1]; 312 313 const priceItem = 314 detailWrap?.children[2]; 315 316 const hasService = store.store_rate_service; 317 const hasAtmosphere = store.store_rate_atmosphere; 318 const hasPrice = store.store_rate_purchase_price; 319 320 if (!hasService && serviceItem) { 321 serviceItem.style.display = 'none'; 322 } 323 324 if (!hasAtmosphere && atmosphereItem) { 325 atmosphereItem.style.display = 'none'; 326 } 327 328 if (!hasPrice && priceItem) { 329 priceItem.style.display = 'none'; 330 } 331 332 if (!hasService && !hasAtmosphere && !hasPrice && detailWrap) { 333 detailWrap.style.display = 'none'; 334 } 335 336 const ratingWraps = tempDiv.querySelectorAll( 337 '.p-store-purchase__result_item_rating-wrap, .p-store-purchase__result_map_list_item_rating' 338 ); 339 340 if (!store.store_place_id) { 341 ratingWraps.forEach(el => { 342 el.style.display = 'none'; 343 }); 344 } 345 346 // store_place_ratingè©ä¾¡ããæã®ç»åã使 347 const rating = parseFloat(store.store_place_rating) || 0; 348 const fullStar = tempDiv.querySelector('.js-star-icon-full'); 349 const halfStar = tempDiv.querySelector('.js-star-icon-half'); 350 const noneStar = tempDiv.querySelector('.js-star-icon-none'); 351 352 // 3種é¡ã®æã¢ã¤ã³ã³ããã³ãã¬ã¼ãå ã«åå¨ããå ´åã®ã¿å¦çãå®è¡ 353 if (fullStar && halfStar && noneStar) { 354 const starContainer = fullStar.parentElement; 355 starContainer.innerHTML = ''; // ãã³ãã¬ã¼ãã®å ã¢ã¤ã³ã³ã䏿¦ã¯ãªã¢ 356 357 for (let i = 1; i <= 5; i++) { 358 if (rating >= i) { 359 starContainer.appendChild(fullStar.cloneNode(true)); 360 } else if (rating >= i - 0.5) { 361 starContainer.appendChild(halfStar.cloneNode(true)); 362 } else { 363 starContainer.appendChild(noneStar.cloneNode(true)); 364 } 365 } 366 tempDiv.innerHTML = tempDiv.innerHTML.replace('{{star_icons}}', starContainer.innerHTML); 367 } 368 369 // ãã¤ã»ã«ç´å¶åº 370 let fcEl = null; 371 const elements = tempDiv.querySelectorAll('*');
372 elements.forEach(el => { 373 if (el.textContent.includes('{{store_post_fc_text}}')) { 374 const hasChildWithText = Array.from(el.children).some(child => child.textContent.includes('{{store_post_fc_text}}')); 375 if (!hasChildWithText) { 376 fcEl = el; 377 } 378 } 379 }); 380 381 if (fcEl) { 382 if (!store.store_post_fc) { 383 fcEl.innerHTML = fcEl.innerHTML.replace('{{store_post_fc_text}}', 'ãã¤ã»ã«ç´å¶åº'); 384 } else { 385 fcEl.remove(); 386 const webBtn = tempDiv.querySelector('.p-store-purchase__result_item_link_btn--web'); 387 if (webBtn) { 388 webBtn.remove(); 389 } 390 391 const linkWrap = tempDiv.querySelector( 392 '.p-store-purchase__result_item_link' 393 ); 394 395 if (linkWrap) { 396 linkWrap.classList.add('is-single'); 397 } 398 } 399 } 400 401 // æ¬æ¥äºç´ç©ºãæéããåé¤ 402 let reserveEl = null; 403 elements.forEach(el => { 404 if (el.textContent.includes('æ¬æ¥äºç´ç©ºãæéãã')) { 405 const hasChildWithText = Array.from(el.children).some(child => child.textContent.includes('æ¬æ¥äºç´ç©ºãæéãã')); 406 if (!hasChildWithText) { 407 reserveEl = el; 408 } 409 } 410 }); 411 if (reserveEl) { 412 reserveEl.remove(); 413 } 414 415 // å¤ãç¡ããã°ã¿ã°ãã¨åé¤ 416 removeIfEmptyKeys.forEach(key => { 417 const marker = `{{REMOVE_${key.toUpperCase()}}}`; 418 const original = `{{${key}}}`; 419 let targetEl = null; 420 const freeTextEl = tempDiv.querySelector('.p-store-purchase__result_item_link_btn_sm'); 421 if (freeTextEl && !store.store_post_tel_free_text) { 422 freeTextEl.remove(); 423 } 424 const currentElements = tempDiv.querySelectorAll('*'); 425 currentElements.forEach(el => { 426 if (el.textContent.includes(marker) || el.textContent.includes(original)) { 427 const hasChildWithText = Array.from(el.children).some(child => 428 child.textContent.includes(marker) || child.textContent.includes(original) 429 ); 430 if (!hasChildWithText) { 431 targetEl = el; 432 } 433 } 434 }); 435 if (targetEl) { 436 targetEl.remove(); 437 } 438 }); 439 440 return tempDiv.innerHTML; 441 }; 442 443 const mapStoreList = []; // ãããã®ãã¼ã«ã¼ç¨ãªã¹ã 444 const isUnlimitedMapList = (searchType === 'area' && pref !== ''); 445 // ç¾å¨å°æ¤ç´¢ã§å°å³ã®è¡¨ç¤ºç¯å²(bounds)ãæå®ããåæ¤ç´¢ãã©ãã 446 const isBoundsSearch = (searchType === 'nearby' && !!bounds); 447 // ã¨ãªã¢(é½éåºç)æ¤ç´¢ãã¾ãã¯è¡¨ç¤ºç¯å²ã§ã®åæ¤ç´¢æã¯ãAPIãè¿ãçµãè¾¼ã¿æ¡ä»¶ã«åè´ããå ¨ä»¶(map_list)ãå°å³ã«ä½¿ã 448 const hasFullMapList = (isUnlimitedMapList || isBoundsSearch) && Array.isArray(data.data.map_list); 449 450 const setStoreExtraFields = (store) => { 451 store.store_post_fc_label = store.store_post_fc 452 ? 'é»è©±çªå·' 453 : 'éè©±ç¡æ'; 454 455 store.store_post_tel_free_text = store.store_post_fc ? '' : '(ç¡æ)'; 456 }; 457 458 data.data.list.forEach(store => { 459 setStoreExtraFields(store); 460 combinedHTML += processTemplate(templateHTML, store); 461 462 // map_list ãããå ´åãå°å³ç¨ã®HTMLã¯ãã®ã«ã¼ãã§ã¯ä½ããå¾ç¶ã®å ¨ä»¶ã«ã¼ãã§ä½ã 463 if (!hasFullMapList && mapTemplateHTML && (isUnlimitedMapList || currentMapListCount < MAP_LIST_LIMIT)) { 464 combinedMapHTML += processTemplate(mapTemplateHTML, store); 465 mapStoreList.push(store); 466 currentMapListCount++; 467 } 468 }); 469 470 // ã¨ãªã¢å ã®å ¨åºèãã³ã表示ï¼ãã£ã¨è¦ãã§ã®åèªã¿è¾¼ã¿æã¯åæ§ç¯ããªãï¼ 471 if (hasFullMapList && !isAppend && mapTemplateHTML) { 472 data.data.map_list.forEach(store => { 473 setStoreExtraFields(store); 474 combinedMapHTML += processTemplate(mapTemplateHTML, store); 475 mapStoreList.push(store); 476 }); 477 } 478 479 // çæããHTMLã js_store_result ã®ä¸ã«æ¿å ¥ 480 if (isAppend) { 481 target.insertAdjacentHTML('beforeend', combinedHTML); 482
483 // #js_store_map çã§åæ ï¼ã¨ãªã¢æ¤ç´¢ã§å ¨ä»¶è¡¨ç¤ºæ¸ã¿ã®å ´åã¯è¿½å ããªãï¼ 484 if (mapTarget && window.jQuery && !hasFullMapList) { 485 if ($(mapTarget).hasClass('slick-initialized')) { 486 const tempContainer = document.createElement('div'); 487 tempContainer.innerHTML = combinedMapHTML; 488 Array.from(tempContainer.children).forEach(child => { 489 $(mapTarget).slick('slickAdd', child.outerHTML); 490 }); 491 } else { 492 mapTarget.insertAdjacentHTML('beforeend', combinedMapHTML); 493 } 494 } 495 } else { 496 if (!mapOnly) { 497 target.innerHTML = combinedHTML; 498 } 499 500 // #js_store_map çã§åæ 501 if (mapTarget) { 502 mapTarget.innerHTML = combinedMapHTML; 503 if (window.jQuery) { 504 $(mapTarget).slick({ 505 arrows: false, 506 dots: false, 507 infinite: false, 508 variableWidth: true, 509 }); 510 // ã¹ã©ã¤ã夿´æã«ãã¼ã«ã¼ããã©ã¼ã«ã¹ 511 $(mapTarget).off('afterChange.mapSync').on('afterChange.mapSync', function(event, slick, currentSlide) { 512 if (typeof focusMapMarker === 'function') { 513 focusMapMarker(currentSlide); 514 } 515 }); 516 } 517 } 518 } 519 520 // ãã¼ã«ã¼ãå°å³ã«åæ ï¼ã¨ãªã¢æ¤ç´¢ã§å ¨ä»¶è¡¨ç¤ºæ¸ã¿ã®å ´åããã£ã¨è¦ãæã¯æ´æ°ããªãï¼ 521 // mapOnly(å°å³ã®è¡¨ç¤ºç¯å²ã§ã®åæ¤ç´¢)ã®å ´åã¯ãã¦ã¼ã¶ã¼ãåãããå°å³ã®ä½ç½®ã»ãºã¼ã ã夿´ããªã 522 if (typeof updateMap === 'function' && !(isAppend && hasFullMapList)) { 523 updateMap(mapStoreList, isAppend && !hasFullMapList, { skipFitBounds: mapOnly }); 524 } 525 } 526 527 // ããã£ã¨è¦ãããã¿ã³ã®è¡¨ç¤ºå¶å¾¡ 528 if (!mapOnly && moreBtn) { 529 const currentLoaded = page * 10; 530 if (currentLoaded >= data.data.total_count) { 531 moreBtn.style.display = 'none'; // å ¨ä»¶èªã¿è¾¼ã¿å®äºãããé表示 532 } else { 533 moreBtn.style.display = ''; // ã¾ã ç¶ããããã°è¡¨ç¤º 534 } 535 } 536 537 } else { 538 console.error('API error response:', data.data); 539 } 540 }) 541 .catch(error => console.error('API fetch error:', error)); 542 } 543 544 // js-store-more-btnã§è¿½å èªã¿è¾¼ã¿ 545 if (moreBtn) { 546 moreBtn.addEventListener('click', function(e) { 547 e.preventDefault(); 548 currentPage++; 549 const pref = prefSelect ? prefSelect.value : ''; 550 const city = citySelect ? citySelect.value : ''; 551 fetchStoreList({ 552 searchType: currentSearchType, 553 pref: pref, 554 city: city, 555 page: currentPage, 556 isAppend: true, 557 lat: currentLat, 558 lng: currentLng 559 }); 560 }); 561 } 562 563 // ãæ¤ç´¢æ¡ä»¶ã¯ãªã¢ããã¿ã³ãã¯ãªãã¯ãããã¨ã 564 const resetBtn = document.querySelector('.js-search-reset'); 565 if (resetBtn) { 566 resetBtn.addEventListener('click', function(e) { 567 e.preventDefault(); 568 569 // ã»ã¬ã¯ãããã¯ã¹ãåæç¶æ ã«æ»ã 570 if (prefSelect) prefSelect.value = ''; 571 if (citySelect) { 572 citySelect.innerHTML = '<option value="">å¸åºçºæã鏿</option>'; 573 citySelect.disabled = true; 574 } 575 576 // ãã©ã¡ã¼ã¿ããªã»ãããã¦å ¨ä»¶åå¾ 577 currentPage = 1; 578 currentLat = null; 579 currentLng = null; 580 currentSearchType = 'area'; 581 582 fetchStoreList({ 583 searchType: currentSearchType, 584 pref: '', 585 city: '', 586 page: currentPage, 587 isAppend: false 588 }); 589 }); 590 } 591 592 593 const initialPref = prefSelect ? prefSelect.value : ''; 594 const initialCity = citySelect ? citySelect.value : ''; 595 currentSearchType = 'area'; 596 fetchStoreList({ 597 searchType: currentSearchType, 598 pref: initialPref, 599 city: initialCity, 600 page: currentPage, 601 isAppend: false 602 }); 603 604 605 606 // #gmap ã« google map api ã§å°å³è¡¨ç¤º 607 let map; 608 let markers = []; 609 let infoWindows = []; // è¤æ°ã®å¹ãåºãã管çããããã®é å 610 let currentLocationMarker = null; // ç¾å¨å°ãã¼ã«ã¼ã管çãã夿° 611 let suppressMapMoveRefetch = false; // fitBoundsçãèªåã®ã³ã¼ãã«ããå°å³ç§»åã§ã¯ãã©ãã°ï¼ãºã¼ã åæ¤ç´¢ãçºçãããªãããã®ãã©ã° 612 let userMovedMap = false; // ãã©ãã°ï¼ãºã¼ã ãã¾ãã¯ç¾å¨å°ã¸ã®åã»ã³ã¿ãªã³ã°ã§å°å³ãåãããã¨ã示ããã©ã°ï¼idleæã«ãããè¦ã¦ååå¾ããã夿ããï¼ 613 let pendingMapUpdate = null; // Google Mapsæ¬ä½ã®èªã¿è¾¼ã¿ãéã«åããªãã£ãå ´åã«ãå°å³ã使ããããã«ãªã£ã¦ããåæ ããããã®ä¿çãã¼ã¿ 614 615 function initMap() { 616 const mapElement = document.getElementById('gmap'); 617 if (!mapElement) return; 618 mapElement.style.height = '100%'; 619 620 // åæä½ç½® 621 const initialLocation = { lat: 35.681236, lng: 139.767125 }; 622 623 map = new google.maps.Map(mapElement, { 624 center: initialLocation, 625 zoom: 8, 626 }); 627 628 window.shopMap = map; 629 window.shopMapCenter = initialLocation; 630
631 // InfoWindowã®éãããã¿ã³ï¼Ããã¿ã³ï¼ãé表示ã«ããCSSãåçã«è¿½å 632 const style = document.createElement('style'); 633 style.innerHTML = '.gm-style .gm-ui-hover-effect { display: none !important; } .gm-style-iw { padding: 0 !important; } .gm-style .gm-style-iw-d { overflow: hidden !important; } .gm-style-iw-chr { display:none !important; }'; 634 document.head.appendChild(style); 635 636 // ç¾å¨å°æ¤ç´¢ä¸ã«å°å³ããã©ãã°ï¼ãºã¼ã ãããã表示ä¸ã®ç¯å²å ã®åºèãååå¾ãã 637 map.addListener('dragend', function() { 638 userMovedMap = true; 639 }); 640 641 map.addListener('zoom_changed', function() { 642 // fitBounds()ãsetZoom()ãªã©ãèªåã®ã³ã¼ãã«ãããºã¼ã 夿´ã¯å¯¾è±¡å¤ã«ãã 643 if (suppressMapMoveRefetch) return; 644 userMovedMap = true; 645 }); 646 647 map.addListener('idle', function() { 648 if (!userMovedMap) return; 649 userMovedMap = false; 650 651 if (currentSearchType !== 'nearby') return; 652 653 const mapBounds = map.getBounds(); 654 if (!mapBounds) return;
655 const sw = mapBounds.getSouthWest(); 656 const ne = mapBounds.getNorthEast(); 657 658 fetchStoreList({ 659 searchType: 'nearby', 660 lat: currentLat, 661 lng: currentLng, 662 isAppend: false, 663 mapOnly: true, 664 bounds: { 665 swLat: sw.lat(), 666 swLng: sw.lng(), 667 neLat: ne.lat(), 668 neLng: ne.lng() 669 } 670 }); 671 }); 672 673 // Google Mapsæ¬ä½ã®èªã¿è¾¼ã¿ãéã«åããä¿çããã¦ããæ´æ°ãããã°ãããã§åæ ãã 674 if (pendingMapUpdate) { 675 const pending = pendingMapUpdate; 676 pendingMapUpdate = null; 677 updateMap(pending.storeList, pending.isAppend, pending.options); 678 } 679 } 680 681 // åå¾ããåºèãã¼ã¿ããã¨ã«ãããã®ãã¼ã«ã¼ãæ´æ° 682 function updateMap(storeList, isAppend, options = {}) { 683 const skipFitBounds = options.skipFitBounds || false; 684 685 // Google Mapsæ¬ä½ã®èªã¿è¾¼ã¿ãã¾ã å®äºãã¦ããªãå ´åã¯ãèªã¿è¾¼ã¿å®äºå¾ã«åæ ã§ããããä¿çãã 686 if (!map) { 687 pendingMapUpdate = { storeList, isAppend, options }; 688 return; 689 } 690 691 if (!isAppend) { 692 // æ°è¦æ¤ç´¢æã¯æ¢åã®ãã¼ã«ã¼ãã¯ãªã¢ 693 markers.forEach(marker => marker.setMap(null)); 694 infoWindows.forEach(iw => iw.close()); 695 markers = []; 696 infoWindows = []; 697 // ç¾å¨å°ã®ãã¼ã«ã¼ãã¯ãªã¢ 698 if (currentLocationMarker) { 699 currentLocationMarker.setMap(null); 700 currentLocationMarker = null; 701 } 702 } 703 704 storeList.forEach(store => { 705 const markerIndex = markers.length; // ç¾å¨ã®ãã¼ã«ã¼ã®ã¤ã³ããã¯ã¹ 706 const lat = parseFloat(store.store_lat); 707 const lng = parseFloat(store.store_lng); 708 709 // 緯度ã»çµåº¦ãæå¹ãªæ°å¤ã§ãããã㤠0,0 ã§ã¯ãªãå ´åã®ã¿ãã¼ã«ã¼ã追å 710 if (Number.isFinite(lat) && Number.isFinite(lng) && lat !== 0 && lng !== 0) { 711 const position = { lat: lat, lng: lng }; 712 713 // FCãã©ããã§ãã¼ã«ã¼ç»åãåãæ¿ãï¼ãã¹ã¯å®éã®ç»åã«åããã¦å¤æ´ãã¦ãã ããï¼ 714 const isFC = store.store_post_fc; 715 const iconPath = isFC ? '/wp-content/themes/bsportal/assets/img/new/store-purchase/pin_fc.svg' : '/wp-content/themes/bsportal/assets/img/new/store-purchase/pin_direct.svg'; 716 717 const markerIcon = { 718 url: iconPath, 719 scaledSize: new google.maps.Size(35, 41) 720 }; 721 722 const marker = new google.maps.Marker({ 723 position: position, 724 map: map, 725 title: store.store_post_name, 726 icon: markerIcon, 727 zIndex: 1 728 }); 729 730 const storeName = store.store_post_name; 731 const storeAddress = `${store.store_post_address1 || ''}${store.store_post_address2 || ''}${store.store_post_address3 || ''}`; 732 const storeLink = store.store_post_slag ? `/store/${store.store_post_slag}/` : '#'; 733 734 const infoWindow = new google.maps.InfoWindow({ 735 content: ` 736 <div style="padding: 10px; font-size: 14px;"> 737 <h3 style="margin:0;font-weight:700;font-size:1.4rem;">${storeName}</h3> 738 </div> 739 ` 740 }); 741 742 // ãã¼ã«ã¼ã¯ãªãã¯æã«è©²å½ã®ã¹ã©ã¤ãã¸ç§»åããå¹ãåºããéã 743 marker.addListener('click', () => { 744 const mapTarget = document.getElementById('js_store_map'); 745 if (mapTarget && window.jQuery && $(mapTarget).hasClass('slick-initialized')) { 746 $(mapTarget).slick('slickGoTo', markerIndex); 747 } 748 749 infoWindows.forEach(iw => iw.close()); 750 infoWindow.open(map, marker); 751 }); 752 753 markers.push(marker); 754 infoWindows.push(infoWindow); 755 } 756 }); 757 758 // ç¾å¨å°ãåå¾ã§ãã¦ããå ´åã¯ãããã©ã«ãã®ãã¼ã«ã¼ã追å 759 if (currentSearchType === 'nearby' && currentLat !== null && currentLng !== null) { 760 if (!currentLocationMarker) { 761 currentLocationMarker = new google.maps.Marker({ 762 position: { lat: currentLat, lng: currentLng }, 763 map: map, 764 title: 'ç¾å¨å°', 765 }); 766 } 767 } 768
769 // ãã¼ã«ã¼ã1ã¤ä»¥ä¸ããå ´åã®ã¿å°å³ã®è¡¨ç¤ºç¯å²ãèª¿æ´ 770 if (markers.length > 0) { 771 const bounds = new google.maps.LatLngBounds(); 772 // ç¾å¨è¡¨ç¤ºããã¦ãããã¹ã¦ã®ãã¼ã«ã¼ãç¯å²ã«å«ãã 773 markers.forEach(marker => { 774 bounds.extend(marker.getPosition()); 775 }); 776 777 // ç¾å¨å°æ¤ç´¢ã®å ´åã¯ãç¾å¨å°ãç¯å²ã«å«ãã 778 if (currentSearchType === 'nearby' && currentLat !== null && currentLng !== null) { 779 bounds.extend(new google.maps.LatLng(currentLat, currentLng)); 780 } 781 782 // ã¿ãåãæ¿ãæã«ä½¿ç¨ã§ããããã«boundsãã°ãã¼ãã«ã«ä¿æ 783 window.shopMapBounds = bounds; 784 785 // å°å³ã®è¡¨ç¤ºç¯å²ã§ã®åæ¤ç´¢(ãã©ãã°ï¼ãºã¼ã )ã®å ´åã¯ãã¦ã¼ã¶ã¼ãåãããå°å³ã®ä½ç½®ã»ãºã¼ã ã夿´ããªã 786 if (!skipFitBounds) { 787 const mapElement = document.getElementById('gmap'); 788 if (mapElement && mapElement.offsetWidth > 0 && mapElement.offsetHeight > 0) { 789 suppressMapMoveRefetch = true; 790 map.fitBounds(bounds, { top: 50, right: 50, bottom: 150, left: 50 }); 791 } 792 793 if (!isAppend) { 794 // 1åºèã ããããããå ´åãªã©ã«ãºã¼ã ããããªãããã«å¶é 795 const listener = google.maps.event.addListener(map, 'idle', function () { 796 if (map.getZoom() > 15) map.setZoom(15); 797 window.shopMapCenter = map.getCenter(); 798 google.maps.event.removeListener(listener); 799 suppressMapMoveRefetch = false; 800 }); 801 } else { 802 suppressMapMoveRefetch = false; 803 } 804 } 805 } 806 } 807 808 // ç¹å®ã®ãã¼ã«ã¼ã«ãã©ã¼ã«ã¹ãã颿° 809 function focusMapMarker(index) { 810 if (map && markers[index]) { 811 // ãã¼ã«ã¼ãç»é¢ä¸å¤®ã«ç§»å 812 map.panTo(markers[index].getPosition()); 813 814 // ä»ã®å¹ãåºããå ¨ã¦éãã対象ã®å¹ãåºããéã 815 infoWindows.forEach(iw => iw.close()); 816 infoWindows[index].open(map, markers[index]); 817 818 // InfoWindowã¨ãã¼ã«ã¼ã®z-indexãæä½ãã¦åé¢ã«è¡¨ç¤º 819 infoWindows.forEach((iw, i) => { 820 iw.setZIndex(i === index ? 999 : 1); 821 }); 822 markers.forEach((m, i) => { 823 m.setZIndex(i === index ? 999 : 1); 824 }); 825 } 826 } 827 828 // å°å³ã®ãªãµã¤ãºã¨è¡¨ç¤ºé åã®èª¿æ´ãè¡ãã°ãã¼ãã«é¢æ° 829 function resizeAndFitMap() { 830 if (window.shopMap) { 831 // ãã®ãªãµã¤ãºï¼åãã£ããã«ããå°å³ç§»åããã¦ã¼ã¶ã¼ã®ãã©ãã°ï¼ãºã¼ã ã¨èª¤æ¤ç¥ããªãããæå¶ãã 832 suppressMapMoveRefetch = true; 833 google.maps.event.trigger(window.shopMap, 'resize'); 834 // boundsãè¨å®ããã¦ããã°fitBoundsããããã§ãªããã°ä¸å¿ä½ç½®ãåè¨å® 835 if (window.shopMapBounds) { 836 window.shopMap.fitBounds(window.shopMapBounds, { top: 50, right: 50, bottom: 150, left: 50 }); 837 } else if (window.shopMapCenter) { 838 window.shopMap.setCenter(window.shopMapCenter); 839 } 840 google.maps.event.addListenerOnce(window.shopMap, 'idle', function() { 841 suppressMapMoveRefetch = false; 842 }); 843 } 844 } 845 window.resizeAndFitMap = resizeAndFitMap; 846 847 // Google Mapså´ã®ã³ã¼ã«ããã¯ããå¼ã¹ãããã«ãå®éã®åæåå¦çãç»é²ãã 848 // ï¼window.initMap èªä½ã¯ãã¡ã¤ã«åé ã§å ã«å®ç¾©æ¸ã¿ãinitMapCalled ã§äºéå®è¡ãé²ãï¼ 849 let initMapCalled = false; 850 function runInitMapOnce() { 851 if (initMapCalled) return; 852 initMapCalled = true; 853 initMap(); 854 } 855 window.__runInitMap = runInitMapOnce; 856 857 // ãã§ã«ã³ã¼ã«ããã¯ãå ã«çºç«ãã¦ããå ´åãã¾ãã¯APIãæ¢ã«èªã¿è¾¼ã¿æ¸ã¿ã®å ´åã¯ç´æ¥å®è¡ 858 if (window.__googleMapsReady || (typeof google !== 'undefined' && google.maps)) { 859 runInitMapOnce(); 860 } 861 862 // ãè¿ãã®ãåºãæ¢ããæ©è½ï¼ç¾å¨å°åå¾ï¼ 863 const searchNearbyButtons = document.querySelectorAll('.js-search-nearby'); 864 searchNearbyButtons.forEach(function(searchNearbyButton) { 865 searchNearbyButton.addEventListener('click', function(e) { 866 e.preventDefault(); 867 868 if (navigator.geolocation) { 869 navigator.geolocation.getCurrentPosition( 870 function(position) { 871 const lat = position.coords.latitude; 872 const lng = position.coords.longitude; 873 874 if (prefSelect) prefSelect.value = ''; 875 if (citySelect) { 876 citySelect.innerHTML = '<option value="">å¸åºçºæã鏿</option>'; 877 citySelect.disabled = true; 878 } 879 880 currentPage = 1; 881 currentLat = lat; 882 currentLng = lng; 883 currentSearchType = 'nearby'; 884 // 以åã®å°å³æä½ã§ç«ã£ãã¾ã¾ã«ãªã£ã¦ããå¯è½æ§ã®ãããã©ã°ããªã»ãããã¦ãã 885 userMovedMap = false;
886 fetchStoreList({ 887 searchType: currentSearchType, 888 pref: '', 889 city: '', 890 page: currentPage, 891 isAppend: false, 892 lat: currentLat, 893 lng: currentLng 894 }); 895 896 // å°å³ã¿ãã«åãæ¿ãã 897 if (window.jQuery) { 898 const $mapTabBtn = window.jQuery('.p-store-purchase__result_tab_btn').eq(1); 899 if ($mapTabBtn.length && !$mapTabBtn.hasClass('is-active')) { 900 $mapTabBtn.trigger('click'); 901 } 902 } 903 904 // #store-result ã«ã¹ã¯ãã¼ã«ãã 905 const storeResultEl = document.getElementById('store-result'); 906 if (storeResultEl) { 907 const header = document.querySelector('.l-header'); 908 const position = storeResultEl.getBoundingClientRect().top + window.pageYOffset; 909 910 // ã¹ã¯ãã¼ã«ä¸ãscroll.jså´ã®ãããã¼åºå®è¡¨ç¤ºãã¸ãã¯ã¨ç«¶åãã¦éãªããçºçãããã¨ãããããã 911 // ã¢ãã¡ã¼ã·ã§ã³ä¸ã¯ä¸æçã«ãããã¼ãé表示ã«ãã¦ãã 912 if (header) { 913 header.style.visibility = 'hidden'; 914 } 915 916 window.scrollTo({ 917 top: position, 918 behavior: 'smooth' 919 }); 920 921 // çå°å¾ãæçµçãªã¹ã¯ãã¼ã«ä½ç½®ã«å¿ãããããã¼ã®ç¶æ ãç´æ¥æå®ãã¦ããè¡¨ç¤ºã«æ»ã 922 setTimeout(function() { 923 if (!header) return; 924 const HEADER_STICKY_TRIGGER = 600; // scroll.js ã® trigger ã¨åãå¤ 925 if (window.pageYOffset <= HEADER_STICKY_TRIGGER) { 926 header.classList.remove('is-sticky', 'is-hide'); 927 } else { 928 header.classList.remove('is-sticky'); 929 header.classList.add('is-hide'); 930 } 931 header.style.visibility = ''; 932 }, 600); 933 } 934 }, 935 function(error) { 936 let message = 'ä½ç½®æ å ±ã®åå¾ã«å¤±æãã¾ããã'; 937 switch (error.code) { 938 case error.PERMISSION_DENIED: 939 message = 'ä½ç½®æ å ±ã®å©ç¨ã許å¯ããã¦ãã¾ããããã©ã¦ã¶ã®è¨å®ãã確èªãã ããã'; 940 break; 941 case error.POSITION_UNAVAILABLE: 942 message = 'ç¾å¨ä½ç½®ãåå¾ã§ãã¾ããã§ããã'; 943 break; 944 case error.TIMEOUT: 945 message = 'ä½ç½®æ å ±ã®åå¾ãã¿ã¤ã ã¢ã¦ããã¾ããã'; 946 break; 947 } 948 alert(message); 949 } 950 ); 951 } else { 952 alert('ã使ãã®ãã©ã¦ã¶ã§ã¯ä½ç½®æ å ±å徿©è½ããå©ç¨ããã ãã¾ããã'); 953 } 954 }); 955 }); 956 957 const currentButtons = document.querySelectorAll('.js-current'); 958 if (currentButtons.length > 0) { 959 currentButtons.forEach(button => { 960 button.addEventListener('click', function(e) { 961 e.preventDefault(); 962 963 if (currentSearchType === 'nearby') { 964 if (navigator.geolocation) { 965 navigator.geolocation.getCurrentPosition( 966 function(position) { 967 const lat = position.coords.latitude; 968 const lng = position.coords.longitude; 969 970 // ç¾å¨å°ãææ°ã®ä½ç½®ã«æ´æ°ï¼ç¾å¨å°ãã¼ã«ã¼ã»è·é¢è¡¨ç¤ºã«ãåæ ãããï¼ 971 currentLat = lat; 972 currentLng = lng; 973 974 if (window.shopMap) { 975 // å°å³ãè½ã¡çãã(idle)ã¿ã¤ãã³ã°ã§ããã®ä½ç½®ãä¸å¿ã¨ããç¯å²ã®åºèãååå¾ããã 976 userMovedMap = true; 977 window.shopMap.panTo({ lat: lat, lng: lng }); 978 } 979 }, 980 function(error) { 981 let message = 'ä½ç½®æ å ±ã®åå¾ã«å¤±æãã¾ããã'; 982 switch (error.code) { 983 case error.PERMISSION_DENIED: 984 message = 'ä½ç½®æ å ±ã®å©ç¨ã許å¯ããã¦ãã¾ããããã©ã¦ã¶ã®è¨å®ãã確èªãã ããã'; 985 break; 986 case error.POSITION_UNAVAILABLE: 987 message = 'ç¾å¨ä½ç½®ãåå¾ã§ãã¾ããã§ããã'; 988 break; 989 case error.TIMEOUT: 990 message = 'ä½ç½®æ å ±ã®åå¾ãã¿ã¤ã ã¢ã¦ããã¾ããã'; 991 break; 992 } 993 alert(message); 994 } 995 ); 996 } else { 997 alert('ã使ãã®ãã©ã¦ã¶ã§ã¯ä½ç½®æ å ±å徿©è½ããå©ç¨ããã ãã¾ããã'); 998 } 999 } else { 1000 const searchNearbyBtn = document.querySelector('.js-search-nearby'); 1001 if (searchNearbyBtn) { 1002 searchNearbyBtn.click(); 1003 } 1004 } 1005 }); 1006 }); 1007 } 1008 1009 // ãã¨ãªã¢ããæ¢ãããã¿ã³ï¼#searchï¼ã¯ãªãã¯æï¼ã¹ã¯ãã¼ã«ï¼ã¨ãªã¢æ¤ç´¢ã®ã¢ã³ã¼ãã£ãªã³ãéã 1010 const openAreaSearchButtons = document.querySelectorAll('.js-open-area-search'); 1011 openAreaSearchButtons.forEach(function(button) { 1012 button.addEventListener('click', function(e) { 1013 const target = document.getElementById('search'); 1014 if (!target) return; 1015 1016 e.preventDefault(); 1017 1018 const destination = target.getBoundingClientRect().top + window.pageYOffset; 1019 1020 if (window.jQuery) { 1021 window.jQuery('html').css('scroll-behavior', 'auto'); 1022 window.jQuery('html, body').stop().animate({ scrollTop: destination }, 500, function() { 1023 window.jQuery('html').css('scroll-behavior', ''); 1024 }); 1025 } else { 1026 window.scrollTo({ top: destination, behavior: 'smooth' }); 1027 } 1028 1029 // å®éã®ã¨ãªã¢æ¤ç´¢ã¢ã³ã¼ãã£ãªã³ãéãï¼ãã§ã«éãã¦ããã°ä½ãããªãï¼ 1030 const accordionBtn = document.querySelector('.p-store-purchase__search_form_accordion'); 1031 if (accordionBtn && !accordionBtn.classList.contains('is-open')) { 1032 accordionBtn.click(); 1033 } 1034 }); 1035 }); 1036 1037});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.