1(function ($) { 2 "use strict"; 3 /* 4 author: [email protected] 5 version: 2.2.12 6 */ 7 $(function () { 8 createTracker($); 9 loadProvince($); 10 11 setTimeout(function () { 12 /* Hide the component states, city, & postcode */ 13 const prefixs = ["billing", "shipping"]; 14 prefixs.forEach((prefix) => { 15 let hide_component = [ 16 prefix + "_country_field", 17 prefix + "_company_field", 18 prefix + "_address_1_field", 19 prefix + "_address_2_field", 20 prefix + "_state_field", 21 prefix + "_city_field", 22 prefix + "_postcode_field", 23 prefix + "biteship_district", 24 prefix + "_biteship_district_info_field", 25 ]; 26 hide_component.forEach((element) => { 27 if (window.location.href.toString().includes("edit-address") && !element.includes("country")) { 28 $(`#${element}`).hide(); 29 } else if (!window.location.href.toString().includes("edit-address")) { 30 $(`#${element}`).hide(); 31 } 32 }); 33 $(`#${prefix}_biteship_location`).css({ 34 "padding-left": "29px", 35 background: 'url("' + window.location.protocol + "//" + window.location.host.replace("www.", "") + '/wp-content/plugins/biteship/public/images/pin.svg") no-repeat left', 36 "background-size": "13px", 37 "background-position": "7px", 38 height: "48px", 39 "min-height": "45px", 40 }); 41 }); 42 $("#myModal").hide(); 43 customShippingText($); 44 if (parseInt(phpVars.userSession.clearCache)) { 45 clearComponent($, "billing", true); 46 clearComponent($, "shipping", true); 47 $("[data-title=Shipping]").text("Masukkan alamat lengkap untuk menghitung ongkos kirim"); 48 console.log("CLEAR CACHE"); 49 } else { 50 if (phpVars.checkoutType === "dropdown" && !location.href.includes("edit-address")) { 51 removeState("billing_areas"); 52 removeState("shipping_areas"); 53 var billing_areas = localStorage.getItem("billing_areas"); 54 if (billing_areas == undefined) { 55 getAreasV2($, "billing"); 56 } 57 var shipping_areas = localStorage.getItem("shipping_areas"); 58 if (shipping_areas == undefined) { 59 getAreasV2($, "shipping"); 60 } 61 } 62 $("#billing_postcode").val(phpVars.userSession.postcode); 63 $("body").trigger("update_checkout", { update_shipping_method: true }); 64 } 65 }, 1800); 66 67 modifyComponent($, "billing"); 68 modifyComponent($, "shipping"); 69 $("body").append(` 70 <div id="myModal"> 71 <div class="modal-content"> 72 <div> 73 <span style="font-size: 25px;">Pin Alamat .</span> 74 <span id="closemyModal" class="close">×</span> 75 </div> 76 <form id="mapSearchForm" style="margin-top: 10px;font-size:13px;"> 77 <input style="width: 100%" type="text" id="placeSearch" placeholder="Masukkan alamat lengkap yang ada atau pilih pin"> 78 </form> 79 <div id="mapCheckout" class="map-order-review"></div> 80 </div> 81 </div>`); 82 83 if (!phpVars) { 84 phpVars = {}; 85 } 86 $("#placeSearch").click(function () { 87 if (screen.width >= 500) { 88 disableScroll(); 89 } 90 }); 91 92 gmapView($); 93 var modal = $("#myModal"); 94 var close = $("#closemyModal"); 95 if (close.length > 0) { 96 close[0].addEventListener("click", function () { 97 closeModal(modal); 98 }); 99 } 100 $(document).on("click", ".select-location", function () { 101 closeModal(modal); 102 $(document.body).trigger("update_checkout"); 103 }); 104 105 /* This only for smart search version 0.0.2*/ 106 smartSearchV2($, phpVars); 107 108 /* Refresh fee calculation when payment method is changed */ 109 $("form.checkout").on("change", 'input[name="payment_method"]', function () { 110 $(document.body).trigger("update_checkout"); 111 }); 112 113 $("form.checkout").on("change", 'input[name="is_insurance_active"]', function () { 114 $(document.body).trigger("update_checkout"); 115 }); 116 117 /* Refresh calculation when pilih Alamat Toko is changed */ 118 refreshMultiOrigin($, "billing"); 119 refreshMultiOrigin($, "shipping"); 120 }); 121})(jQuery); 122 123function getKeyByValue(object, value) { 124 return Object.keys(object).find((key) => object[key].toUpperCase() === value.toUpperCase()); 125} 126 127function getAreasV2($, prefix) { 128 var check = document.getElementById(`${prefix}_biteship_province`); 129 if (check !== null) { 130 var areaID = $(`#${prefix}_biteship_province`).val(); 131 if (areaID !== null && areaID.length > 0) { 132 var baseURL = phpVars.biteshipBaseUrl || ""; 133 $(".overlay").css("display", "block"); 134 $.ajax({ 135 url: `${baseURL}
135/v1/woocommerce/maps/administrative_division_levels`, 136 data: { 137 level: "2", 138 area_id: areaID, 139 }, 140 type: "POST", 141 headers: { 142 authorization: `Bearer ${phpVars.biteshipLicenseKey || ""}`, 143 }, 144 success: function (data) { 145 if (!data.success) { 146 alert("API Biteship sedang bermasalah."); 147 } 148 if (data.areas.length > 0) { 149 /* render data city, district, zipcode */ 150 localStorage.setItem(`${prefix}_areas`, JSON.stringify(data.areas)); 151 setMapAreas($, data.areas, `${prefix}_biteship_city`, "administrative_division_level_2_name"); 152 setMapAreas($, data.areas, `${prefix}_biteship_district`, "administrative_division_level_3_name"); 153 setMapAreas($, data.areas, `${prefix}_biteship_zipcode`, "postal_code"); 154 $(`#${prefix}_state`).val(getStateID(data.areas[0]["administrative_division_level_1_name"])).change(); 155 getListMultiOrigin($, areaID, prefix); 156 setCountryState($, "billing"); 157 setCountryState($, "shipping"); 158 clearMap(); 159 $("body").trigger("update_checkout"); 160 $(".overlay").css("display", "none"); 161 } 162 }, 163 error: function (_) { 164 console.log("Gagal mencari lokasi berdasarkan provinsi, kota & kecamatan."); 165 $(".overlay").css("display", "none"); 166 }, 167 }); 168 } 169 } 170} 171 172function setMapAreas($, areas, component, division) { 173 let choose = ""; 174 if (component.includes("city")) { 175 choose = "Pilih Kota"; 176 } else if (component.includes("district")) { 177 choose = "Pilih Kecamatan"; 178 } else if (component.includes("zipcode")) { 179 choose = "Pilih Kode Pos"; 180 } 181 $(`#${component}`).empty().prop("disabled", false); 182 let unique = []; 183 areas.map(function (val) { 184 if (!unique.includes(val[division])) { 185 if (unique.length == 0) { 186 $(`#${component}`).append('<option value="" selected>' + choose + "</option>"); 187 } 188 unique.push(val[division]); 189 $(`#${component}`).append('<option value="' + val[division] + '">' + val[division] + "</option>"); 190 } 191 }); 192} 193 194function setPosition(marker, infoWindow, map, location, $) { 195 marker.setPosition(location); 196 marker.setMap(map); 197 infoWindow.setContent("<p class='select-location'>Pilih titik ini</p>"); 198 infoWindow.setPosition(location); 199 infoWindow.open(map, marker); 200 201 var latLong = `${location.lat()},${location.lng()}`; 202 $("#position").val(latLong); 203 $("#billing_biteship_location_coordinate").val(latLong); 204 $("#shipping_biteship_location_coordinate").val(latLong); 205 getAddress($, latLong); 206 $("#billing_biteship_location_coordinate").on("input", function () { 207 $("body").trigger("update_checkout", { update_shipping_method: true }); 208 }); 209 $("#shipping_biteship_location_coordinate").on("input", function () { 210 $("body").trigger("update_checkout", { update_shipping_method: true }); 211 }); 212} 213 214function getAddress($, latLong) { 215 var enc = function (s, b) { 216 var w = ""; 217 for (var i = 0; i < s.length; i++) { 218 w += String.fromCharCode(s.charCodeAt(i) ^ b); 219 } 220 return unescape(w); 221 }; 222 var apiKey = enc(phpVars.apiKey, window.location.host.replace("www.", "").length) || ""; 223 $.ajax({ 224 url: `https://maps.googleapis.com/maps/api/geocode/json?latlng=${latLong}&sensor=true&key=${apiKey}`, 225 type: "GET", 226 success: function (response) { 227 switch (response.status) { 228 case "OK": 229 var address = response.results[0].formatted_address; 230 $("#billing_biteship_location").val(address).addClass("valid"); 231 $("#shipping_biteship_location").val(address).addClass("valid"); 232 if (address.length >= 110) { 233 $(`#billing_biteship_location`).css({ 234 "padding-left": "29px", 235 background: 'url("' + window.location.protocol + "//" + window.location.host.replace("www.", "") + '/wp-content/plugins/biteship/public/images/pin.svg") no-repeat left', 236 "background-size": "13px", 237 "background-position": "7px", 238 height: "66px", 239 }); 240 $(`#shipping_biteship_location`).css({ 241 "padding-left": "29px", 242 background: 'url("' + window.location.protocol + "//" + window.location.host.replace("www.", "") + '/wp-content/plugins/biteship/public/images/pin.svg") no-repeat left', 243 "background-size": "13px", 244 "background-position": "7px", 245 height: "66px", 246 }); 247 } else { 248 $(`#billing_biteship_location`).css({ 249 "padding-left": "29px", 250 background: 'url("' + window.location.protocol + "//" + window.location.host.replace("www.", "") + '/wp-content/plugins/biteship/public/images/pin.svg") no-repeat left', 251 "background-size": "13px", 252 "background-position": "7px", 253 height: "48px", 254 }); 255 $(`#shipping_biteship_location`).css({ 256 "padding-left": "29px", 257 background: 'url("' + window.location.protocol + "//" + window.location.host.replace("www.", "") + '/wp-content/plugins/biteship/public/images/pin.svg") no-repeat left', 258 "background-size": "13px", 259 "background-position": "7px", 260 height: "48px", 261 }); 262 } 263 saveState("billing_biteship_location", address); 264 saveState("shipping_biteship_location", address); 265 saveState("billing_biteship_location_coordinate", latLong); 266 saveState("shipping_biteship_location_coordinate", latLong); 267 break; 268 default: 269 alert(response.status); 270 } 271 }, 272 }); 273} 274 275function customShippingText($) { 276 if ($("[data-title=Shipping]").html() !== undefined) { 277 if ($("[data-title=Shipping]").html().includes("options") || $("[data-title=Shipping]").html().includes("invalid")) { 278 $("[data-title=Shipping]").text("Masukkan alamat lengkap untuk menghitung ongkos kirim."); 279 } 280 } 281} 282 283function clearComponent($, prefix, isActive) { 284 $(`#${prefix}_city`).val(""); 285 $(`#${prefix}_postcode`).val(""); 286 $(`#${prefix}_state`).prop("selected", false); 287 $(`#${prefix}_biteship_new_district`).val(""); 288 $(`#${prefix}_biteship_multi_origins`).val(""); 289 if (isActive) { 290 $(`#${prefix}_biteship_location`).val(""); 291 } 292 if (isActive) { 293 getAreasV2($, prefix); 294 } 295 customShippingText($); 296} 297 298function getProvinces() { 299 return { 300 Bali: "IDNP1", 301 "Bangka Belitung": "IDNP2", 302 Banten: "IDNP3", 303 Bengkulu: "IDNP4", 304 "DI Yogyakarta": "IDNP5", 305 "DKI Jakarta": "IDNP6", 306 Gorontalo: "IDNP7", 307 Jambi: "IDNP8", 308 "Jawa Barat": "IDNP9", 309 "Jawa Tengah": "IDNP10", 310 "Jawa Timur": "IDNP11", 311 "Kalimantan Barat": "IDNP12", 312 "Kalimantan Selatan": "IDNP13", 313 "Kalimantan Tengah": "IDNP14", 314 "Kalimantan Timur": "IDNP15", 315 "Kalimantan Utara": "IDNP16", 316 "Kepulauan Riau": "IDNP17",
317 Lampung: "IDNP18", 318 Maluku: "IDNP19", 319 "Maluku Utara": "IDNP20", 320 "Nanggroe Aceh Darussalam (NAD)": "IDNP21", 321 "Nusa Tenggara Barat (NTB)": "IDNP22", 322 "Nusa Tenggara Timur (NTT)": "IDNP23", 323 Papua: "IDNP24", 324 "Papua Barat": "IDNP25", 325 Riau: "IDNP26", 326 "Sulawesi Barat": "IDNP27", 327 "Sulawesi Selatan": "IDNP28", 328 "Sulawesi Tengah": "IDNP29", 329 "Sulawesi Tenggara": "IDNP30", 330 "Sulawesi Utara": "IDNP31", 331 "Sumatera Barat": "IDNP32", 332 "Sumatera Selatan": "IDNP33", 333 "Sumatera Utara": "IDNP34", 334 }; 335} 336function getStateID(key) { 337 var mapState = getProvinces(); 338 return mapState[key]; 339} 340 341function setZipcode($, district, prefix) { 342 if (localStorage.getItem(`${prefix}_areas`) !== null) { 343 let no = 1; 344 var listZipcode = []; 345 $(`#${prefix}_biteship_zipcode`).empty(); 346 $(`#${prefix}_biteship_multi_origins`).val(""); 347 var areas = JSON.parse(localStorage.getItem(`${prefix}_areas`)); 348 areas.map(function (val) { 349 if (district == val.administrative_division_level_3_name) { 350 if (!listZipcode.includes(val.postal_code)) { 351 if (no === 1) { 352 $(`#${prefix}_biteship_zipcode`).append('<option value="" selected>Pilih Kode Pos</option>'); 353 } 354 $(`#${prefix}_biteship_zipcode`).append('<option value="' + val.postal_code + '">' + val.postal_code + "</option>"); 355 no += 1; 356 listZipcode.push(val.postal_code); 357 } 358 } 359 }); 360 } 361} 362 363function setDistrict($, city, prefix) { 364 if (localStorage.getItem(`${prefix}_areas`) !== null) { 365 let no = 0; 366 var areas = JSON.parse(localStorage.getItem(`${prefix}_areas`)); 367 var listDistricts = []; 368 $(`#${prefix}_biteship_district`).empty(); 369 $(`#${prefix}_biteship_zipcode`).empty(); 370 areas.map(function (val) { 371 if (city == val.administrative_division_level_2_name) { 372 if (!listDistricts.includes(val.administrative_division_level_3_name)) { 373 if (no == 0) { 374 $(`#${prefix}_biteship_district`).append('<option value="" selected>Pilih Kecamatan</option>'); 375 } 376 $(`#${prefix}_biteship_district`).append('<option value="' + val.administrative_division_level_3_name + '">' + val.administrative_division_level_3_name + "</option>"); 377 listDistricts.push(val.administrative_division_level_3_name); 378 } 379 } 380 }); 381 } 382} 383 384function closeModal(modal) { 385 modal.css("display", "none"); 386} 387 388function modifyComponent($, prefix) { 389 $("#billing_phone_field>label").html('No Tlp <abbr class="required" title="required">*</abbr>'); 390 $("#billing_email_field>label").html('Alamat Email <abbr class="required" title="required">*</abbr>'); 391 392 $(`#${prefix}_biteship_address`).change(function () { 393 var address = $(`#${prefix}_biteship_address`).val(); 394 $(`#${prefix}_address_1`).val(address); 395 saveState(`${prefix}_address_1`, address); 396 }); 397 $(`#${prefix}_biteship_location`).click(function () { 398 $("#myModal").show(); 399 $("#placeSearch").val(""); 400 }); 401 $(`#${prefix}_biteship_province`).change(function () { 402 clearComponent($, prefix, false); 403 getAreasV2($, prefix); 404 saveState(`${prefix}_biteship_province`, $(`#${prefix}_biteship_province`).val()); 405 $("body").trigger("update_checkout"); 406 }); 407 $(`#${prefix}_biteship_city`).change(function () { 408 clearComponent($, prefix, false); 409 var city = $(`#${prefix}_biteship_city`).val(); 410 $(`#${prefix}_city`).val(city); 411 setDistrict($, city, prefix); 412 saveState(`${prefix}_biteship_city`, $(`#${prefix}_biteship_city`).val()); 413 $("body").trigger("update_checkout"); 414 }); 415 $(`#${prefix}_biteship_district`).change(function () { 416 var district = $(`#${prefix}_biteship_district`).val(); 417 saveState(`${prefix}_biteship_district`, $(`#${prefix}_biteship_district`).val()); 418 setZipcode($, district, prefix); 419 }); 420 $(`#${prefix}_biteship_zipcode`).change(function () { 421 /* only used zipcode or longlat for courier */ 422 var zipcode = $(`#${prefix}_biteship_zipcode`).val(); 423 $(`#${prefix}_postcode`).val(zipcode).change(); 424 $("body").trigger("update_checkout"); 425 saveState(`${prefix}_biteship_zipcode`, $(`#${prefix}_biteship_zipcode`).val()); 426 }); 427 428 /* smart search */ 429 $(`#${prefix}_biteship_new_district`).keyup(function () { 430 var district = $(`#${prefix}_biteship_new_district`).val(); 431 if (district.length === 0) { 432 $(`#${prefix}_biteship_district_info`).val(""); /* clear data */ 433 $(`#${prefix}_biteship_district_info_field`).hide(); 434 $("body").trigger("update_checkout", { update_shipping_method: true }); 435 clearComponent($, "billing", true); 436 clearComponent($, "shipping", true); 437 } 438 }); 439} 440 441function saveState(key, value) { 442 localStorage.setItem(key, value); 443} 444 445function loadState(key) { 446 return localStorage.getItem(key); 447} 448 449function removeState(key) { 450 return localStorage.removeItem(key); 451} 452 453function preventDefault(e) { 454 e.preventDefault(); 455} 456 457function preventDefaultForScrollKeys(e) { 458 var keys = { 37: 1, 38: 1, 39: 1, 40: 1 }; 459 if (keys[e.keyCode]) { 460 preventDefault(e); 461 return false;
462 } 463} 464var supportsPassive = false; 465try { 466 window.addEventListener( 467 "test", 468 null, 469 Object.defineProperty({}, "passive", { 470 get: function () { 471 supportsPassive = true; 472 }, 473 }), 474 ); 475} catch (e) {} 476 477var wheelOpt = supportsPassive ? { passive: false } : false; 478var wheelEvent = "onwheel" in document.createElement("div") ? "wheel" : "mousewheel"; 479function disableScroll() { 480 window.addEventListener("DOMMouseScroll", preventDefault, false); 481 window.addEventListener(wheelEvent, preventDefault, wheelOpt); 482 window.addEventListener("touchmove", preventDefault, wheelOpt); 483 window.addEventListener("keydown", preventDefaultForScrollKeys, false); 484} 485function enableScroll() { 486 window.removeEventListener("DOMMouseScroll", preventDefault, false); 487 window.removeEventListener(wheelEvent, preventDefault, wheelOpt); 488 window.removeEventListener("touchmove", preventDefault, wheelOpt); 489 window.removeEventListener("keydown", preventDefaultForScrollKeys, false); 490} 491 492function loadProvince($) { 493 let no = 0; 494 var mapState = getProvinces(); 495 const prefixs = ["billing", "shipping"]; 496 prefixs.forEach((prefix) => { 497 if (document.getElementById(`${prefix}_biteship_province`) !== null) { 498 if (!document.getElementById(`${prefix}_biteship_province`).innerHTML.includes("IDNP1")) { 499 for (const [key, value] of Object.entries(mapState)) { 500 if (no == 0) { 501 $(`#${prefix}_biteship_province`).empty(); 502 $(`#${prefix}_biteship_province`).append('<option value="" selected>Pilih Provinsi</option>'); 503 $(`#${prefix}_biteship_city`).empty(); 504 $(`#${prefix}_biteship_city`).append('<option value="" selected>Pilih Kota</option>'); 505 $(`#${prefix}_biteship_district`).empty(); 506 $(`#${prefix}_biteship_district`).append('<option value="" selected>Pilih Kecamatan</option>'); 507 $(`#${prefix}_biteship_zipcode`).empty(); 508 $(`#${prefix}_biteship_zipcode`).append('<option value="" selected>Pilih Kode Pos</option>'); 509 $(`#${prefix}_biteship_multi_origins`).empty(); 510 $(`#${prefix}_biteship_multi_origins`).append('<option value="" selected>Pilih province dulu</option>'); 511 } 512 $(`#${prefix}_biteship_province`).append('<option value="' + value + '">' + key + "</option>"); 513 no += 1; 514 } 515 } 516 } 517 }); 518} 519 520function createTracker($) { 521 if (phpVars.trackingPageUrl.length > 0 && parseInt(phpVars.trackingPageIsactive)) { 522 if ($("body").html().includes('data-title="Actions"')) { 523 $("tr.woocommerce-orders-table__row").each(function (i) { 524 var btnView = $(this).find("td.woocommerce-orders-table__cell.woocommerce-orders-table__cell-order-actions a"); 525 var component = $(this).find("td.woocommerce-orders-table__cell.woocommerce-orders-table__cell-order-actions"); 526 527 var orderId = new URL(btnView.attr("href")).searchParams.get("view-order"); 528 if (orderId === null) { 529 const temp = btnView.attr("href").split("/"); 530 if (temp.length > 3) { 531 orderId = temp[temp.length - 2]; 532 } 533 } 534 if (orderId !== undefined) { 535 var data = { 536 action: "get_order_detail", 537 orderId: orderId, 538 dataType: "json", 539 }; 540 $.post("/wp-admin/admin-ajax.php", data, function (response) { 541 if (response.success) { 542 if (response.data.waybill_id.length > 0) { 543 component.append( 544 `<a href="${response.data.link}" target="_blank" class="woocommerce-button wp-element-button button view">TRACK</a>`, 545 [btnView], 546 ); 547 } 548 } else { 549 console.log("ERROR!!!", orderId); 550 } 551 }); 552 } 553 }); 554 } 555 } 556} 557 558function smartSearchV2($, phpVars) { 559 if (phpVars !== {} && phpVars.checkoutType === "smartsearch") { 560 try { 561 $(".init-select2 select").select2(); 562 $(".select2-ajax select").each(function () { 563 var baseURL = phpVars.biteshipBaseUrl || ""; 564 $(this).select2({ 565 ajax: { 566 url: `${baseURL}
566/v1/woocommerce/maps/areas`, 567 dataType: "json", 568 headers: { 569 authorization: `Bearer ${phpVars.biteshipLicenseKey || ""}`, 570 }, 571 type: "POST", 572 delay: 250, 573 data: function (params) { 574 return { 575 countries: "ID", 576 input: params.term, 577 type: "single", 578 }; 579 }, 580 processResults: function (data, _) { 581 var result = []; 582 if (data.areas.length > 0) { 583 result = data.areas.map(function (val) { 584 return { 585 id: val.id, 586 text: `${val.postal_code}, ${val.administrative_division_level_3_name}, ${val.administrative_division_level_2_name}, ${val.administrative_division_level_1_name}`, 587 name: val.name, 588 provice: val.administrative_division_level_1_name, 589 district: val.administrative_division_level_3_name, 590 city: val.administrative_division_level_2_name, 591 state: val.administrative_division_level_1_name, 592 zipcode: val.postal_code, 593 }; 594 }); 595 } 596 saveState("smartsearch_area", JSON.stringify(result)); 597 return { 598 results: result, 599 }; 600 }, 601 cache: true, 602 }, 603 minimumInputLength: 3, 604 language: { 605 inputTooShort: function (args) { 606 return "Input minimal 3 karakter"; 607 }, 608 }, 609 placeholder: $(this).attr("placeholder"), 610 }); 611 }); 612 613 const addressType = ["billing", "shipping"]; 614 addressType.forEach((prefix) => { 615 $(`#${prefix}_biteship_new_district`).change(function () { 616 setTimeout(function () { 617 var loadState = localStorage.getItem("smartsearch_area"); 618 if (loadState !== undefined) { 619 JSON.parse(loadState).map(function (val) { 620 if (val.text === document.getElementById(`select2-${prefix}_biteship_new_district-container`).title) { 621 if (val.id.split("IDNC").length > 1) { 622 getListMultiOrigin($, val.id.split("IDNC")[0], prefix); 623 } 624 $(`#${prefix}_state`).val(val.state).change(); 625 $(`#${prefix}_city`).val(val.city); 626 $(`#${prefix}_postcode`).val(val.zipcode); 627 $(`#${prefix}_biteship_district`).val(val.district); 628 $("body").trigger("update_checkout"); 629 clearMap(); 630 customShippingText($); 631 } 632 }); 633 } 634 }, 1200); 635 }); 636 }); 637 } catch (error) { 638 console.log(error); 639 } 640 } 641} 642 643function getListMultiOrigin($, areaID, prefix) { 644 if (parseInt(phpVars.multipleOriginsIsactive)) { 645 var data = { 646 action: "biteship_public_get_multiple_origin", 647 areaID: areaID, 648 security: phpVars.biteshipNonce, 649 dataType: "json", 650 }; 651 $.post(woocommerce_params.ajax_url, data, function (response) { 652 if (response.success) { 653 setMultiOrigin($, response.data, prefix); 654 } else { 655 window.alert("ERROR!!!"); 656 } 657 }); 658 } else { 659 console.log("multiple origin not active"); 660 } 661} 662 663function setMultiOrigin($, data, prefix) { 664 $(`#${prefix}_biteship_multi_origins`).empty(); 665 if (data.multiple_addresses.length === 0) { 666 $(`#${prefix}_biteship_multi_origins`).removeAttr("disabled"); 667 data.default_address.map(function (val) { 668 $(`#${prefix}_biteship_multi_origins`).append('<option value="' + val.id + '">
668' + val.shopname + " - " + val.address + "</option>"); 669 }); 670 return; 671 } 672 $(`#${prefix}_biteship_multi_origins`).removeAttr("disabled"); 673 $(`#${prefix}_biteship_multi_origins`).append('<option value="none" selected>Pilih Toko</option>'); 674 data.multiple_addresses.map(function (val) { 675 $(`#${prefix}_biteship_multi_origins`).append('<option value="' + val.id + '">' + val.shopname + " - " + val.address + "</option>"); 676 }); 677} 678 679function gmapView($) { 680 var marker = null; 681 var infoWindow = null; 682 var enc = function (s, b) { 683 var w = ""; 684 for (var i = 0; i < s.length; i++) { 685 w += String.fromCharCode(s.charCodeAt(i) ^ b); 686 } 687 return unescape(w); 688 }; 689 var apiKey = enc(phpVars.apiKey, window.location.host.replace("www.", "").length) || ""; 690 $.getScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places`, function () { 691 var myLatLng = { lat: -6.1753871, lng: 106.8249641 }; 692 if (phpVars.userSession.coordinate.length > 5) { 693 var userCoordinate = phpVars.userSession.coordinate.split(","); 694 myLatLng.lat = parseFloat(userCoordinate[0]); 695 myLatLng.lng = parseFloat(userCoordinate[1]); 696 } 697 698 var map = new google.maps.Map(document.getElementById("mapCheckout"), { 699 zoom: 15, 700 center: myLatLng, 701 disableDefaultUI: true, 702 fullscreenControl: true, 703 }); 704 marker = new google.maps.Marker({ 705 position: null, 706 map: null, 707 title: "Location", 708 }); 709 710 infoWindow = new google.maps.InfoWindow({}); 711 map.addListener("click", function (mapsMouseEvent) { 712 var selectedPosition = mapsMouseEvent.latLng; 713 setPosition(marker, infoWindow, map, selectedPosition, $); 714 }); 715 716 /* Add event when user click searchbox autocomplete */ 717 var input = document.getElementById("placeSearch"); 718 var autocomplete = new google.maps.places.Autocomplete(input); 719 autocomplete.setComponentRestrictions({ country: ["id"] }); 720 autocomplete.addListener("place_changed", function () { 721 var place = autocomplete.getPlace(); 722 if (!place.geometry) { 723 /* 724 User entered the name of a Place that was not suggested and 725 pressed the Enter key, or the Place Details request failed. 726 */ 727 return; 728 } 729 myLatLng = { 730 lat: place.geometry.location.lat(), 731 lng: place.geometry.location.lng(), 732 }; 733 map.setCenter(place.geometry.location); 734 marker.setPosition(place.geometry.location); 735 marker.setMap(map); 736 setPosition(marker, infoWindow, map, place.geometry.location, $); 737 $("#position-input").val(place.geometry.location.lat() + "," + place.geometry.location.lng()); 738 if (screen.width >= 500) { 739 enableScroll(); 740 } 741 }); 742 }); 743} 744 745function refreshMultiOrigin($, prefix) { 746 $(`#${prefix}_biteship_multi_origins`).on("change", function () { 747 if (this.value === "none") { 748 alert("Pastikan anda sudah pilih toko"); 749 return; 750 } 751 if (phpVars.biteshipLicenseKeyType !== "woocommerceFree" || phpVars.biteshipLicenseKeyType !== "woocommerceEssentials") { 752 clearMap(); 753 } 754 $("body").trigger("update_checkout", { update_shipping_method: true }); 755 gmapView($); 756 }); 757} 758 759function clearMap() { 760 if (document.getElementById(`position`) !== null) { 761 document.getElementById(`position`).value = ""; 762 } 763 if (document.getElementById(`billing_biteship_location`) !== null) { 764 document.getElementById(`billing_biteship_location`).value = ""; 765 } 766 if (document.getElementById(`shipping_biteship_location`) !== null) { 767 document.getElementById(`shipping_biteship_location`).value = ""; 768 } 769 if (document.getElementById(`billing_biteship_location_coordinate`) !== null) { 770 document.getElementById(`billing_biteship_location_coordinate`).value = ""; 771 } 772 if (document.getElementById(`shipping_biteship_location_coordinate`) !== null) { 773 document.getElementById(`shipping_biteship_location_coordinate`).value = ""; 774 } 775} 776 777/*setCountryState - for textbox not selected box */ 778function setCountryState($, prefix) { 779 if (!location.href.includes("edit-address")) { 780 var fullPrefix = "#" + prefix + `_state`; 781 var checkBillState = document.getElementById(prefix + `_state`); 782 if (checkBillState !== null) { 783 var mapState = getProvinces(); 784 if ($(fullPrefix).val().includes("IDN")) { 785 for (const [key, value] of Object.entries(mapState)) { 786 if (value === $(fullPrefix).val()) { 787 document.getElementById("billing_state").value = key; 788 console.log("yohohoohoh"); 789 break; 790 } 791 } 792 } 793 } 794 } 795}
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.