PageSourceSearch

https://www.hondacars-sensyu.com/assets/js/nearby.js?153323

js hondacars-sensyu.com collected 2026-10-08 06:33:41 UTC 13,842 bytes, 350 lines download raw bytes

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‚ªŽg—p‰Â”\‚©ƒ`ƒFƒbƒN
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          //10•b‚Ń^ƒCƒ€ƒAƒEƒg
46          maximumAge: 600000 //10•ªŠÔ—LŒø
47
48        });
49        return dfd.promise();
50      }
51
52      // ZŠŽw’è
53      function dfdPointPosition() {
54        var dfd = $.Deferred();
55
56        if (type === 'gps') {
57          // Geolocation‚ªŽg—p‰Â”\‚©ƒ`ƒFƒbƒN
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            //10•b‚Ń^ƒCƒ€ƒAƒEƒg
73            maximumAge: 600000 //10•ªŠÔ—LŒø
74
75          });
76          return dfd.promise();
77        } else if (type === 'address') {
78          // —X•֔ԍ†‚©‚Ç‚¤‚©‚ð”»’è‚·‚éƒtƒ@ƒ“ƒNƒVƒ‡ƒ“
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Š‚̈ܓxŒo“x‚ðŽæ“¾
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[ƒ^‚ª‘µ‚Á‚½’iŠK‚Ń\[ƒg‚ðŠJŽn
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          // sort—p‚Ì”z—ñ‚ð’è‹`
147          var sorted = [];
148
149          // ‹——£‚ÌŠ„‚èo‚µ‚ðs‚È‚¢AŠeƒf[ƒ^‚Édistance‘®«‚ðÝ’è
150          for (var key in points) {
151            var _distance = getDistance(points[key].lat, points[key].lng, lat, lng, 0) / 1000; //km‚ÅŽZo
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">‹x“X“ú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[ƒrƒX‚ª—LŒø‚È’[––‚©‚炲—˜—p‚­‚¾‚³‚¢B");
265        } else {
266          alert("ZŠ‚Ü‚½‚Í—X•֔ԍ†‚ð“ü—Í‚µ‚Ä‚­‚¾‚³‚¢B");
267        }
268
269        $('.' + settings.loading_class).remove();
270      });
271
272      /**
273       * 2“_ŠÔ‚̈ܓxŒo“x‚©‚ç‹——£‚ðŽæ“¾
274       * ‘ª’nüqŠCŽZ–@‚ðŽg—p‚µ‚Ä‹——£‚ðŽZo‚·‚éB
275       * @see http://hamasyou.com/blog/2010/09/07/post-2/
276       * @param float ˆÜ“x1
277       * @param float Œo“x2
278       * @param float ˆÜ“x2
279       * @param float Œo“x2
280       * @param ¬”“_ˆÈ‰º‚ÌŒ…”(‚ׂ«æ‚ÅŽZo¸“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.