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 window.EasypackGeowidgetModalA11y.getOptions( 265 { 266 width: 800, 267 height: wH, 268 attach: '#easypack_show_geowidget_modal', 269 title: 'Wybierz paczkomat', 270 content: '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>' 271 } 272 ) 273 ); 274 275 if ( typeof method != 'undefined' && method !== null ) { 276 277 console.log( 'Inpost PL: ready' ); 278 console.log( method ); 279 280 let config = 'parcelCollect'; 281 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 282 283 let wH = jQuery( window ).height() - 80; 284 285 let map_content = '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>'; 286 inpostjsGeowidgetModal.setContent( map_content ); 287 288 let selector = method + ':' + postfix; 289 let shipping_option_input = null; 290 let li_parent = null; 291 292 console.log( "Inpost PL: shipping option input value" ); 293 console.log( selector ); 294 295 let shipping_options_block = jQuery( '#shipping_method' ); 296 if ( typeof shipping_options_block != 'undefined' && shipping_options_block !== null ) {
297 jQuery( shipping_options_block ).find( 'input' ).each( 298 function (index, input) { 299 if ( selector === jQuery( input ).val() ) { 300 shipping_option_input = input; 301 //console.log( "Inpost PL: shipping option input" ); 302 //console.log( shipping_option_input ); 303 } 304 } 305 ); 306 } 307 308 let map_button = '<div class="easypack_show_geowidget" id="easypack_js_type_geowidget">\n' + 309 easypack_front_map.button_text1 + '</div>'; 310 if ( shipping_option_input ) { 311 li_parent = jQuery( shipping_option_input ).closest( 'li' ); 312 //console.log( "Inpost PL: li_parent" ); 313 //console.log( li_parent ); 314 } 315 316 if ( method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 317 if ( typeof li_parent != 'undefined' && li_parent !== null ) { 318 jQuery( li_parent ).after( map_button ); 319 console.log( "Inpost PL: add map button" ); 320 inpost_pl_js_set_locker_from_local_storage(); 321 322 } 323 324 } else { 325 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 326 let linked_fs_method_data = inpost_methods[postfix]; 327 if ( typeof linked_fs_method_data != 'undefined' && linked_fs_method_data !== null ) { 328 let linked_fs_method = linked_fs_method_data.inpost_title; 329 if ( linked_fs_method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 330 if (typeof li_parent != 'undefined' && li_parent !== null) { 331 jQuery( li_parent ).after( map_button ); 332 inpost_pl_js_set_locker_from_local_storage(); 333 } 334 } 335 } 336 } 337 338 jQuery( '#easypack_js_type_geowidget' ).on( 339 'click', 340 function () {
341 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 342 if ( ! inpostjsGeowidgetModal.isOpen) { 343 console.log( 'inpost geowidget open jQuery' ); 344 inpostjsGeowidgetModal.open(); 345 } 346 } 347 } 348 ); 349 350 // open modal with map. 351 document.addEventListener( 352 'click', 353 function (e) { 354 e = e || window.event; 355 var target = e.target || e.srcElement; 356 357 if (target.hasAttribute( 'id' ) && target.getAttribute( 'id' ) === 'easypack_js_type_geowidget') { 358 e.preventDefault(); 359 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 360 if ( ! inpostjsGeowidgetModal.isOpen ) { 361 inpostjsGeowidgetModal.open(); 362 } 363 } 364 } 365 } 366 ); 367 } 368 369 jQuery( document.body ).on( 370 'update_checkout', 371 function () { 372 jQuery( '.easypack_show_geowidget' ).each( 373 function (ind, elem) { 374 jQuery( elem ).remove(); 375 } 376 ); 377 jQuery( '.easypack_selected_point_data' ).each( 378 function (ind, elem) { 379 jQuery( elem ).remove(); 380 } 381 ); 382 383 if ( typeof method != 'undefined' && method !== null ) { 384 385 console.log( 'Inpost PL: ready' ); 386 console.log( method ); 387 388 let config = 'parcelCollect'; 389 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 390 391 let wH = jQuery( window ).height() - 80; 392 393 let map_content = '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>'; 394 inpostjsGeowidgetModal.setContent( map_content ); 395 396 let selector = method + ':' + postfix; 397 let shipping_option_input = null; 398 let li_parent = null; 399 400 console.log( "Inpost PL: shipping option input value" ); 401 console.log( selector ); 402 403 let shipping_options_block = jQuery( '#shipping_method' ); 404 if ( typeof shipping_options_block != 'undefined' && shipping_options_block !== null ) { 405 jQuery( shipping_options_block ).find( 'input' ).each( 406 function (index, input) { 407 if ( selector === jQuery( input ).val() ) { 408 shipping_option_input = input; 409 console.log( "Inpost PL: shipping option input" ); 410 console.log( shipping_option_input ); 411 } 412 } 413 ); 414 } 415 416 let map_button = '<div class="easypack_show_geowidget" id="easypack_js_type_geowidget">\n' + 417 easypack_front_map.button_text1 + '</div>'; 418 if ( shipping_option_input ) { 419 li_parent = jQuery( shipping_option_input ).closest( 'li' ); 420 console.log( "Inpost PL: li_parent" ); 421 console.log( li_parent ); 422 } 423 424 if ( method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 425 if ( typeof li_parent != 'undefined' && li_parent !== null ) { 426 jQuery( li_parent ).after( map_button ); 427 inpost_pl_js_set_locker_from_local_storage(); 428 console.log( "Inpost PL: add map button" ); 429 } 430 431 } else { 432 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 433 let linked_fs_method_data = inpost_methods[postfix]; 434 if ( typeof linked_fs_method_data != 'undefined' && linked_fs_method_data !== null ) { 435 let linked_fs_method = linked_fs_method_data.inpost_title; 436 if ( linked_fs_method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 437 if (typeof li_parent != 'undefined' && li_parent !== null) { 438 jQuery( li_parent ).after( map_button ); 439 inpost_pl_js_set_locker_from_local_storage(); 440 } 441 } 442 } 443 } 444 445 jQuery( '#easypack_js_type_geowidget' ).on( 446 'click', 447 function () {
448 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 449 if ( ! inpostjsGeowidgetModal.isOpen) { 450 console.log( 'inpost geowidget open jQuery' ); 451 inpostjsGeowidgetModal.open(); 452 } 453 } 454 } 455 ); 456 457 // open modal with map. 458 document.addEventListener( 459 'click', 460 function (e) { 461 e = e || window.event; 462 var target = e.target || e.srcElement; 463 464 if (target.hasAttribute( 'id' ) && target.getAttribute( 'id' ) === 'easypack_js_type_geowidget') { 465 e.preventDefault(); 466 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 467 if ( ! inpostjsGeowidgetModal.isOpen ) { 468 inpostjsGeowidgetModal.open(); 469 } 470 } 471 } 472 } 473 ); 474 } 475 476 } 477 ); 478 479 jQuery( document.body ).on( 480 'updated_checkout', 481 function () { 482 483 let shipping_data = inpost_pl_get_shipping_method_js_mode(); 484 let method = shipping_data.method; 485 let postfix = shipping_data.postfix; 486 487 jQuery( '.easypack_show_geowidget' ).each( 488 function (ind, elem) { 489 jQuery( elem ).remove(); 490 } 491 ); 492 jQuery( '.easypack_selected_point_data' ).each( 493 function (ind, elem) { 494 jQuery( elem ).remove(); 495 } 496 ); 497 498 if ( typeof method != 'undefined' && method !== null ) { 499 let config = 'parcelCollect'; 500 config = inpost_pl_js_get_map_config_based_on_instance_id( postfix, method ); 501 502 let wH = jQuery( window ).height() - 80; 503 504 let map_content = '<inpost-geowidget id="inpost-geowidget" onpoint="inpost_pl_select_point_callback_js_mode" token="' + token + '" language="pl" config="' + config + '"></inpost-geowidget>'; 505 inpostjsGeowidgetModal.setContent( map_content ); 506 507 let selector = method + ':' + postfix; 508 let shipping_option_input = null; 509 let li_parent = null; 510 console.log( "shipping option input value" ); 511 console.log( selector ); 512 513 let shipping_options_block = jQuery( '#shipping_method' ); 514 if ( typeof shipping_options_block != 'undefined' && shipping_options_block !== null ) { 515 jQuery( shipping_options_block ).find( 'input' ).each( 516 function (index, input) { 517 if ( selector === jQuery( input ).val() ) { 518 shipping_option_input = input; 519 } 520 } 521 ); 522 } 523 524 let map_button = '<div class="easypack_show_geowidget" id="easypack_js_type_geowidget">\n' + 525 easypack_front_map.button_text1 + '</div>'; 526 if ( shipping_option_input ) { 527 li_parent = jQuery( shipping_option_input ).closest( 'li' ); 528 } 529 530 if ( method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 531 if ( typeof li_parent != 'undefined' && li_parent !== null ) { 532 jQuery( li_parent ).after( map_button ); 533 inpost_pl_js_set_locker_from_local_storage(); 534 } 535 536 } else { 537 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 538 let linked_fs_method_data = inpost_methods[postfix]; 539 if ( typeof linked_fs_method_data != 'undefined' && linked_fs_method_data !== null ) { 540 let linked_fs_method = linked_fs_method_data.inpost_title; 541 if ( linked_fs_method.indexOf( 'easypack_parcel_machines' ) !== -1 ) { 542 if (typeof li_parent != 'undefined' && li_parent !== null) { 543 jQuery( li_parent ).after( map_button ); 544 inpost_pl_js_set_locker_from_local_storage(); 545 } 546 } 547 } 548 } 549 550 jQuery( '#easypack_js_type_geowidget' ).on( 551 'click', 552 function () {
553 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 554 if ( ! inpostjsGeowidgetModal.isOpen) { 555 console.log( 'inpost geowidget open jQuery' ); 556 inpostjsGeowidgetModal.open(); 557 } 558 } 559 } 560 ); 561 562 // open modal with map. 563 document.addEventListener( 564 'click', 565 function (e) { 566 e = e || window.event; 567 var target = e.target || e.srcElement; 568 569 if (target.hasAttribute( 'id' ) ) { 570 if (target.getAttribute( 'id' ) === 'easypack_js_type_geowidget') { 571 e.preventDefault(); 572 if (typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null) { 573 if ( ! inpostjsGeowidgetModal.isOpen) { 574 inpostjsGeowidgetModal.open(); 575 } 576 } 577 } 578 } 579 } 580 ); 581 582 } 583 } 584 ); 585 586 document.addEventListener( 587 'change', 588 function (e) { 589 e = e || window.event; 590 var target = e.target; 591 if (target.hasAttribute( 'name' )) { 592 if (target.getAttribute( 'name' ) === 'shipping_method[0]') { 593 localStorage.setItem( 'EasyPackPointObject', null ); 594 console.log( 'reset local storage value' ); 595 jQuery('input[name=parcel_machine_desc]').each( 596 function (ind, elem) { 597 jQuery(elem).val(''); 598 } 599 ); 600 jQuery('input[name=parcel_machine_id]').each( 601 function (ind, elem) { 602 jQuery(elem).val(''); 603 } 604 ); 605 jQuery('*[id*=selected-parcel-machine-id]').each( 606 function (ind, elem) { 607 jQuery(elem).html(''); 608 } 609 ); 610 } 611 } 612 } 613 ); 614 615 jQuery( document ).ready( 616 function () { 617 618 jQuery( '.inpost_pl_geowidget_typ' ).on( 619 'click', 620 function () {
621 if ( typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null ) { 622 if ( ! inpostjsGeowidgetModal.isOpen) { 623 console.log( 'inpost_pl_geowidget_typ open jQuery' ); 624 inpostjsGeowidgetModal.open(); 625 } 626 } 627 } 628 ); 629 630 document.addEventListener( 631 'click', 632 function (e) { 633 e = e || window.event; 634 var target = e.target || e.srcElement; 635 636 if ( target.classList.contains( 'inpost_pl_geowidget_typ' ) ) { 637 e.preventDefault(); 638 console.log( 'JS btn click' ); 639 if (typeof inpostjsGeowidgetModal != 'undefined' && inpostjsGeowidgetModal !== null) { 640 if ( ! inpostjsGeowidgetModal.isOpen) { 641 inpostjsGeowidgetModal.open(); 642 } 643 } 644 } 645 } 646 ); 647 648 jQuery( '.inpost-pl-related-point-btn' ).click( 649 function (e) { 650 e.preventDefault(); 651 console.log( 'inpost-pl-related-point-btn' ); 652 653 let this_btn = jQuery( this ); 654 655 if ( inpost_pl_is_ajax_get_point_running ) { 656 console.log( 'AJAX already is running' ); 657 return false; 658 } 659 660 jQuery( '.inpost-pl-related-point-btn' ).each( 661 function (ind, elem) { 662 jQuery( elem ).css( 'background', '#fff' ); 663 } 664 ); 665 666 let nearest_point_selected = jQuery( this_btn ).attr( 'data-id' ); 667 668 let order_key = ''; 669 try { 670 let params = new URLSearchParams( window.location.search ); 671 order_key = params.get( 'key' ) || ''; 672 } catch (e) { 673 order_key = ''; 674 } 675 676 let data = { 677 action: 'update_locker_from_typ_page', 678 order_id: jQuery( '#inpost-pl-related-data-order' ).val(), 679 order_key: order_key, 680 inpost_pl_locker: nearest_point_selected, 681 inpost_pl_locker_desc: jQuery( this_btn ).attr( 'data-address-id' ), 682 security: easypack_front_map.security 683 }; 684 685 jQuery.ajax( 686 { 687 type: 'POST', 688 url: easypack_front_map.ajaxurl, 689 data: data, 690 dataType: 'json', 691 beforeSend: function () { 692 inpost_pl_is_ajax_get_point_running = true; 693 jQuery( '.hidden-inpost-pl-typ-data' ).css( 'display', 'none' ); 694 jQuery( this_btn ).find( '.inpost-pl-select-from-points-preloader' ).css( 'display', 'block' ); 695 jQuery( '.inpost_pl_locker_changed' ).each( 696 function (ind, elem) { 697 jQuery( elem ).remove(); 698 } 699 ); 700 }, 701 success: function (data, textStatus, jqXHR) { 702 console.log( 'inpost_pl_choose_locker_from_nearest result:' ); 703 console.log( data ); 704 705 if ( 'success' in data ) { 706 if ( data.success ) { 707 jQuery( this_btn ).css( 'background', '#afeaad' ); 708 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>' ); 709 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>' ); 710 } else { 711 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>' ); 712 } 713 714 } else { 715 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>' ); 716 } 717 }, 718 error: function (jqXHR, textStatus, errorThrown) { 719 console.log( 'inpost_pl_choose_locker_from_nearest_error' ); 720 console.log( 'error: ' + jqXHR.status ); 721 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>' ); 722 return false; 723 }, 724 complete: function () { 725 console.log( 'Complete' ); 726 inpost_pl_is_ajax_get_point_running = false;
727 728 jQuery( this_btn ).find( '.inpost-pl-select-from-points-preloader' ).css( 'display', 'none' ); 729 } 730 } 731 ); 732 } 733 ); 734 735 } 736 ); 737 738 } 739); 740 741 742function inpost_pl_js_get_map_config_based_on_instance_id(instance_id, method) { 743 let map_config = 'parcelCollect'; 744 let inpost_methods = inpost_pl_js_get_configured_inpost_methods(); 745 746 if (instance_id !== undefined && instance_id !== null && instance_id !== '') { 747 let selected_method = inpost_methods[instance_id]; 748 if (typeof selected_method != 'undefined' && selected_method !== null) { 749 let method_id = selected_method.inpost_title; 750 if (method_id === 'easypack_parcel_machines_cod') { 751 map_config = 'parcelCollectPayment'; 752 } 753 if (method_id === 'easypack_shipping_courier_c2c') { 754 map_config = 'parcelSend'; 755 } 756 if (method_id === 'easypack_parcel_machines_weekend' || method_id === 'easypack_parcel_machines_weekend_cod') { 757 map_config = 'parcelCollect247'; 758 } 759 } 760 761 } else { 762 if (method === 'easypack_parcel_machines_cod') { 763 map_config = 'parcelCollectPayment'; 764 } 765 if (method === 'easypack_shipping_courier_c2c') { 766 map_config = 'parcelSend'; 767 } 768 if (method === 'easypack_parcel_machines_weekend' || method === 'easypack_parcel_machines_weekend_cod') { 769 map_config = 'parcelCollect247'; 770 } 771 } 772 773 return map_config; 774} 775 776function inpost_pl_js_get_configured_inpost_methods() { 777 if (typeof window.easypack_front_map != 'undefined' && window.easypack_front_map !== null) { 778 if ( window.easypack_front_map.inpost_methods ) { 779 return window.easypack_front_map.inpost_methods; 780 } 781 } 782 return []; 783}
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.