1var inpostjsGeowidgetModal; 2let inpost_pl_is_ajax_get_point_running = false; 3 4function inpost_pl_get_shipping_method_js_mode() { 5 let data = {}; 6 let method = jQuery( 'input[name^="shipping_method"]:checked' ).val(); 7 let postfix = ''; 8 if ('undefined' == typeof method || null === method ) { 9 method = jQuery( 'input[name^="shipping_method"]' ).val(); 10 } 11 if (typeof method != 'undefined' && method !== null) { 12 if (method.indexOf( ':' ) > -1) { 13 let arr = method.split( ':' ); 14 method = arr[0]; 15 postfix = arr[1]; 16 } 17 } 18 data.method = method; 19 data.postfix = postfix; 20 21 return data; 22} 23 24function inpost_pl_select_point_callback_js_mode(point) { 25 26 let selected_point_data = ''; 27 let parcelMachineAddressDesc = ''; 28 let address_line1 = ''; 29 let address_line2 = ''; 30 31 let point_name = ''; 32 if ( 'name' in point ) { 33 point_name = point.name; 34 if (point_name.startsWith( "PL_" )) { 35 // Remove first 3 characters "PL_". 36 point_name = point_name.slice( 3 ); 37 } 38 } 39 40 if ( typeof point.location_description != 'undefined' && point.location_description !== null ) { 41 parcelMachineAddressDesc = point.location_description; 42 } 43 if ( typeof point.address.line1 != 'undefined' && point.address.line1 !== null ) { 44 address_line1 = point.address.line1; 45 } 46 if ( typeof point.address.line2 != 'undefined' && point.address.line2 !== null ) { 47 address_line2 = point.address.line2; 48 } 49 50 if ( point.location_description ) { 51 52 selected_point_data = '<div class="easypack_selected_point_data" id="easypack_selected_point_data" style="margin-bottom:15px">\n' 53 + '<div id="selected-parcel-machine-id">' + point_name + '</div>\n' 54 + '<span id="selected-parcel-machine-desc">' + address_line1 + '<br>' + address_line2 + '</span><br>' 55 + '<span id="selected-parcel-machine-desc1">(' + point.location_description + ')</span>' + 56 '<input type="hidden" id="parcel_machine_id"\n' + 57 'name="parcel_machine_id" class="parcel_machine_id" value="' + point_name + '"/>\n' + 58 '<input type="hidden" id="parcel_machine_desc"\n' + 59 'name="parcel_machine_desc" class="parcel_machine_desc" value="' + parcelMachineAddressDesc + '"/></div>\n'; 60 61 } else { 62 selected_point_data = '<div class="easypack_selected_point_data" id="easypack_selected_point_data" style="margin-bottom:15px">\n' 63 + '<div id="selected-parcel-machine-id">' + point_name + '</div>\n' 64 + '<span id="selected-parcel-machine-desc">' + point.address.line1 + '<br>' + address_line2 + '</span><br>' 65 '<input type="hidden" id="parcel_machine_id"\n' + 66 'name="parcel_machine_id" class="parcel_machine_id" value="' + point_name + '"/>\n' + 67 '<input type="hidden" id="parcel_machine_desc"\n' + 68 'name="parcel_machine_desc" class="parcel_machine_desc" value="' + parcelMachineAddressDesc + '"/></div>'; 69 } 70 71 jQuery( '#easypack_selected_point_data' ).each( 72 function (ind, elem) { 73 jQuery( elem ).remove(); 74 } 75 ); 76 77 jQuery( '.inpost_pl_additional_validation_field' ).each( 78 function (ind, elem) { 79 jQuery( elem ).remove(); 80 } 81 ); 82 83 jQuery( '#easypack_js_type_geowidget' ).after( selected_point_data ); 84 jQuery( "#easypack_js_type_geowidget" ).text( easypack_front_map.button_text2 ); 85 86 let point_address = address_line1 + '<br>' + address_line2; 87 88 let is_need_write_missed_locker = false; 89 let typ_page = jQuery( '#selected-parcel-locker-pl-id' ); 90 if ( typeof typ_page != 'undefined' && typ_page !== null ) { 91 if ( typ_page.length > 0 ) { 92 is_need_write_missed_locker = true; 93 jQuery( typ_page ).html( point_name ); 94 let typ_page_desc = jQuery( '#selected-parcel-machine-desc' ); 95 if (typeof typ_page_desc != 'undefined' && typ_page_desc !== null) { 96 jQuery( typ_page_desc ).html( selected_point_data ); 97 } 98 jQuery( '.hidden-inpost-pl-typ-data' ).css( 'display', 'block' ); 99 } 100 } 101 102 let EasyPackPointObject = { 'pointName': point_name, 'pointDesc': parcelMachineAddressDesc, 'visiblePointData': point_address }; 103 localStorage.setItem( 'EasyPackPointObject', JSON.stringify( EasyPackPointObject ) ); 104 105 // for some templates like Divi - add hidden fields for Inpost Parcel locker dynamically. 106 var form = document.getElementsByClassName( 'checkout woocommerce-checkout' )[0]; 107 var additionalInput1 = document.createElement( 'input' ); 108 additionalInput1.type = 'hidden'; 109 additionalInput1.name = 'parcel_machine_id'; 110 additionalInput1.value = point_name; 111 additionalInput1.classList.add( 'inpost_pl_additional_validation_field' ); 112 113 var additionalInput2 = document.createElement( 'input' ); 114 additionalInput2.type = 'hidden'; 115 additionalInput2.name = 'parcel_machine_desc'; 116 additionalInput2.value = parcelMachineAddressDesc; 117 additionalInput2.classList.add( 'inpost_pl_additional_validation_field' ); 118 119 if (form) { 120 form.appendChild( additionalInput1 ); 121 form.appendChild( additionalInput2 ); 122 } 123 124 inpostjsGeowidgetModal.close(); 125 126 if ( is_need_write_missed_locker ) { 127 128 let preloader_gif = easypack_front_map.preloader;
129 let preloader = '<span class="inpost-pl-typ-preloader"><img src="' + preloader_gif + '" alt="inpost-pl-typ-preloader"></span>'; 130 131 let data = { 132 action: 'update_locker_from_typ_page', 133 order_id: jQuery( '#inpost-pl-typ-map-data' ).attr( 'data-id' ), 134 inpost_pl_locker: point_name, 135 inpost_pl_locker_desc: parcelMachineAddressDesc, 136 security: easypack_front_map.security 137 }; 138 139 jQuery.ajax( 140 { 141 type: 'POST', 142 url: easypack_front_map.ajaxurl, 143 data: data, 144 dataType: 'json', 145 beforeSend: function () { 146 inpost_pl_is_ajax_get_point_running = true; 147 jQuery( '.inpost_pl_geowidget_related_preloader' ).css( 'display', 'flex' ); 148 jQuery( '.inpost_pl_locker_changed' ).each( 149 function (ind, elem) { 150 jQuery( elem ).remove(); 151 } 152 ); 153 jQuery( '.inpost-pl-related-point-btn' ).each( 154 function (ind, elem) { 155 jQuery( elem ).css( 'background', '#fff' ); 156 } 157 ); 158 }, 159 success: function (data, textStatus, jqXHR) { 160 console.log( 'inpost_pl_update_locker_from_map result:' ); 161 console.log( data ); 162 163 if ( 'success' in data ) { 164 if ( data.success ) { 165 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#26be22; font-weight: bold">' + easypack_front_map.updated_text + ': ' + point_name + '</div>' ); 166 } else { 167 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + easypack_front_map.error_text + '</div>' ); 168 } 169 170 } else { 171 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + easypack_front_map.error_text + '</div>' ); 172 } 173 }, 174 error: function (jqXHR, textStatus, errorThrown) { 175 console.log( 'inpost_pl_update_locker_from_map_error' ); 176 console.log( 'error: ' + jqXHR.status ); 177 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + easypack_front_map.error_text + '</div>' ); 178 return false; 179 }, 180 complete: function () { 181 console.log( 'Complete' ); 182 inpost_pl_is_ajax_get_point_running = false; 183 184 jQuery( '.inpost-pl-typ-preloader' ).each( 185 function (ind, elem) { 186 jQuery( elem ).remove(); 187 } 188 ); 189 jQuery( '.inpost_pl_geowidget_related_preloader' ).each( 190 function (ind, elem) { 191 jQuery( elem ).css( 'display', 'none' ); 192 } 193 ); 194 } 195 } 196 ); 197 198 } 199} 200 201function inpost_pl_js_set_locker_from_local_storage() { 202 let EasyPackPointObject = localStorage.getItem( 'EasyPackPointObject' ); 203 204 if (EasyPackPointObject !== null) { 205 let selected_point_data = ''; 206 let point, 207 visible_desc, 208 desc; 209 210 let pointData = JSON.parse( EasyPackPointObject ); 211 if (typeof pointData != 'undefined' && pointData !== null) { 212 if (typeof pointData.pointName != 'undefined' && pointData.pointName !== null) { 213 point = pointData.pointName; 214 } 215 if (typeof pointData.visiblePointData != 'undefined' && pointData.visiblePointData !== null) { 216 visible_desc = pointData.visiblePointData; 217 } 218 if (typeof pointData.pointDesc != 'undefined' && pointData.pointDesc !== null && typeof pointData.visiblePointData != 'undefined' && pointData.visiblePointData !== null) { 219 desc = pointData.pointDesc; 220 selected_point_data = '<div class="easypack_selected_point_data" id="easypack_selected_point_data" style="margin-bottom:15px">\n' 221 + '<div id="selected-parcel-machine-id">' + point + '</div>\n' 222 + '<span id="selected-parcel-machine-desc1">(' + visible_desc + ')</span>' + 223 '<input type="hidden" id="parcel_machine_id"\n' + 224 'name="parcel_machine_id" class="parcel_machine_id" value="' + point + '"/>\n' + 225 '<input type="hidden" id="parcel_machine_desc"\n' + 226 'name="parcel_machine_desc" class="parcel_machine_desc" value="' + pointData.pointDesc + '"/></div>\n'; 227 } else { 228 selected_point_data = '<div class="easypack_selected_point_data" id="easypack_selected_point_data" style="margin-bottom:15px">\n' 229 + '<div id="selected-parcel-machine-id">' + point + '</div>\n' 230 '<input type="hidden" id="parcel_machine_id"\n' + 231 'name="parcel_machine_id" class="parcel_machine_id" value="' + point + '"/>\n' + 232 '<input type="hidden" id="parcel_machine_desc"\n' + 233 'name="parcel_machine_desc" class="parcel_machine_desc" value="' + pointData.pointDesc + '"/></div>'; 234 } 235 236 jQuery( '#easypack_js_type_geowidget' ).after( selected_point_data ); 237 jQuery( "#easypack_js_type_geowidget" ).text( easypack_front_map.button_text2 ); 238 } 239 240 } 241} 242 243 244jQuery( document ).ready( 245 function () { 246 247 console.log( "Inpost PL: front_js" ); 248 249 // Prepare modal with map. 250 let token = easypack_front_map.geowidget_v5_token; 251 let shipping_data = inpost_pl_get_shipping_method_js_mode(); 252 let method = shipping_data.method; 253 let postfix = shipping_data.postfix; 254 let config = 'parcelCollect'; 255 256 if (typeof method != 'undefined' && method !== null) { 257 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 258 } 259 260 var wH = jQuery( window ).height() - 80; 261 262 inpostjsGeowidgetModal = new jBox( 263 'Modal', 264 { 265 width: 800, 266 height: wH, 267 attach: '#easypack_show_geowidget_modal', 268 title: 'Wybierz paczkomat', 269 content: '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>' 270 } 271 ); 272 273 if ( typeof method != 'undefined' && method !== null ) { 274 275 console.log( 'Inpost PL: ready' ); 276 console.log( method ); 277 278 let config = 'parcelCollect'; 279 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 280 281 let wH = jQuery( window ).height() - 80; 282 283 let map_content = '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>'; 284 inpostjsGeowidgetModal.setContent( map_content ); 285 286 let selector = method + ':' + postfix; 287 let shipping_option_input = null; 288 let li_parent = null; 289 290 console.log( "Inpost PL: shipping option input value" ); 291 console.log( selector ); 292 293 let shipping_options_block = jQuery( '#shipping_method' ); 294 if ( typeof shipping_options_block != 'undefined' && shipping_options_block !== null ) {
295 jQuery( shipping_options_block ).find( 'input' ).each( 296 function (index, input) { 297 if ( selector === jQuery( input ).val() ) { 298 shipping_option_input = input; 299 //console.log( "Inpost PL: shipping option input" ); 300 //console.log( shipping_option_input ); 301 } 302 } 303 ); 304 } 305 306 let map_button = '<div class="easypack_show_geowidget" id="easypack_js_type_geowidget">\n' + 307 easypack_front_map.button_text1 + '</div>'; 308 if ( shipping_option_input ) { 309 li_parent = jQuery( shipping_option_input ).closest( 'li' ); 310 //console.log( "Inpost PL: li_parent" ); 311 //console.log( li_parent ); 312 } 313 314 if ( method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 315 if ( typeof li_parent != 'undefined' && li_parent !== null ) { 316 jQuery( li_parent ).after( map_button ); 317 console.log( "Inpost PL: add map button" ); 318 inpost_pl_js_set_locker_from_local_storage(); 319 320 } 321 322 } else { 323 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 324 let linked_fs_method_data = inpost_methods[postfix]; 325 if ( typeof linked_fs_method_data != 'undefined' && linked_fs_method_data !== null ) { 326 let linked_fs_method = linked_fs_method_data.inpost_title; 327 if ( linked_fs_method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 328 if (typeof li_parent != 'undefined' && li_parent !== null) { 329 jQuery( li_parent ).after( map_button ); 330 inpost_pl_js_set_locker_from_local_storage(); 331 } 332 } 333 } 334 } 335 336 jQuery( '#easypack_js_type_geowidget' ).on( 337 'click', 338 function () {
339 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 340 if ( ! inpostjsGeowidgetModal.isOpen) { 341 console.log( 'inpost geowidget open jQuery' ); 342 inpostjsGeowidgetModal.open(); 343 } 344 } 345 } 346 ); 347 348 // open modal with map. 349 document.addEventListener( 350 'click', 351 function (e) { 352 e = e || window.event; 353 var target = e.target || e.srcElement; 354 355 if (target.hasAttribute( 'id' ) && target.getAttribute( 'id' ) === 'easypack_js_type_geowidget') { 356 e.preventDefault(); 357 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 358 if ( ! inpostjsGeowidgetModal.isOpen ) { 359 inpostjsGeowidgetModal.open(); 360 } 361 } 362 } 363 } 364 ); 365 } 366 367 jQuery( document.body ).on( 368 'update_checkout', 369 function () { 370 jQuery( '.easypack_show_geowidget' ).each( 371 function (ind, elem) { 372 jQuery( elem ).remove(); 373 } 374 ); 375 jQuery( '.easypack_selected_point_data' ).each( 376 function (ind, elem) { 377 jQuery( elem ).remove(); 378 } 379 ); 380 381 if ( typeof method != 'undefined' && method !== null ) { 382 383 console.log( 'Inpost PL: ready' ); 384 console.log( method ); 385 386 let config = 'parcelCollect'; 387 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 388 389 let wH = jQuery( window ).height() - 80; 390 391 let map_content = '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>'; 392 inpostjsGeowidgetModal.setContent( map_content ); 393 394 let selector = method + ':' + postfix; 395 let shipping_option_input = null; 396 let li_parent = null; 397 398 console.log( "Inpost PL: shipping option input value" ); 399 console.log( selector ); 400 401 let shipping_options_block = jQuery( '#shipping_method' ); 402 if ( typeof shipping_options_block != 'undefined' && shipping_options_block !== null ) { 403 jQuery( shipping_options_block ).find( 'input' ).each( 404 function (index, input) { 405 if ( selector === jQuery( input ).val() ) { 406 shipping_option_input = input; 407 console.log( "Inpost PL: shipping option input" ); 408 console.log( shipping_option_input ); 409 } 410 } 411 ); 412 } 413 414 let map_button = '<div class="easypack_show_geowidget" id="easypack_js_type_geowidget">\n' + 415 easypack_front_map.button_text1 + '</div>'; 416 if ( shipping_option_input ) { 417 li_parent = jQuery( shipping_option_input ).closest( 'li' ); 418 console.log( "Inpost PL: li_parent" ); 419 console.log( li_parent ); 420 } 421 422 if ( method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 423 if ( typeof li_parent != 'undefined' && li_parent !== null ) { 424 jQuery( li_parent ).after( map_button ); 425 inpost_pl_js_set_locker_from_local_storage(); 426 console.log( "Inpost PL: add map button" ); 427 } 428 429 } else { 430 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 431 let linked_fs_method_data = inpost_methods[postfix]; 432 if ( typeof linked_fs_method_data != 'undefined' && linked_fs_method_data !== null ) { 433 let linked_fs_method = linked_fs_method_data.inpost_title; 434 if ( linked_fs_method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 435 if (typeof li_parent != 'undefined' && li_parent !== null) { 436 jQuery( li_parent ).after( map_button ); 437 inpost_pl_js_set_locker_from_local_storage(); 438 } 439 } 440 } 441 } 442 443 jQuery( '#easypack_js_type_geowidget' ).on( 444 'click', 445 function () {
446 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 447 if ( ! inpostjsGeowidgetModal.isOpen) { 448 console.log( 'inpost geowidget open jQuery' ); 449 inpostjsGeowidgetModal.open(); 450 } 451 } 452 } 453 ); 454 455 // open modal with map. 456 document.addEventListener( 457 'click', 458 function (e) { 459 e = e || window.event; 460 var target = e.target || e.srcElement; 461 462 if (target.hasAttribute( 'id' ) && target.getAttribute( 'id' ) === 'easypack_js_type_geowidget') { 463 e.preventDefault(); 464 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 465 if ( ! inpostjsGeowidgetModal.isOpen ) { 466 inpostjsGeowidgetModal.open(); 467 } 468 } 469 } 470 } 471 ); 472 } 473 474 } 475 ); 476 477 jQuery( document.body ).on( 478 'updated_checkout', 479 function () { 480 481 let shipping_data = inpost_pl_get_shipping_method_js_mode(); 482 let method = shipping_data.method; 483 let postfix = shipping_data.postfix; 484 485 jQuery( '.easypack_show_geowidget' ).each( 486 function (ind, elem) { 487 jQuery( elem ).remove(); 488 } 489 ); 490 jQuery( '.easypack_selected_point_data' ).each( 491 function (ind, elem) { 492 jQuery( elem ).remove(); 493 } 494 ); 495 496 if ( typeof method != 'undefined' && method !== null ) { 497 let config = 'parcelCollect'; 498 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 499 500 let wH = jQuery( window ).height() - 80; 501 502 let map_content = '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>'; 503 inpostjsGeowidgetModal.setContent( map_content ); 504 505 let selector = method + ':' + postfix; 506 let shipping_option_input = null; 507 let li_parent = null; 508 console.log( "shipping option input value" ); 509 console.log( selector ); 510 511 let shipping_options_block = jQuery( '#shipping_method' ); 512 if ( typeof shipping_options_block != 'undefined' && shipping_options_block !== null ) { 513 jQuery( shipping_options_block ).find( 'input' ).each( 514 function (index, input) { 515 if ( selector === jQuery( input ).val() ) { 516 shipping_option_input = input; 517 } 518 } 519 ); 520 } 521 522 let map_button = '<div class="easypack_show_geowidget" id="easypack_js_type_geowidget">\n' + 523 easypack_front_map.button_text1 + '</div>'; 524 if ( shipping_option_input ) { 525 li_parent = jQuery( shipping_option_input ).closest( 'li' ); 526 } 527 528 if ( method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 529 if ( typeof li_parent != 'undefined' && li_parent !== null ) { 530 jQuery( li_parent ).after( map_button ); 531 inpost_pl_js_set_locker_from_local_storage(); 532 } 533 534 } else { 535 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 536 let linked_fs_method_data = inpost_methods[postfix]; 537 if ( typeof linked_fs_method_data != 'undefined' && linked_fs_method_data !== null ) { 538 let linked_fs_method = linked_fs_method_data.inpost_title; 539 if ( linked_fs_method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 540 if (typeof li_parent != 'undefined' && li_parent !== null) { 541 jQuery( li_parent ).after( map_button ); 542 inpost_pl_js_set_locker_from_local_storage(); 543 } 544 } 545 } 546 } 547 548 jQuery( '#easypack_js_type_geowidget' ).on( 549 'click', 550 function () {
551 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 552 if ( ! inpostjsGeowidgetModal.isOpen) { 553 console.log( 'inpost geowidget open jQuery' ); 554 inpostjsGeowidgetModal.open(); 555 } 556 } 557 } 558 ); 559 560 // open modal with map. 561 document.addEventListener( 562 'click', 563 function (e) { 564 e = e || window.event; 565 var target = e.target || e.srcElement; 566 567 if (target.hasAttribute( 'id' ) ) { 568 if (target.getAttribute( 'id' ) === 'easypack_js_type_geowidget') { 569 e.preventDefault(); 570 if (typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null) { 571 if ( ! inpostjsGeowidgetModal.isOpen) { 572 inpostjsGeowidgetModal.open(); 573 } 574 } 575 } 576 } 577 } 578 ); 579 580 } 581 } 582 ); 583 584 document.addEventListener( 585 'change', 586 function (e) { 587 e = e || window.event; 588 var target = e.target; 589 if (target.hasAttribute( 'name' )) { 590 if (target.getAttribute( 'name' ) === 'shipping_method[0]') { 591 localStorage.setItem( 'EasyPackPointObject', null ); 592 console.log( 'reset local storage value' ); 593 jQuery('input[name=parcel_machine_desc]').each( 594 function (ind, elem) { 595 jQuery(elem).val(''); 596 } 597 ); 598 jQuery('input[name=parcel_machine_id]').each( 599 function (ind, elem) { 600 jQuery(elem).val(''); 601 } 602 ); 603 jQuery('*[id*=selected-parcel-machine-id]').each( 604 function (ind, elem) { 605 jQuery(elem).html(''); 606 } 607 ); 608 } 609 } 610 } 611 ); 612 613 jQuery( document ).ready( 614 function () { 615 616 jQuery( '.inpost_pl_geowidget_typ' ).on( 617 'click', 618 function () {
619 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 620 if ( ! inpostjsGeowidgetModal.isOpen) { 621 console.log( 'inpost_pl_geowidget_typ open jQuery' ); 622 inpostjsGeowidgetModal.open(); 623 } 624 } 625 } 626 ); 627 628 document.addEventListener( 629 'click', 630 function (e) { 631 e = e || window.event; 632 var target = e.target || e.srcElement; 633 634 if ( target.classList.contains( 'inpost_pl_geowidget_typ' ) ) { 635 e.preventDefault(); 636 console.log( 'JS btn click' ); 637 if (typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null) { 638 if ( ! inpostjsGeowidgetModal.isOpen) { 639 inpostjsGeowidgetModal.open(); 640 } 641 } 642 } 643 } 644 ); 645 646 jQuery( '.inpost-pl-related-point-btn' ).click( 647 function (e) { 648 e.preventDefault(); 649 console.log( 'inpost-pl-related-point-btn' ); 650 651 let this_btn = jQuery( this ); 652 653 if ( inpost_pl_is_ajax_get_point_running ) { 654 console.log( 'AJAX already is running' ); 655 return false; 656 } 657 658 jQuery( '.inpost-pl-related-point-btn' ).each( 659 function (ind, elem) { 660 jQuery( elem ).css( 'background', '#fff' ); 661 } 662 ); 663 664 let nearest_point_selected = jQuery( this_btn ).attr( 'data-id' ); 665 666 let order_key = ''; 667 try { 668 let params = new URLSearchParams( window.location.search ); 669 order_key = params.get( 'key' ) || ''; 670 } catch (e) { 671 order_key = ''; 672 } 673 674 let data = { 675 action: 'update_locker_from_typ_page', 676 order_id: jQuery( '#inpost-pl-related-data-order' ).val(), 677 order_key: order_key, 678 inpost_pl_locker: nearest_point_selected, 679 inpost_pl_locker_desc: jQuery( this_btn ).attr( 'data-address-id' ), 680 security: easypack_front_map.security 681 }; 682 683 jQuery.ajax( 684 { 685 type: 'POST', 686 url: easypack_front_map.ajaxurl, 687 data: data, 688 dataType: 'json', 689 beforeSend: function () { 690 inpost_pl_is_ajax_get_point_running = true; 691 jQuery( '.hidden-inpost-pl-typ-data' ).css( 'display', 'none' ); 692 jQuery( this_btn ).find( '.inpost-pl-select-from-points-preloader' ).css( 'display', 'block' ); 693 jQuery( '.inpost_pl_locker_changed' ).each( 694 function (ind, elem) { 695 jQuery( elem ).remove(); 696 } 697 ); 698 }, 699 success: function (data, textStatus, jqXHR) { 700 console.log( 'inpost_pl_choose_locker_from_nearest result:' ); 701 console.log( data ); 702 703 if ( 'success' in data ) { 704 if ( data.success ) { 705 jQuery( this_btn ).css( 'background', '#afeaad' ); 706 jQuery( this_btn ).find( '.inpost-pl-related-locker-info' ).after( '<div class="inpost_pl_locker_changed" style="color:#26be22; font-weight: bold">' + easypack_front_map.updated_text + ': ' + nearest_point_selected + '</div>' ); 707 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#26be22; font-weight: bold">' + easypack_front_map.updated_text + ': ' + nearest_point_selected + '</div>' ); 708 } else { 709 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + easypack_front_map.error_text + '</div>' ); 710 } 711 712 } else { 713 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + easypack_front_map.error_text + '</div>' ); 714 } 715 }, 716 error: function (jqXHR, textStatus, errorThrown) { 717 console.log( 'inpost_pl_choose_locker_from_nearest_error' ); 718 console.log( 'error: ' + jqXHR.status ); 719 jQuery( '#inpost-pl-typ-map-data' ).before( '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + easypack_front_map.error_text + '</div>' ); 720 return false; 721 }, 722 complete: function () { 723 console.log( 'Complete' ); 724 inpost_pl_is_ajax_get_point_running = false;
725 726 jQuery( this_btn ).find( '.inpost-pl-select-from-points-preloader' ).css( 'display', 'none' ); 727 } 728 } 729 ); 730 } 731 ); 732 733 } 734 ); 735 736 } 737); 738 739 740function inpost_pl_js_get_map_config_based_on_instance_id(instance_id, method) { 741 let map_config = 'parcelCollect'; 742 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 743 744 if (instance_id !== undefined && instance_id !== null && instance_id !== '') { 745 let selected_method = inpost_methods[instance_id]; 746 if (typeof selected_method != 'undefined' && selected_method !== null) { 747 let method_id = selected_method.inpost_title; 748 if (method_id === 'easypack_parcel_machines_cod') { 749 map_config = 'parcelCollectPayment'; 750 } 751 if (method_id === 'easypack_shipping_courier_c2c') { 752 map_config = 'parcelSend'; 753 } 754 if (method_id === 'easypack_parcel_machines_weekend' || method_id === 'easypack_parcel_machines_weekend_cod') { 755 map_config = 'parcelCollect247'; 756 } 757 } 758 759 } else { 760 if (method === 'easypack_parcel_machines_cod') { 761 map_config = 'parcelCollectPayment'; 762 } 763 if (method === 'easypack_shipping_courier_c2c') { 764 map_config = 'parcelSend'; 765 } 766 if (method === 'easypack_parcel_machines_weekend' || method === 'easypack_parcel_machines_weekend_cod') { 767 map_config = 'parcelCollect247'; 768 } 769 } 770 771 return map_config; 772} 773 774function inpost_pl_js_get_configured_inpost_methods() { 775 if (typeof window.easypack_front_map != 'undefined' && window.easypack_front_map !== null) { 776 if ( window.easypack_front_map.inpost_methods ) { 777 return window.easypack_front_map.inpost_methods; 778 } 779 } 780 return []; 781}
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.