1document.addEventListener('DOMContentLoaded', function() { 2 3 // ããã¤ã¹å¹ ã«å¿ãã¦srcãã©ã¡ã¼ã¿ã®å¤ãè¨å®ããã 4 const deviceSrcField = document.getElementById('device_src'); 5 deviceSrcField.value = window.innerWidth >= 768 ? 'bestcar_rightmodule_pc' : 'bestcar_rightmodule_sp'; 6 7 // ã¦ã£ã³ãã¦ãµã¤ãºã夿´ãããã¨ãã«åè¨å®ããã 8 const mediaQuery = window.matchMedia('(min-width: 768px)'); 9 function handleChange(e) { 10 if (e.matches) { 11 deviceSrcField.value = 'bestcar_rightmodule_pc'; 12 } else { 13 deviceSrcField.value = 'bestcar_rightmodule_sp'; 14 } 15 } 16 handleChange(mediaQuery); 17 mediaQuery.addEventListener('change', handleChange); 18 19 // ã»ã¬ã¯ãè¦ç´ ãåå¾ 20 const makerSelect = document.getElementById('maker'); 21 const modelSelect = document.getElementById('model'); 22 23 // ã¡ã¼ã«ã¼é¸æç¨ã»ã¬ã¯ãã«ãèªã¿è¾¼ã¿ä¸ãç¶æ ãè¨å® 24 makerSelect.disabled = true; 25 const loadingOption = document.createElement('option'); 26 loadingOption.text = 'èªã¿è¾¼ã¿ä¸...'; 27 makerSelect.add(loadingOption); 28 29 // APIããã¡ã¼ã«ã¼ä¸è¦§ãåå¾ 30 fetch('/wp-json/carview/v1/makers') 31 .then(response => response.json()) 32 .then(data => { 33 // èªã¿è¾¼ã¿ç¶æ ãè§£é¤ 34 makerSelect.innerHTML = ''; 35 makerSelect.disabled = false; 36 37 // ããã©ã«ããªãã·ã§ã³ã追å 38 const defaultOption = document.createElement('option'); 39 defaultOption.value = ''; 40 defaultOption.text = 'ã¡ã¼ã«ã¼ã鏿'; 41 makerSelect.add(defaultOption); 42 43 // ã¡ã¼ã«ã¼ãªã¹ããåå¾ 44 const makerList = data.scope[0].entry[0].maker_list[0]; 45 // å½å ã¡ã¼ã«ã¼ã¨è¼¸å ¥ã¡ã¼ã«ã¼ãï¼ã¤ã®é åã«çµ±å 46 const allMakers = []; 47 if (makerList.domestic && makerList.domestic.length > 0) { 48 allMakers.push(...makerList.domestic); 49 } 50 if (makerList.imported && makerList.imported.length > 0) { 51 allMakers.push(...makerList.imported); 52 } 53 54 // ãã¹ã¦ã®ã¡ã¼ã«ã¼ãã»ã¬ã¯ãã«è¿½å 55 allMakers.forEach(maker => { 56 const option = document.createElement('option'); 57 option.value = maker.mkid; 58 option.text = maker.mkname; 59 makerSelect.add(option); 60 }); 61 }) 62 .catch(error => { 63 console.error('Error fetching makers:', error); 64 makerSelect.innerHTML = '<option value="">ã¨ã©ã¼ãçºçãã¾ãã</option>'; 65 makerSelect.disabled = false; 66 }); 67 68 // ã¡ã¼ã«ã¼é¸æå¤æ´æã®å¦ç 69 makerSelect.addEventListener('change', function() { 70 71 // ã¢ãã«é¸æç¨ã»ã¬ã¯ãããªã»ãããç¡å¹åããã 72 modelSelect.innerHTML = '<option value="">ã¢ãã«ã鏿</option>'; 73 modelSelect.disabled = true; 74 75 if (this.value) { 76 const modelLoadingOption = document.createElement('option'); 77 modelLoadingOption.text = 'èªã¿è¾¼ã¿ä¸...'; 78 modelSelect.innerHTML = ''; 79 modelSelect.add(modelLoadingOption); 80 81 const mkParam = encodeURIComponent(this.value); 82 fetch(`/wp-json/carview/v1/models?maker_id=${mkParam}`) 83 .then(response => response.json()) 84 .then(data => { 85 modelSelect.innerHTML = ''; 86 modelSelect.disabled = false; 87 88 const defaultModelOption = document.createElement('option'); 89 defaultModelOption.value = ''; 90 defaultModelOption.text = 'ã¢ãã«ã鏿'; 91 modelSelect.add(defaultModelOption); 92 93 if (data && data.scope && data.scope[0] && data.scope[0].entry && 94 data.scope[0].entry[0] && data.scope[0].entry[0].model_list) { 95 96 const modelList = data.scope[0].entry[0].model_list; 97 98 // è»ç¨®åã§ã½ã¼ã 99 modelList.sort((a, b) => a.mdname.localeCompare(b.mdname)); 100 101 // å ¨ã¦ã®ã¢ãã«ãã»ã¬ã¯ãã«è¿½å 102 modelList.forEach(model => { 103 const option = document.createElement('option'); 104 option.value = model.mdid; 105 option.text = model.mdname; 106 modelSelect.add(option); 107 }); 108 } 109 }) 110 .catch(error => { 111 console.error('Error fetching models:', error); 112 modelSelect.innerHTML = '<option value="">ã¨ã©ã¼ãçºçãã¾ãã</option>'; 113 modelSelect.disabled = false;
114 }); 115 } 116 }); 117});
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.