1/** 2 * @file 3 * Attaches pricespider buy now button functionality. 4 */ 5 6 (function ($) { 7 8 'use strict'; 9 10 Drupal.behaviors.sbd_price_spider = { 11 attach: function (context, settings) { 12 var locationServiceProvider = drupalSettings.location_services; 13 var buynow_pricespider = drupalSettings.buynow_pricespider; 14 var locationServiceUrl = drupalSettings.location_service_url; 15 var searchCategoryPage = drupalSettings.search_category_page; 16 17 if (locationServiceProvider == '') { 18 if (buynow_pricespider == '1') { 19 locationServiceProvider = 'pricespider'; 20 } 21 if (buynow_pricespider== '2') { 22 locationServiceProvider = 'customlocations'; 23 } 24 } 25 26 $(document).once().on('click', '.ps-wheretobuy-button', function(e) { 27 window.open(locationServiceUrl, '_blank'); 28 }); 29 30 // Open PS modal on PDP and search, category pages. 31 $(document).on('click', '.ps-buy-button', function (e) { 32 var skuId = $(this).attr('data-sku'); 33 let psModalDiv = $(".ps-container-pdp"); 34 if (searchCategoryPage == 1) { 35 psModalDiv = $(".ps-search-category-modal"); 36 } 37 // Check for PDP, search and category pages. 38 if ($(psModalDiv)[0]) { 39 $(psModalDiv).children(".ps-widget-container-area").addClass('ps-widget'); 40 $(psModalDiv).children(".ps-widget").removeAttr("ps-sku"); 41 $(psModalDiv).children(".ps-widget").attr('ps-sku', skuId); 42 } 43 var attr = $(psModalDiv).children(".ps-widget").attr('ps-sku'); 44 // For some browsers, `attr` is undefined; for others, 45 // `attr` is false. Check for both. 46 if (typeof attr !== 'undefined' && attr !== false) { 47 PriceSpider.rebind(); 48 } 49 // Add body class to prevent scrolling 50 // $('body').addClass('buy-now-modal-open'); 51 $(this).blur(); 52 var $modal; 53 // $modal = $button.siblings('.ps-container'); 54 if ($(psModalDiv)[0]) { 55 $modal = $(psModalDiv); 56 } 57 if (locationServiceProvider == 'customlocations') { 58 window.location.href = locationServiceUrl; 59 } 60 else { 61 // For PDP, search and category. 62 if ($(psModalDiv)[0]) { 63 if ($(".ps-container").css('display') == 'none') { 64 $(".ps-container").css("display", "block"); 65 } 66 } 67 var originalContent; 68 var wWidth = $(window).width(); 69 var dWidth = wWidth * 0.8; 70 $modal.dialog({ 71 width: dWidth, 72 modal: true, 73 bgiframe: true, 74 resizable: false, 75 height: 'auto', 76 fluid: true, 77 closeOnEscape: true, 78 position: { my: "center", at: "center", of: window }, 79 open: function (event, ui) { 80 originalContent = $modal.html(); 81 $('.ui-widget-overlay').on('click', function () { 82 $('.ui-dialog-content').dialog('close'); 83 $('body').removeClass('buy-now-modal-open'); 84 }); 85 }, 86 close: function (event, ui) { 87 $modal.html(originalContent); 88 }, 89 }); 90 } 91 }); 92 93 // Remove body class to allow scrolling 94 $(document).on('click', 'button.ui-dialog-titlebar-close', function() { 95 $('body').removeClass('buy-now-modal-open'); 96 }); 97 98 $(document).keyup(function(e) { 99 if (e.key === "Escape") { // escape key maps to keycode `27` 100 $('body').removeClass('buy-now-modal-open'); 101 } 102 }); 103 104 // Remove body class to allow scrolling 105 $(document).on('click', 'ui-widget-overlay', function() { 106 $('body').removeClass('buy-now-modal-open'); 107 }); 108 109 // on window resize run function 110 $(window).resize(function () { 111 fluidDialog(); 112 }); 113 114 // catch dialog if opened within a viewport smaller than the dialog width 115 $(document).on("dialogopen", ".ui-dialog", function (event, ui) { 116 fluidDialog(); 117 }); 118 119 function fluidDialog() { 120 var $visible = $(".ui-dialog:visible"); 121 // each open dialog 122 $visible.each(function () { 123 var $this = $(this); 124 var dialog = $this.find(".ui-dialog-content").data("ui-dialog"); 125 // if fluid option == true 126 if (dialog.options.fluid) { 127 var wWidth = $(window).width(); 128 // check window width against dialog width 129 if (wWidth < (parseInt(dialog.options.maxWidth) + 50)) { 130 // keep dialog from filling entire screen 131 $this.css("max-width", "90%"); 132 } else { 133 // fix maxWidth bug 134 $this.css("max-width", dialog.options.maxWidth + "px"); 135 } 136 //reposition dialog 137 dialog.option("position", dialog.options.position); 138 } 139 }); 140 } 141 } 142 }; 143 144})(jQuery);
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.