1// non-blocking AJAX loading, speeds up page load 2$.getScript("https://widget.packeta.com/v6/www/js/library.js") 3 .fail(function() { 4 console.error('Unable to load Packeta Widget.'); 5 }); 6 7var country = 'cz,sk'; /* Default countries */ 8 9function PacketeryCheckoutModulesManager() { 10 // ids correspond to parts of class names in checkout-module/*.js - first letter in upper case 11 this.supportedModules = ['Standard', 'Unknown', 'Supercheckout']; 12 this.loadedModules = []; 13 this.detectedModule = null; 14 15 this.loadModules = function() { 16 this.loadedModules = []; 17 var manager = this; 18 19 this.supportedModules.forEach(function (moduleId) { 20 // moduleId = 'Standard' => className = 'PacketeryCheckoutModuleStandard' 21 var className = 'PacketeryCheckoutModule' + moduleId; 22 23 // if really loaded via hookDisplayHeader() 24 if (typeof window[className] !== 'undefined') { 25 manager.loadedModules.push(window[className]); 26 } 27 }); 28 }; 29 30 this.detectModule = function () { 31 if (this.detectedModule !== null) { 32 return this.detectedModule; 33 } 34 35 if (this.loadedModules.length === 0) { 36 this.loadModules(); 37 } 38 39 var manager = this; 40 this.loadedModules.forEach(function (module) { 41 if ((manager.detectedModule === null) && module.findDeliveryOptions().length) { 42 manager.detectedModule = module; 43 } 44 }); 45 46 return this.detectedModule; 47 }; 48 49 // in case we need to change this in the future 50 this.getCarrierId = function ($selectedInput) { 51 return $selectedInput.val().replace(',', ''); 52 } 53 54 this.getWidgetParent = function ($selectedInput) { 55 return $('#packetery-carrier-' + this.getCarrierId($selectedInput)); 56 } 57} 58var packeteryModulesManager = new PacketeryCheckoutModulesManager(); 59var widgetInitialized = false; 60var $selectedInput; 61 62$(document).ready(function () { 63 if ($('.zas-box').length) { 64 onShippingLoadedCallback(); 65 widgetInitialized = true; 66 } 67}); 68 69$(window).load(function () { 70 if ($('.zas-box').length && widgetInitialized === false) { 71 onShippingLoadedCallback(); 72 widgetInitialized = true; 73 } 74}); 75 76window.initializePacketaWidget = function () 77{ 78 // set YOUR Packeta API key 79 var packetaApiKey = $("#packeta-api-key").val(); 80 81 // no Packetery carrier enabled 82 if (typeof packetaApiKey === 'undefined') { 83 return; 84 } 85 86 // parameters common to all carriers 87 var customerCountry = $('#customerCountry').val(); 88 if (customerCountry !== '') { 89 country = customerCountry; 90 } 91 var language = 'en'; 92 var shopLanguage = $('#shop-language').val(); 93 if (shopLanguage !== '') { 94 language = shopLanguage; 95 } 96 var app_identity = $('#app_identity').val(); // Get module version for widgets 97 98 var module = packeteryModulesManager.detectModule(); 99 $selectedInput = module.getSelectedInput(); 100 if ($selectedInput.length === 0) { 101 $(module.getExtraContentSelector()).hide(); 102 return; 103 } 104 105 $('.open-packeta-widget').click(function (e) { 106 e.preventDefault(); 107 var widgetOptions = { 108 appIdentity: app_identity, 109 country: country, 110 language: language, 111 }; 112 var $widgetParent = packeteryModulesManager.getWidgetParent($selectedInput); 113 var widgetCarriers = $widgetParent.find('#widget_carriers').val(); 114 if (widgetCarriers !== '') { 115 widgetOptions.carriers = widgetCarriers; 116 } 117 Packeta.Widget.pick(packetaApiKey, function (pickupPoint) 118 { 119 var $selectedDeliveryOption = module.getSelectedInput(); 120 $widgetParent = packeteryModulesManager.getWidgetParent($selectedDeliveryOption); 121 122 if (pickupPoint != null) 123 { 124 /* Save needed pickup point attributes to inputs */ 125 $widgetParent.find('.packeta-branch-id').val(pickupPoint.id); 126 $widgetParent.find('.packeta-branch-name').val(pickupPoint.name); 127 $widgetParent.find('.packeta-branch-currency').val(pickupPoint.currency); 128 $widgetParent.find('.packeta-pickup-point-type').val(pickupPoint.pickupPointType); 129 $widgetParent.find('.packeta-carrier-id').val(pickupPoint.carrierId); 130 $widgetParent.find('.packeta-carrier-pickup-point-id').val(pickupPoint.carrierPickupPointId); 131 132 // We let customer know, which branch he picked by filling html inputs 133 $widgetParent.find('.picked-delivery-place').html(pickupPoint.name); 134 135 module.enableSubmitButton(); 136 137 /* Get ID of selected carrier */ 138 var prestashopCarrierId = packeteryModulesManager.getCarrierId($selectedDeliveryOption); 139 140 /* Save packetery order without order ID - just cart id so we can access carrier data later */ 141 packetery.widgetSaveOrderBranch( 142 prestashopCarrierId, 143 pickupPoint.id, 144 pickupPoint.name, 145 pickupPoint.pickupPointType, 146 pickupPoint.carrierId, 147 pickupPoint.carrierPickupPointId, 148 pickupPoint.currency 149 ); 150 151 if (module !== null) { 152 module.hideValidationErrors(); 153 } 154 } 155 else 156 { 157 /* If point isn't selected - disable */ 158 if($widgetParent.find('.packeta-branch-id').val() === "") { 159 module.disableSubmitButton(); 160 } 161 } 162 }, widgetOptions); 163 }); 164 165 $('.open-packeta-widget-hd').click(function (e) { 166 e.preventDefault(); 167 var $widgetParent = packeteryModulesManager.getWidgetParent($selectedInput); 168 var widgetCarriers = $widgetParent.find('#widget_carriers').val(); 169 var customerStreet = $widgetParent.find('#customerStreet').val(); 170 var customerHouseNumber = $widgetParent.find('#customerHouseNumber').val(); 171 var customerCity = $widgetParent.find('#customerCity').val(); 172 var customerZip = $widgetParent.find('#customerZip').val(); 173 var widgetOptions = { 174 layout: 'hd', 175 language: language, 176 country: country, 177 // in this case, there will always be one carrier
178 carrierId: widgetCarriers, 179 }; 180 if (customerStreet) { 181 widgetOptions.street = customerStreet; 182 } 183 if (customerHouseNumber) { 184 widgetOptions.houseNumber = customerHouseNumber; 185 } 186 if (customerCity) { 187 widgetOptions.city = customerCity; 188 } 189 if (customerZip) { 190 widgetOptions.postCode = customerZip; 191 } 192 Packeta.Widget.pick(packetaApiKey, function (result) { 193 var $selectedDeliveryOption = module.getSelectedInput(); 194 $widgetParent = packeteryModulesManager.getWidgetParent($selectedDeliveryOption); 195 196 if (result != null && result.address != null) { 197 // there is also property packetaWidgetMessage which is true 198 var address = result.address; 199 var $addressValidationResult = $widgetParent.find('.address-validation-result'); 200 if (address.country === country) { 201 packetery.widgetSaveOrderAddress(address); 202 $widgetParent.find('#addressValidated').val(true); 203 $addressValidationResult.addClass('address-validated'); 204 $addressValidationResult.text($widgetParent.find('#addressValidatedMessage').val()); 205 $widgetParent.find('.picked-delivery-place').html( 206 address.street + ' ' + address.houseNumber + ', ' + address.city + ', ' + address.postcode 207 ); 208 module.enableSubmitButton(); 209 } else { 210 $widgetParent.find('#addressValidated').val(false); 211 $addressValidationResult.removeClass('address-validated'); 212 $addressValidationResult.text($widgetParent.find('#countryDiffersMessage').val()); 213 if (PacketaModule.ui.isAddressValidationUnsatisfied($widgetParent)) { 214 module.disableSubmitButton(); 215 } 216 } 217 } 218 }, widgetOptions); 219 }); 220}; 221 222PacketaModule = window.PacketaModule || {}; 223 224PacketaModule.ui = { 225 isHdCarrier: function ($widgetParent) { 226 return !!$widgetParent.find('#open-packeta-widget-hd').length; 227 }, 228 229 isPpCarrier: function ($widgetParent) { 230 return !!$widgetParent.find('#open-packeta-widget').length; 231 }, 232 233 isPickupPointInvalid: function ($widgetParent) { 234 var selectedBranchId = $widgetParent.find('.packeta-branch-id').val(); 235 return this.isPpCarrier($widgetParent) && !selectedBranchId; 236 }, 237 238 isAddressValidationUnsatisfied: function ($widgetParent) { 239 var addressValidated = PacketaModule.ui.makeBoolean($widgetParent.find('#addressValidated').val()); 240 var addressValidationSetting = $('#addressValidationSetting').val(); 241 return (this.isHdCarrier($widgetParent) && addressValidationSetting === 'required' && !addressValidated); 242 }, 243 244 makeBoolean: function (value) { 245 if (value === 'false') { 246 return false; 247 } 248 return !!value; 249 } 250}; 251 252tools = { 253 fixextracontent: function () 254 { 255 var module = packeteryModulesManager.detectModule(); 256 257 if (module === null) { 258 return; 259 } 260 261 $(module.getExtraContentSelector()).each(function () 262 { 263 var $extra = $(this); 264 if (!$extra.find('#open-packeta-widget').length && !$extra.find('#open-packeta-widget-hd').length) { 265 return; 266 } 267 268 if ($extra.find('#open-packeta-widget').length) { 269 var carrierId = parseInt($extra.find('#carrier_id').val()); 270 var zpointCarriers = $extra.find('#zpoint_carriers').val(); 271 zpointCarriers = JSON.parse(zpointCarriers); 272 if (!zpointCarriers.includes(carrierId)) { 273 $extra.find('#open-packeta-widget').hide(); 274 $extra.find('#selected-branch').hide(); 275 } 276 277 /* Only displayed extra content */ 278 if ($extra.is(':visible')) { 279 /* And branch is not set, disable */ 280 var id_branch = $extra.find(".packeta-branch-id").val(); 281 if (id_branch <= 0) { 282 module.disableSubmitButton(); 283 } 284 } 285 } 286 if ($extra.is(':visible') && 287 $extra.find('#open-packeta-widget-hd').length && 288 PacketaModule.ui.isAddressValidationUnsatisfied($extra) 289 ) { 290 module.disableSubmitButton(); 291 } 292 }); 293 294 /* Enable / Disable continue buttons after carrier change */ 295
296 var $deliveryInputs = module.findDeliveryOptions(); 297 $deliveryInputs.change(function () 298 { 299 var 300 $this = $(this), 301 prestashop_carrier_id = packeteryModulesManager.getCarrierId($this), 302 $extra = packeteryModulesManager.getWidgetParent($this); 303 304 // if selected carrier has no Packeta widget then enable Continue button and we're done here 305 if (!$extra.find('#open-packeta-widget').length && !$extra.find('#open-packeta-widget-hd').length) { 306 module.enableSubmitButton(); 307 return; 308 } 309 310 if ($this.is(':checked')) { 311 $selectedInput = $this; 312 var $wrapper = $extra.closest(module.getExtraContentSelector()); 313 setTimeout(function () { 314 if ($wrapper.is(':hidden')) { 315 $wrapper.show(); 316 } 317 }, 700); 318 } 319 320 if ($extra.find('#open-packeta-widget').length) { 321 var id_branch = $extra.find(".packeta-branch-id").val(); 322 if (id_branch !== '') { 323 var name_branch = $extra.find(".packeta-branch-name").val(); 324 var currency_branch = $extra.find(".packeta-branch-currency").val(); 325 var pickup_point_type = $extra.find(".packeta-pickup-point-type").val(); 326 var widget_carrier_id = $extra.find(".packeta-carrier-id").val(); 327 var carrier_pickup_point_id = $extra.find(".packeta-carrier-pickup-point-id").val(); 328 module.enableSubmitButton(); 329 packetery.widgetSaveOrderBranch(prestashop_carrier_id, id_branch, name_branch, pickup_point_type, widget_carrier_id, carrier_pickup_point_id, currency_branch); 330 } else { 331 module.disableSubmitButton(); 332 } 333 } 334 if ($extra.find('#open-packeta-widget-hd').length) { 335 if (PacketaModule.ui.isAddressValidationUnsatisfied($extra)) { 336 module.disableSubmitButton(); 337 } else { 338 module.enableSubmitButton(); 339 } 340 } 341 }); 342 } 343} 344 345packetery = { 346 widgetSaveOrderBranch: function (prestashop_carrier_id, id_branch, name_branch, pickup_point_type, widget_carrier_id, carrier_pickup_point_id, currency_branch) 347 { 348 $.ajax({ 349 type: 'POST', 350 url: ajaxs.baseuri() + '/modules/packetery/ajax_front.php?action=widgetsaveorderbranch' + ajaxs.checkToken(), 351 data: { 352 'prestashop_carrier_id': prestashop_carrier_id, 353 'id_branch': id_branch, 354 'name_branch': name_branch, 355 'currency_branch': currency_branch, 356 'pickup_point_type': pickup_point_type, 357 'widget_carrier_id': widget_carrier_id, 358 'carrier_pickup_point_id': carrier_pickup_point_id 359 }, 360 beforeSend: function () { 361 $("body").toggleClass("wait"); 362 }, 363 success: function (msg) { 364 return true; 365 }, 366 complete: function () { 367 $("body").toggleClass("wait"); 368 }, 369 }); 370 }, 371 widgetSaveOrderAddress: function (address) { 372 $.ajax({ 373 type: 'POST', 374 url: ajaxs.baseuri() + '/modules/packetery/ajax_front.php?action=widgetSaveOrderAddress' + ajaxs.checkToken(), 375 data: { 376 'address': address 377 }, 378 beforeSend: function () { 379 $("body").toggleClass("wait"); 380 }, 381 complete: function () { 382 $("body").toggleClass("wait"); 383 } 384 }); 385 } 386} 387 388ajaxs = { 389 baseuri: function () 390 { 391 return $('#baseuri').val(); 392 }, 393 checkToken: function () 394 { 395 return '&token=' + prestashop.static_token; 396 }, 397} 398 399 400function onShippingLoadedCallback() { 401 initializePacketaWidget(); 402 tools.fixextracontent(); 403}
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.