1"use strict"; 2 3(function ($, window, undefined) { 4 $.fn.nearby = function (options) { 5 // console.log( this ); 6 // => element who fired event. 7 // Create some defaults, extending them with any options that were provided. 8 var settings = $.extend({ 9 array: null, 10 from: 'gps', 11 min: 4, 12 input: '.js-nearby-input', 13 container_class: 'c-showroom-nearby', 14 result_class: '.c-showroom-nearby__foot', 15 loading_class: 'c-showroom-nearby__loading', 16 item_class: 'c-showroom-nearby-item', 17 link_prefix: '', 18 view: 'distance' 19 }, options); 20 var el = this; 21 $('.' + settings.container_class).prepend('<span class="' + settings.loading_class + '">...</span>'); 22 return this.each(function () { 23 var points = settings.array; 24 var type = settings.from; 25 26 // »ÝÊuÌæ¾ 27 function dfdCurrentPosition() { 28 var dfd = $.Deferred(); 29 30 // GeolocationªgpÂ\©`FbN 31 if (!window.navigator.geolocation) dfd.reject(); 32 33 // »ÝnÌæ¾ 34 window.navigator.geolocation.getCurrentPosition( // Success 35 function (position) { 36 dfd.resolve(position); 37 }, // Error 38 function (error) { 39 dfd.reject(); 40 }, // Options 41 { 42 enableHighAccuracy: true, 43 //Êuîñ̸xð 44 timeout: 10000, 45 //10bÅ^CAEg 46 maximumAge: 600000 //10ªÔLø 47 48 }); 49 return dfd.promise(); 50 } 51 52 // Zwè 53 function dfdPointPosition() { 54 var dfd = $.Deferred(); 55 56 if (type === 'gps') { 57 // GeolocationªgpÂ\©`FbN 58 if (!window.navigator.geolocation) dfd.reject(); 59 60 // »ÝnÌæ¾ 61 window.navigator.geolocation.getCurrentPosition( // Success 62 function (position) { 63 dfd.resolve(position); 64 }, // Error 65 function (error) { 66 dfd.reject(); 67 }, // Options 68 { 69 enableHighAccuracy: true, 70 //Êuîñ̸xð 71 timeout: 10000, 72 //10bÅ^CAEg 73 maximumAge: 600000 //10ªÔLø 74 75 }); 76 return dfd.promise(); 77 } else if (type === 'address') { 78 // XÖԩǤ©ð»è·ét@NV 79 var isPostcode = function isPostcode(postcode) { 80 if (postcode.match(/^\d{3}-?\d{4}$/)) { 81 return true; 82 } else { 83 return false; 84 } 85 }; 86 87 // wèµ½ZÌÜxoxðæ¾ 88 var place = $(settings.input).val(); 89 90 if (isPostcode(place)) { 91 $.ajax({
92 url: '/common-php/ajax.php?url=https://api.zipaddress.net/?zipcode=' + place, 93 type: "GET", 94 data: { 95 'zipcode': place 96 }, 97 dataType: 'json' 98 }).done(function (data) { 99 var fullAddress = data.data.fullAddress; 100 fullAddress = encodeURI(fullAddress); 101 $.ajax({ 102 url: '/common-php/geocoding/?q=' + fullAddress, 103 type: "GET", 104 dataType: 'xml' 105 }).done(function (xml) { 106 dfd.resolve(xml); 107 }).fail(function (error) { 108 dfd.reject(); 109 }); 110 }).fail(function (error) { 111 dfd.reject(); 112 }); 113 } else { 114 place = encodeURI(place); 115 $.ajax({ 116 url: '/common-php/geocoding/?q=' + place, 117 type: "GET", 118 dataType: 'xml' 119 }).done(function (xml) { 120 dfd.resolve(xml); 121 }).fail(function (error) { 122 dfd.reject(); 123 }); 124 } 125 126 return dfd.promise(); 127 } else {} 128 } 129 130 // f[^ªµÁ½iKÅ\[gðJn 131 $.when(dfdPointPosition()).done(function (position) { 132 var lat, lng; 133 134 // »Ýn 135 if (type === 'gps') { 136 var lat = position.coords.latitude; 137 var lng = position.coords.longitude; 138 } else if (type === 'address') { 139 var lat = $(position).find('lat').text(); 140 var lng = $(position).find('lng').text(); 141 } else { 142 alert('nearby.js : option \'from\' has Invalid value.'); 143 } 144 145 if (lat && lng) { 146 // sortpÌzñðè` 147 var sorted = []; 148 149 // £ÌèoµðsÈ¢Aef[^Édistance®«ðÝè 150 for (var key in points) { 151 var _distance = getDistance(points[key].lat, points[key].lng, lat, lng, 0) / 1000; //kmÅZo 152 153 154 points[key].distance = Math.floor(_distance * 100) / 100; 155 156 // ¬_æ2ÊÜÅÉÀè 157 sorted.push(points[key].distance); 158 } 159 160 // »Ýn©çÌ£ª¬³¢É\[g 161 sorted.sort(function (a, b) { 162 if (a < b) return -1; 163 if (a > b) return 1; 164 return 0; 165 }); 166 sorted.splice(settings.min); 167 168 // f[^ðoÍ 169 el.html(''); 170 171 // £ª¯¶XܪññoͳêĵܤÌÅoÍÏÌ_R[hðÛ¶·é 172 var already = []; 173 174 var appendHtml = ""; 175 176 for (var i = 0; i < settings.min; i++) { 177 for (var key in points) { 178 if (sorted[i] === points[key].distance && already.indexOf(points[key].shop_cd) == -1) { 179 already.push(points[key].shop_cd); 180 var cName = settings.item_class; 181 var shop = points[key]; 182 183 if (settings.type == "newcar") { 184 var contactHtml = ` 185 <div class="${cName}__contact _newcar"> 186 <a class="${cName}-button" href="https://contact.hondanet.co.jp/hc-sensyu/form/contact/inquiry/jump?contact=4&shop_code=${shop.shop_cd}" target="_blank"> 187 <span>X\ñ<small>(¤k\)</small></span> 188 </a> 189 <a class="${cName}-button" href="https://contact.hondanet.co.jp/hc-sensyu/form/contact/inquiry/jump?contact=3&shop_code=${shop.shop_cd}" target="_blank"> 190 <span>æ\ñ</span> 191 </a> 192 <a class="${cName}-button" href="https://contact.hondanet.co.jp/hc-sensyu/form/contact/inquiry/jump?contact=2&shop_code=${shop.shop_cd}" target="_blank"> 193 <span>©ÏË</span> 194 </a> 195 <a class="${cName}-button" href="https://shopsearch.honda.co.jp/auto/d-contact/input/op_auto/?form_id=0241&kyoten_cd=${shop.shop_cd}&hojin_cd=3351452&kanban_no=1" target="_blank">
196 <span>¸è\</span> 197 </a> 198 <a class="${cName}-button" href="https://contact.hondanet.co.jp/hc-sensyu/form/contact/inquiry/jump?contact=1&shop_code=${shop.shop_cd}" target="_blank"> 199 <span>J^O¿</span> 200 </a> 201 </div>`; 202 } else if (settings.type == "move") { 203 var contactHtml = ` 204 <div class="${cName}__contact _move"> 205 <a class="${cName}-button" href="https://shopsearch.honda.co.jp/auto/d-contact/input/op_auto/?form_id=0261&kyoten_cd=${shop.shop_cd}&hojin_cd=3351452&kanban_no=1" target="_blank"> 206 <span>]A</span> 207 </a> 208 </div>`; 209 } else if (settings.type == "other") { 210 var contactHtml = ` 211 <div class="${cName}__contact _other"> 212 <a class="${cName}-button" href="https://shopsearch.honda.co.jp/auto/d-contact/input/op_auto/?form_id=0311&kyoten_cd=${shop.shop_cd}&hojin_cd=3351452&kanban_no=1" target="_blank"> 213 <span>»Ì¼¨â¹</span> 214 </a> 215 </div>`; 216 } else { 217 var contactHtml = ` 218 <div class="${cName}__contact"> 219 <a class="${cName}-button" href="/showroom/sr${shop.shop_cd}.html#contact"> 220 <span>±ÌXÜɨâ¹</span> 221 </a> 222 </div>`; 223 } 224 225 var html = ` 226 <li class="${cName}"> 227 <a class="${cName}__head" href="/showroom/sr${shop.shop_cd}.html"> 228 <i class="${cName}__rank" data-num="${i + 1}">${i + 1}</i> 229 <div class="${cName}__name"> 230 <em>${shop.shop_name}</em> 231 </div> 232 <div class="${cName}__distance">${shop.distance}</div> 233 </a> 234 <div class="${cName}__body"> 235 <div class="${cName}__profile"> 236 <div class="${cName}__hour">cÆÔF${shop.hours}</div> 237 <div class="${cName}__close">xXúF${shop.close}</div> 238 <a class="${cName}__tel" href="tel:${shop.tel}"> 239 <i><svg xmlns="http://www.w3.org/2000/svg" width="34" height="35" viewBox="0 0 34 35" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M7.9037 6.3602C9.00759 5.25631 10.8292 5.36971 11.7876 6.60201L14.4558 10.0325C14.9454 10.662 15.1184 11.4817 14.925 12.2554L14.111 15.5116C14.025 15.8554 14.1257 16.2191 14.3763 16.4696L18.0305 20.1238C18.281 20.3743 18.6447 20.4751 18.9885 20.3891L22.2447 19.5751C23.0184 19.3816 23.8381 19.5547 24.4676 20.0443L27.8981 22.7124C29.1304 23.6709 29.2438 25.4925 28.1399 26.5964L26.6019 28.1343C25.5016 29.2347 23.8558 29.7178 22.322 29.1786C18.5137 27.8397 14.939 25.6476 11.8957 22.6043C8.85246 19.5611 6.66041 15.9864 5.32149 12.1781C4.78225 10.6443 5.2654 8.99849 6.36574 7.89816L7.9037 6.3602Z" fill="currentColor"/></svg></i> 240 <span>${shop.tel}</span> 241 </a> 242 </div> 243 ${contactHtml} 244 </div> 245 </li>`; 246 appendHtml += html; 247 } 248 } 249 } 250
251 el.html(`<ul class="${settings.container_class}__list"> 252 ${appendHtml} 253 </ul>`); 254 255 $('.' + settings.loading_class).remove(); 256 el.slideDown(); 257 $(settings.result_class).show().css('display', 'block'); 258 } else { 259 alert("ZܽÍXÖÔðü͵ľ³¢B"); 260 $('.' + settings.loading_class).remove(); 261 } 262 }).fail(function () { 263 if (type === 'gps') { 264 alert("ÊuîñT[rXªLøÈ[©ç²p¾³¢B"); 265 } else { 266 alert("ZܽÍXÖÔðü͵ľ³¢B"); 267 } 268 269 $('.' + settings.loading_class).remove(); 270 }); 271 272 /** 273 * 2_ÔÌÜxox©ç£ðæ¾ 274 * ªnüqCZ@ðgpµÄ£ðZo·éB 275 * @see http://hamasyou.com/blog/2010/09/07/post-2/ 276 * @param float Üx1 277 * @param float ox2 278 * @param float Üx2 279 * @param float ox2 280 * @param ¬_ÈºÌ (׫æÅZo¸xðwè) 281 */ 282 283 function getDistance(lat1, lng1, lat2, lng2, precision) { 284 var distance = 0; 285 286 if (Math.abs(lat1 - lat2) < 0.00001 && Math.abs(lng1 - lng2) < 0.00001) { 287 distance = 0; 288 } else { 289 lat1 = lat1 * Math.PI / 180; 290 lng1 = lng1 * Math.PI / 180; 291 lat2 = lat2 * Math.PI / 180; 292 lng2 = lng2 * Math.PI / 180; 293 var A = 6378140; 294 var B = 6356755; 295 var F = (A - B) / A; 296 var P1 = Math.atan(B / A * Math.tan(lat1)); 297 var P2 = Math.atan(B / A * Math.tan(lat2)); 298 var X = Math.acos(Math.sin(P1) * Math.sin(P2) + Math.cos(P1) * Math.cos(P2) * Math.cos(lng1 - lng2)); 299 var L = F / 8 * ((Math.sin(X) - X) * Math.pow(Math.sin(P1) + Math.sin(P2), 2) / Math.pow(Math.cos(X / 2), 2) - (Math.sin(X) - X) * Math.pow(Math.sin(P1) - Math.sin(P2), 2) / Math.pow(Math.sin(X), 2)); 300 distance = A * (X + L); 301 var decimal_no = Math.pow(10, precision); 302 distance = Math.round(decimal_no * distance / 1) / decimal_no; 303 } 304 305 return distance; 306 } 307 }); 308 309 // return for 'Method Chain' end. 310 }; 311 312// end pluginName. 313})(jQuery, window); 314 315function zip(type="all", from="address") { 316 317 // remove shop_type : 'other' 318 if (typeof gmapArr != 'undefined') { 319 $.each(gmapArr, function (i, v) { 320 if (v.shop_type == 'other') { 321 delete gmapArr[i]; 322 } 323 }); 324 } 325 326 let mapdata = (type == "newcar" && gmapArrNewcar) ? gmapArrNewcar : gmapArr; 327 var nearbyOption = { 328 array: mapdata, 329 min: 4 330 }; 331 332 nearbyOption.from = from; 333 nearbyOption.type = type; 334 var nearbyWrapper = '.js-nearby[data-search="' + type + '"] '; 335 nearbyOption.input = nearbyWrapper + '.js-nearby-input'; 336 nearbyOption.result_class = nearbyWrapper + ' .js-nearby-result'; 337 $(nearbyWrapper + '.js-nearby-list').nearby(nearbyOption); 338} 339 340$(function () { 341 $('.js-nearby-gps').on('click', function () { 342 zip($(this).closest('.js-nearby').attr('data-search'), 'gps'); 343 }); 344 $(document).on('click', '.js-nearby-hide', function () { 345 $(this).closest('.js-nearby').find('.js-nearby-result').slideUp(); 346 }); 347 $(document).on('focus', '.js-nearby-input', function () { 348 $(this).closest('.js-nearby').find('.js-nearby-result').slideUp(); 349 }); 350});
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.