PageSourceSearch

https://ufa.com/_ui/responsive/common/js/acc.ufastoresoldtoswitch.js

js ufa.com collected 2026-10-02 10:51:14 UTC 25,982 bytes, 578 lines download raw bytes

1ACC.ufastoresoldtoswitch = {
2
3    _autoload: [
4        "bindClickPickupInStoreButton",
5        "bindPickupInStoreSearch",
6        "bindClickFilterOnline",
7        "bindClickFilterAll",
8        "bindStoreSoldToSwitch",
9        "storeInfoPopup",
10        "bindViewFuelPrices",
11        ["storeSoldToSwitchContinue", $(".js-storesoldtoswitch-continue").length !== 0],
12        ["updateStoreField", $(".js-current-store-location").length !== 0],
13        "handlePermission"
14    ],
15
16    storeId: "",
17    handlePermission: function (useMyLocation) {
18        if (navigator.permissions && navigator.permissions.query) {
19            navigator.permissions.query({name:'geolocation'}).then(function(result) {
20                var currentStoreName = document.querySelector('.current-store-name');
21              if (result.state == 'granted' && (currentStoreName && !currentStoreName.innerHTML)) {
22                  navigator.geolocation.getCurrentPosition(
23                    function (position) {
24                       ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", position.coords.latitude, position.coords.longitude);
25                        setTimeout(window.location.reload.bind(window.location), 2000);//setting the wait time to 2 secs  to complete the usersoldtoswitch function
26                    },
27                    function (error) {
28                       ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", '', '');
29                    }
30                  );
31                  ACC.ufastoresoldtoswitch.spacingButtons();
32              }
33              else if (result.state == 'prompt' && (currentStoreName && !currentStoreName.innerHTML)) {
34              navigator.geolocation.getCurrentPosition(
35                    function (position) {
36                      ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", position.coords.latitude, position.coords.longitude);
37                        setTimeout(window.location.reload.bind(window.location), 2000);//setting the wait time to 2 secs  to complete the usersoldtoswitch function
38                    },
39                    function (error) {
40                      ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", '', '');
41                        setTimeout(window.location.reload.bind(window.location), 2000);//setting the wait time to 2 secs  to complete the usersoldtoswitch function
42                        ACC.ufastoresoldtoswitch.updateStoreField();
43                    }
44                );
45                ACC.ufastoresoldtoswitch.spacingButtons();
46              }
47              else if(useMyLocation){
48                $('.js-use-location-btn').hide();
49                navigator.geolocation.getCurrentPosition(
50                    function (position) {
51                       ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(useMyLocation, position.coords.latitude, position.coords.longitude);
52                    },
53                    function (error) {
54                        $(".js-location-blocked-error").removeClass("hidden");
55                       ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", '', '');
56                       location.reload();
57                    }
58                );
59                ACC.ufastoresoldtoswitch.spacingButtons();
60              }
61              else {
62                  if(!document.querySelector('.current-store-name').innerHTML){
63                      ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", '', '');
64                      setTimeout(window.location.reload.bind(window.location), 3000);//setting the wait time to 3 secs  to complete the usersoldtoswitch function
65                  }
66                  ACC.ufastoresoldtoswitch.updateStoreField();
67              }
68              result.onchange = function() {
69              }
70            });
71        }
72        else if(navigator.geolocation && (useMyLocation || (document.querySelector('.current-store-name') && !document.querySelector('.current-store-name').innerHTML))){
73            if(useMyLocation){
74                $('.js-use-location-btn').hide();
75            }
76            navigator.geolocation.getCurrentPosition(
77                function (position) {
78                   ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(useMyLocation, position.coords.latitude, position.coords.longitude);
79                },
80                function (error) {
81                    if(useMyLocation){
82                        $(".js-location-blocked-error").removeClass("hidden");
83                    }
84                   ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", '', '');
85                }
86            );
87            ACC.ufastoresoldtoswitch.spacingButtons();
88        }
89        ACC.ufastoresoldtoswitch.spacingButtons();
90    },
91
92    bindPickupInStoreSearch: function () {
93        $(document).on('click', '.js-switch-store-search-btn', function (e) {
94            e.preventDefault();
95            var location = $('#colorbox #switchLocationSearchField').val();
96            if(location)
97            {
98                ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(location, '', '');
99            }
100        });
101
102        $(document).on('keypress', '#colorbox #switchLocationSearchField', function (e) {
103            if (e.keyCode === 13) {
104                e.preventDefault();
105                var location = $('#colorbox #switchLocationSearchField').val();
106                if(location)
107                {
108                    ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(location, '', '');
109                }
110                return false;
111            }
112        });
113
114        $(document).on("click", '.js-use-location-btn', function (e) {
115            e.preventDefault();
116            ACC.ufastoresoldtoswitch.handlePermission("useMyLocation");
117        });
118    },
119    updateStoreField: function () {
120        var actionUrl = "/storesoldtoswitch/current-store";
121        var mapsUrl = "https://www.google.com/maps/dir/?api=1&destination=";
122        $.get({
123            url: ACC.config.encodedContextPath + actionUrl,
124            async: false,
125            success: function (response) {
126                if (response && response.geoPoint && response.geoPoint.latitude && response.geoPoint.longitude) {
127                    mapsUrl += response.geoPoint.latitude + "," + response.geoPoint.longitude;
128                    $(".js-current-store-name").each(function () {
129                        $(this).html(response.displayName);
130                        $(this).parent("p").removeClass("hidden");
131                    });
132                    $(".js-current-store-address").each(function () {
133                        $(this).html(response.address.formattedAddress);
134                    });
135                    $(".js-current-store-phone").each(function () {
136                        $(this).html(response.address.phone);
137                        $(this).attr("href", "tel:" + response.address.phone);
138                    });
139                    $(".js-current-store-directions").each(function () {
140                        $(this).attr("href", mapsUrl);
141                    });
142                    $(".js-no-store-selected").each(function () {
143                        $(this).addClass('hidden');
144                    });
145                }
146            }
147        });
148    },
149    bindViewFuelPrices: function () {
150	    $(document).on('click', '.view-fuel-prices-link', function (e) {
151	        e.preventDefault();
152	        $('#fuel-price-table').hide();
153	        $('.get-price-error-message').hide();
154	        $select = $('#fuel-price-selection');
155	        var currentDate = new Date();
156            var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
157            var currentDay = currentDate.getDate();
158            var currentMonth = months[currentDate.getMonth()];
159            var currentYear = currentDate.getFullYear();
160            var hour = currentDate.getHours();
161            var min = currentDate.getMinutes();
162            if (min < 10) {
163                min = "0" + min;
164            }
165            if (hour < 10) {
166                hour = "0" + hour;
167            }
168            var amPm = "AM";
169            if( hour > 12 ) {
170                hour -= 12;
171                amPm = "PM";
172            }
173            $('.fuel-price-local-time').html("As of " + hour + ":" + min + " " + amPm + ", " + currentMonth + " " + currentDay + ", " + currentYear);
174		 	$.ajax({
175	            type: "GET",
176	            url: ACC.config.encodedContextPath + "/cardlink/getPetroleumPointOfServices",
177	            success: function (response) {
178			        $select.html('');
179			        $select.append('<option value="">Select a Location</option>');
180			        $.each(response, function(key, val){
181			            $select.append('<option value="' + val.name + '"' + (val.displayName == $select.data('selected') ? ' selected' : '') + '>' + val.displayName + '</option>');
182			        })
183	            }
184	        });
185            setTimeout(function() {
186                ACC.colorbox.open("Cardlock Only Fuel Prices", {
187                        html: $("#view_fuel_price_modal").html(),
188                        scrolling: false
189                });
190            }, 500);
191	    });
192	    $(document).on('click', '#cboxLoadedContent .get-fuel-price', function (e) {
193        	var getFuelPrice = $('#cboxLoadedContent #fuel-price-selection').find(":selected").val();
194        	$('#cboxLoadedContent #fuel-price-table').hide();
195        	$('#cboxLoadedContent .get-price-error-message').hide();
196        	$.ajax({
197             type: "GET",
198             data: { siteNumber: getFuelPrice },
199        		dataType: "json",
200             url: ACC.config.encodedContextPath + "/cardlink/getPriceAjax/" + getFuelPrice,
201             success: function (response) {
202                console.log("response", response);
203                $("#cboxLoadedContent #fuel-price-table").show();
204                $('#cboxLoadedContent #fuel-price-table tbody').empty();
205                var body = $('#cboxLoadedContent #fuel-price-table tbody');
206                for (var price in response.PriceResponse.prices) {
207        	          var priceData = response.PriceResponse.prices[price];
208        	          body.append($('<tr>')
209        	              .append($('<td>', { text: priceData.Article_Description }))
210        	              .append($('<td>', { text: priceData.Unit_Price }))
211        	          )
212        	       }
213                },
214                error: function (jqXHR, textStatus) {
215                    $('#cboxLoadedContent .get-price-error-message').show();
216                    console.log(textStatus);
217                }
218             });
219        });
220        $(document.body).on('change','#cboxLoadedContent #fuel-price-selection',function(){
221            $('#cboxLoadedContent #fuel-price-table').hide();
222            $('#cboxLoadedContent .get-price-error-message').hide();
223        });
224
225	},
226    storeInfoPopup: function () {
227        $('.js-need-call-popup').on("click", function () {
228            var boxContent = $("#store-info-popup").html();
229            var titleHeader = "";
230
231            ACC.colorbox.open(titleHeader, {
232                html: boxContent,
233                width: "960px",
234            });
235        });
236    },
237    locationSearchSubmit: function (location, latitude, longitude) {
238        var geocoder = new google.maps.Geocoder();
239        if (geocoder && location) {
240            geocoder.geocode({ 'address': location }, function (results, status) {
241                if (status == google.maps.GeocoderStatus.OK) {
242                    console.log(results[0].geometry.location.lat);
243                    ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(location,results[0].geometry.location.lat,results[0].geometry.location.lng);
244                }
245                else {
246                    console.log("Geocoding failed: " + status);
247                    ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(location,latitude,longitude);
248                }
249            });
250        }else{
251            ACC.ufastoresoldtoswitch.locationSearchFinalSubmit(location,latitude,longitude);
252        }
253    },
254    locationSearchFinalSubmit: function (location, latitude, longitude) {
255              var useMyLocation = false;
256              if(location == null){
257                location = "";
258              }
259              else if(location === "useMyLocation"){
260                useMyLocation = true;
261              }
262              var actionUrl = "/storesoldtoswitch/stores-user-location";
263                           var data = {
264                               show: 'All',
265                               q: location,
266                               page: "0",
267                               latitude: latitude,
268                               longitude: longitude,
269                               useMyLocation : useMyLocation
270                           };
271
272                           $.get({
273                               url: ACC.config.encodedContextPath + actionUrl,
274                               data: data,
275                               dataType: "text",
276                               success: function (response) {
277                                   ACC.ufastoresoldtoswitch.refreshSwitchStoreColumn(response);
278                                        ACC.ufastoresoldtoswitch.updateStoreField();
279                               }
280                           });
281
282                       },
283    createListItemHtml: function (data, id) {
284
285
286        var $rdioEl = $("<input>").attr("type", "radio")
287            .attr("name", "storeNamePost")
288            .attr("id", "pickup-entry-" + id)
289            .attr("data-id", id)
290            .addClass("js-pickup-store-input")
291            .val(data.displayName);
292
293        var $divRow = $("<div class='change-store-popup-row'></div>");
294
295        var $spanElStInfo = $("<span style='flex: 40px'>")
296            .addClass("pickup-store-info")
297            .append($("<span>").addClass("pickup-store-list-entry-name sm-font").text(data.displayName))
298            .append($("<span>").addClass("pickup-store-list-entry-address sm-font").text(data.address.formattedAddress))
299            .append($("<a>")
300                .attr('data-uid', data.name)
301                .attr('href', "#")
302                .addClass("pickup-store-list-entry-select js-storesoldtoswitch-link sm-font set-store-"+data.storeType+"-"+data.name+"-selected" + (data.selected ? " ui-checkboxradio-disabled" : ""))
303                .text(data.selected ? "SELECTED" : "Set preferred store >"));
304
305
306
307        var $spanElStAvail = $("<span>")
308            .addClass("store-availability hidden");
309
310        var $divStoreSelectionIcon = $("<div style='display: flex; flex: 1; flex-direction: column'>");
311
312        if (data.isWarehouseEnabled) {
313            var $divBuyOnline = $("<div style='display: flex;align-items: center' class='mb-1'>");
314            $divBuyOnline.append("<span class='glyphicon glyphicon-shopping-cart buy-online-icon'></span>&nbsp;&nbsp;&nbsp;<span class='text-orange'>Buy Online</span>&nbsp;&nbsp;&nbsp;");
315
316            var $divBuyInStore = $("<div style='display: flex;align-items: center'>");
317            $divBuyInStore.append("<span class='glyphicon glyphicon-map-marker'></span>&nbsp;&nbsp;&nbsp;<span class='text-orange'>Buy In Store</span>&nbsp;&nbsp;&nbsp;");
318
319            $divStoreSelectionIcon.append($divBuyOnline);
320            $divStoreSelectionIcon.append($divBuyInStore);
321        }
322        else if (data.isPickupInStoreAvailable) {
323            var $divBuyInStoreOnly = $("<div style='display: flex;align-items: center'>");
324            $divBuyInStoreOnly.append("<span class='glyphicon glyphicon-map-marker in-store-inventory-icon'></span>&nbsp;&nbsp;&nbsp;<span class='text-orange'>Buy In Store Only</span>&nbsp;&nbsp;&nbsp;");
325            $divStoreSelectionIcon.append($divBuyInStoreOnly);
326        }
327
328        if (data.formattedDistance) {
329            var distance = data.formattedDistance.toString().split(" ");
330            if(!distance[0].includes('.')) {
331                distance[0] += ".0";
332            }
333
334            $spanElStAvail.removeClass("hidden");
335            $spanElStAvail.append(
336                $("<span class='text-right'>")
337                    .addClass("available")
338                    .append(document.createTextNode(distance[0] + " " + distance[1]))
339            );
340        }
341
342        $divRow.append($spanElStInfo);
343        $divRow.append($divStoreSelectionIcon);
344        $divRow.append($spanElStAvail);
345
346        var $lblEl = $("<label>").attr("for", "pickup-entry-" + id)
347            .append($divRow)
348
349        return $("<li>").addClass("pickup-store-list-entry")
350            .append($rdioEl)
351            .append($lblEl);
352    },
353
354
355    refreshSwitchStoreColumn: function (data) {
356        data = $.parseJSON(data);
357        var $storeList = $('#colorbox .js-pickup-store-list');
358        $storeList.empty();
359
360        $("#colorbox .js-pickup-component").data("data", data);
361
362        $.each(data.results, function (index, pointOfService) {
363            $storeList.append(ACC.ufastoresoldtoswitch.createListItemHtml(pointOfService, index));
364        });
365        if($('.js-filter-switch-buy-online').is(':checked')){
366            $(".in-store-inventory-icon").each(function() {
367                $(this).closest(".pickup-store-list-entry").hide();
368            });
369        }
370        // select the first store
371        var firstInput = $("#colorbox .js-pickup-store-input")[0];
372        $(firstInput).click();
373
374
375        $("#colorbox .js-add-to-cart-for-pickup-popup, #colorbox .js-qty-selector-minus, #colorbox .js-qty-selector-input, #colorbox .js-qty-selector-plus").removeAttr("disabled");
376
377
378    },
379
380    spacingButtons: function(){
381        if($('.js-use-location-btn').is(":visible")){
382            $(".pickup-search-bar-switch-store").addClass("mb-3");
383        }else {
384            $(".pickup-search-bar-switch-store").removeClass("mb-3");
385        }
386    },
387
388    useLocationAction: function () {
389        var location = $('#colorbox #switchLocationSearchField').val();
390
391        if (navigator.permissions) {
392            navigator.permissions.query({name: 'geolocation'}).then(function (result) {
393                if (result.state == 'granted') {
394                    $('.js-use-location-btn').hide();
395                    navigator.geolocation.getCurrentPosition(
396                        function (position) {
397                            ACC.ufastoresoldtoswitch.locationSearchSubmit(location, position.coords.latitude, position.coords.longitude);
398                        },
399                        function (error) {
400                            ACC.ufastoresoldtoswitch.locationSearchSubmit(location, '', '');
401                        }
402                    );
403
404                    ACC.ufastoresoldtoswitch.spacingButtons();
405
406                } else if (result.state == 'prompt') {
407                    navigator.geolocation.getCurrentPosition(
408                        function (position) {
409                            ACC.ufastoresoldtoswitch.locationSearchSubmit(location, position.coords.latitude, position.coords.longitude);
410                        },
411                        function (error) {
412                            ACC.ufastoresoldtoswitch.locationSearchSubmit(location, '', '');
413                        }
414                    );
415
416                    ACC.ufastoresoldtoswitch.spacingButtons();
417                } else if (result.state == 'denied') {
418                    $('.js-use-location-btn').hide();
419                    $(".js-location-blocked-error").removeClass("hidden");
420                    ACC.ufastoresoldtoswitch.locationSearchSubmit(location, '', '');
421
422                    ACC.ufastoresoldtoswitch.spacingButtons();
423                }
424            });
425        } else {
426            navigator.geolocation.getCurrentPosition(
427                function (position) {
428                    ACC.ufastoresoldtoswitch.locationSearchSubmit(location, position.coords.latitude, position.coords.longitude);
429                },
430                function (error) {
431                    ACC.ufastoresoldtoswitch.locationSearchSubmit(location, '', '');
432                }
433            );
434
435            ACC.ufastoresoldtoswitch.spacingButtons();
436        }
437
438    },
439
440    bindClickPickupInStoreButton: function () {
441
442
443        $(document).on("click", ".js-store-switch-popup", function (e) {
444            e.preventDefault();
445
446            $("#radioSiteSelectAll").prop("checked", true);
447            var boxContent = $("#popup_store_switch_form > #switchModal").clone();
448            var titleHeader = "Set your location to show prices and availability";
449
450            ACC.colorbox.open(titleHeader, {
451                html: boxContent,
452                width: "960px",
453                onComplete: function () {
454
455                    boxContent.show();
456
457                    $("#colorbox input#colorbox #switchLocationSearchField").focus();
458                    ACC.ufastoresoldtoswitch.spacingButtons();
459                    navigator.geolocation.getCurrentPosition(
460                        function (position) {
461                            $('.js-use-location-btn').show();
462                            $(".js-location-blocked-error").addClass("hidden");
463                            ACC.ufastoresoldtoswitch.spacingButtons();
464                        },
465                        function (error) {
466                            $('.js-use-location-btn').hide();
467                            $(".js-location-blocked-error").removeClass("hidden");
468                            ACC.ufastoresoldtoswitch.spacingButtons();
469                        }
470                    );
471                    ACC.ufastoresoldtoswitch.locationSearchFinalSubmit("", '', '');
472                }
473
474            });
475
476        });
477    },
478
479    bindClickFilterOnline: function () {
480        $(document).on("click", ".js-filter-switch-buy-online", function () {
481            $(".in-store-inventory-icon").each(function() {
482                $(this).closest(".pickup-store-list-entry").hide();
483            });
484        });
485    },
486
487    bindClickFilterAll: function () {
488        $(document).on("click", ".js-filter-switch-all", function () {
489            $(".in-store-inventory-icon").each(function() {
490                $(this).closest(".pickup-store-list-entry").show();
491            });
492        });
493    },
494
495    onStoreSoldToSwitchSuccessful: function (data, selectedUid, $newlySelectedSoldTo, oldStoreName, newStoreName) {
496        if (data.redirectNeeded) {
497            if (window.location.search.toString().includes("q=") && oldStoreName) {
498                var regExp1 = new RegExp(oldStoreName + "#", 'g');
499                var newWindowLocation = window.location.pathname + window.location.search.toString().replace(regExp1, newStoreName + "#");
500                var regExp2 = new RegExp(oldStoreName + "%", 'g');
501                newWindowLocation = newWindowLocation.replace(regExp2, newStoreName + "%");
502                var regExp3 = new RegExp(oldStoreName + "&", 'g');
503                newWindowLocation = newWindowLocation.replace(regExp3, newStoreName + "&");
504                var regExp4 = new RegExp(oldStoreName, 'g');
505                newWindowLocation = newWindowLocation.replace(regExp4, newStoreName);
506                window.location = newWindowLocation;
507            } else {
508                window.location.reload();
509            }
510        }
511    },
512
513    bindStoreSoldToSwitch: function () {
514        $(document).on("click", ".js-storesoldtoswitch-link", function (e) {
515            e.preventDefault();
516            var $selectedItem = $(this);
517            if (!$selectedItem.parent().hasClass("selected") && $($(".js-mini-cart-count")[0]).text().match(/\d/g).join("") != 0) {
518                $(".js-confirm-switch-store-popup").attr('data-uid', $selectedItem.data('uid'));
519
520                ACC.colorbox.open("", {
521                    html: $('#storeConfirmSwitchPopup').html(),
522                    width: "520px",
523                    scrolling: false
524                });
525            } else if (!$selectedItem.parent().hasClass("selected") && $($(".js-mini-cart-count")[0]).text().match(/\d/g).join("") == 0) {
526                ACC.ufastoresoldtoswitch.ajaxStoreSwitch($selectedItem.data('uid'), $selectedItem);
527            }
528        });
529    },
530    storeSoldToSwitchContinue: function () {
531        $(document).on("click", ".js-storesoldtoswitch-continue", function (e) {
532            e.preventDefault();
533            ACC.ufastoresoldtoswitch.ajaxStoreSwitch($(this).data('uid'), $(this));
534        });
535
536        $(document).on("click", ".js-storesoldtoswitch-cancel", function () {
537            ACC.colorbox.close();
538        });
539    },
540
541    ajaxStoreSwitch: function (selection, $newlySelectedSoldTo) {
542        var oldStoreName = "";
543        var actionUrl = "/storesoldtoswitch/current-store";
544        $.get({
545            url: ACC.config.encodedContextPath + actionUrl,
546            success: function (response) {
547                if (response) {
548                    oldStoreName = "_" + response.name;
549                }
550            }
551        });
552        $.ajax({
553            url: ACC.config.encodedContextPath + '/storesoldtoswitch',
554            type: "POST",
555            data: {"uid": selection},
556            success: function (data) {
557                if (data.success) {
558                    var newStoreName = "";
559                    $.get({
560                        url: ACC.config.encodedContextPath + actionUrl,
561                        success: function (response) {
562                            if (response) {
563                                newStoreName = "_" + response.name;
564                                ACC.ufastoresoldtoswitch.onStoreSoldToSwitchSuccessful(data, selection, $newlySelectedSoldTo, oldStoreName, newStoreName);
565                            }
566                        }
567                    });
568                } else {
569                    ACC.ufastoresoldtoswitch.onStoreSoldToSwitchError(selection);
570                }
571            },
572            error: function (jqXHR, textStatus) {
573                //TODO: Add logs
574            }
575        });
576    }
577
578};

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.