1/* DAALDEROP custom script for global only ( including : header, footer, global section, global ux-block ) !!! */ 2console.log('global script loaded'); 3 4/*============================================ 5// GLOBAL DAALDEROP 6============================================*/ 7// GLOBAL >>> K Formatter 8function kFormatter(num) { 9 return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'K' : Math.sign(num)*Math.abs(num) 10} 11 12// GLOBAL >>> Number Count ================ */ 13window.addEventListener("load", function(){ 14 jQuery('.numberCount').waypoint(function (direction){ 15 jQuery('.numberCount').each(function () { 16 jQuery(this).prop('Counter',0).animate({ 17 Counter: jQuery(this).attr('data-count') 18 }, { 19 duration: 4000, 20 easing: 'swing', 21 step: function (now) { 22 jQuery(this).text( 23 (window.innerWidth <= 849) ? 24 kFormatter( 25 Math.ceil(now) 26 ) : Math.ceil(now) 27 ); 28 } 29 }); 30 }); 31 this.destroy(); 32 },{ 33 offset: '92%' 34 }); 35}); 36 37/* change lang image (header) */ 38jQuery('img[alt*="English"]').attr('src','/wp-content/uploads/2022/12/lang-en.webp'); 39jQuery('img[alt*="Indonesia"]').attr('src','/wp-content/uploads/2022/12/lang-id.webp'); 40 41// GLOBAL >>> floating hotline 42jQuery('.btnHotline').click( function(){ 43 jQuery('.contentHotline').show(); 44}); 45jQuery('.xContentHotline').click( function(){ 46 jQuery('.contentHotline').hide(); 47}); 48jQuery('body').click(function (event) //click other to close hotline 49{ 50 if(!jQuery(event.target).closest('.btnHotline').length && !jQuery(event.target).is('.btnHotline')) { 51 jQuery(".contentHotline ").hide(); 52 } 53}); 54 55// GLOBAL >>> Flag 56jQuery('img[alt*="EN"]').attr('src','/wp-content/uploads/2022/12/Inggris.jpg'); 57jQuery('img[alt*="ID"]').attr('src','/wp-content/uploads/2022/12/Indonesia.jpg'); 58 59// GLOBAL >>> PRODUCT >>> SWIPER / SLIDER 60if (jQuery(".custom-slider").length) { 61 var swiper = new Swiper(".productSlider", { 62 slidesPerView: 1, 63 spaceBetween: 20, 64 pagination: { 65 el: ".swiper-pagination", 66 clickable: true, 67 }, 68 navigation: { 69 nextEl: ".swiper-button-next", 70 prevEl: ".swiper-button-prev", 71 }, 72 breakpoints: { 73 548: { 74 slidesPerView: 3, 75 spaceBetween: 30, 76 }, 77 }, 78 }); 79} 80 81// GLOBAL >>> PRODUCT >>> GET PRODUCT USE AJAX 82function getProductAjax(the_id) { 83 jQuery(".product-content-body, .product-content-header").addClass("loading"); 84 jQuery.ajax({ 85 // use the ajax object url 86 url: ajax_object.ajax_url, 87 data: { 88 action: "get_product_ajax", // ajax function in php 89 pid: the_id, // send value (can mix by jQuery script) 90 }, 91 dataType: "json", 92 success: function (data) { 93 //when request success 94 jQuery( 95 ".product-content-header .product-title, .product-content-body .product-title" 96 ).html(data[0]); 97 jQuery(".product-content-header .product-image-wrapper").html(data[1]); 98 jQuery(".product-content-header .product-capacity-estimation").html( 99 data[2] 100 ); 101 jQuery(".product-content-body .product-capacity").html(data[3]); 102 jQuery(".product-content-body .product-dimension").html(data[4]); 103 jQuery(".product-content-body .product-single-element").html(data[5]); 104 jQuery(".product-content-body .product-weight").html(data[6]); 105 jQuery(".product-content-body .product-duo-element").html(data[7]); 106 jQuery(".product-content-body .product-download").attr("href", data[8]); 107 jQuery(".product-content-body .tokopedia").attr("href", data[10]); 108 jQuery(".product-content-body .shopee").attr("href", data[11]); 109 jQuery(".product-content-body .blibli").attr("href", data[12]); 110 111 // Added Extra Fitur for 150L 112 if(data[13]) { 113 appendExtraFor150L(); 114 } else { 115 jQuery('.col-extra-fitur').remove(); 116 } 117 118 history.pushState("", "", data[9]); 119 document.title = data[0]; 120 if (jQuery(".header-wrapper.stuck").length) { 121 jQuery("html, body").animate( 122 { 123 scrollTop: 124 jQuery(".product-content-header").offset().top - 125 jQuery(".header-main").height() * 1.5 - 126 100, 127 }, 128 1500 129 ); 130 } else { 131 jQuery("html, body").animate( 132 { 133 scrollTop: 134 jQuery(".product-content-header").offset().top - 135 jQuery(".header-main").height() * 1.5, 136 }, 137 1500 138 ); 139 } 140 jQuery(".product-content-body, .product-content-header").removeClass( 141 "loading error" 142 ); 143 }, 144 error: function (data) { 145 // test to see what you get back on error 146 console.log(data); 147 jQuery(".product-content-body, .product-content-header").addClass( 148 "error" 149 ); 150 }, 151 }); 152} 153 154// Added Extra Fitur for 150L 155function appendExtraFor150L() { 156 const lang = jQuery("html").attr("lang"); 157 const text = lang == "id-ID" ? "Extra Fitur Turbo" : "Extra Turbo Features"; 158 159 jQuery(".section.product-content-header .row").append(` 160 <div class="col pb-0 medium-6 small-12 large-3 col-extra-fitur" style="background: lightgray; margin-block: auto;"> 161 <div class="col-inner" style="padding-block: 10px;"> 162 <div class="text"> 163 <p class="text-primary mb-0" style="font-weight: 700;">${text}</p> 164 <p class="mb-0">+1500W <i>(Optional)</i></p> 165 </div> 166 </div> 167 </div> 168 `); 169} 170 171// GLOBAL >>> submit form address 172if (jQuery(".address-form").length) { 173 //handle form input 174 let typingTimer; 175 let doneTypingInterval = 1250; 176 let $input = jQuery(".address-form .input-cont input"); 177 let formLang = jQuery(".address-form").attr("data-lang"); 178 let loadingText = "Memuat rekomendasi ..."; 179 let failedText = 180 "Gagal memuat rekomendasi. Anda dapat menginputkan secara manual."; 181 if (formLang == "EN") { 182 loadingText = "Getting recommendations ..."; 183 failedText = "Failed to get a recommendation. You can input manually."; 184 } 185 //on keyup, start the countdown 186 $input.on("keyup", function () { 187 if ($input.val()) { 188 jQuery(".address-form .input-cont .input-result").html( 189 '<p class="address-item load">' + loadingText + "</p>" 190 ); 191 jQuery(".address-form .input-cont .input-result").css("display", "flex"); 192 } else { 193 jQuery(".address-form .input-cont .input-result").removeAttr("style"); 194 } 195 clearTimeout(typingTimer); 196 typingTimer = setTimeout(doneTyping, doneTypingInterval); 197 }); 198 //on keydown, clear the countdown
199 $input.on("keydown", function () { 200 clearTimeout(typingTimer); 201 }); 202 // finish typing 203 function doneTyping() { 204 if ($input.val()) { 205 fetch( 206 "https://discover.search.hereapi.com/v1/autosuggest?q=" + 207 $input.val() + 208 "&size=8&addressFilter=countryCode%3DIDN&at=-7.4145,112.5477&apiKey=3O06gmsnebTzvJv6IxmoE_IXDAdnIgTa53VpjQL9kfI" 209 ) 210 .then((response) => { 211 return response.json(); 212 }) 213 .then((data) => { 214 jQuery(".address-form .input-cont .input-result").html(""); 215 216 let formLang = jQuery(".address-form").attr("data-lang"); 217 jQuery(".address-form .input-cont .input-result").append( 218 `<p class="findByGPS" onclick="getGeoAPI();">${(formLang == "EN") ? "Search By Your GPS" : "Cari Berdasarkan GPS Anda"}</p>` 219 ); 220 221 data.items.forEach((item) => { 222 jQuery(".address-form .input-cont .input-result").append( 223 `<p class="address-item">${item.address?.label}</p>` 224 ); 225 jQuery(".address-form .input-result .address-item").click( 226 function () { 227 jQuery(".address-form #address").val(jQuery(this).html()); 228 jQuery(".address-form .input-cont .input-result").removeAttr( 229 "style" 230 ); 231 jQuery(".address-form").submit(); 232 } 233 ); 234 }); 235 }) 236 .catch((error) => { 237 jQuery(".address-form .input-cont .input-result").html( 238 '<p class="address-item error">' + failedText + "</p>" 239 ); 240 console.log("catch error: " + error); 241 }); 242 } 243 } 244 245 const formA = document.forms["address-form"]; 246 const jFormA = jQuery(".address-form"); 247 jQuery(".address-form .address-submit").click(function () { 248 if (formA.reportValidity()) { 249 jQuery(".address-form").submit(); 250 } 251 }); 252 jQuery(".address-form").submit(function (event) { 253 let alamat = jFormA.find("#address").val(); 254 // let address = alamat+' '+kota+' '+kodepos 255 let address = alamat; 256 if (formLang == "EN") { 257 window.location.href = 258 "/en/dealer-location/?address=" + encodeURI(address); 259 } else { 260 window.location.href = "/lokasi-dealer/?address=" + encodeURI(address); 261 } 262 event.preventDefault(); 263 }); 264} 265 266/*============================================ 267// Partnership - max length textarea 268============================================*/ 269jQuery(document).ready(function() { 270 jQuery(".contentPartnership textarea").on('keyup', function(){ 271 var jmltext = jQuery('.contentPartnership textarea').val() 272 jQuery('#msgLength').html(jmltext .length) 273 }); 274}); 275 276/*============================================ 277// FAQ 278============================================*/ 279jQuery('section.faq .icon-angle-down').addClass('dashicons dashicons-arrow-down').removeClass('icon-angle-down'); 280 281/*============================================ 282// Project 283============================================*/ 284jQuery('.projectTab .tabbed-content ul.nav').prepend('<span class="absoluteNavLeft dashicons dashicons-arrow-left"></span>'); 285jQuery('.projectTab .tabbed-content ul.nav').append('<span class="absoluteNavRight dashicons dashicons-arrow-right"></span>'); 286 287jQuery('.absoluteNavLeft').click(function(){ 288var product_width = '-='+jQuery('.tabbed-content ul.nav li').css('width'); 289jQuery('.tabbed-content ul.nav').animate({ 290 scrollLeft: product_width 291 }, "slow"); 292}); 293 294jQuery('.absoluteNavRight').click(function(){ 295var product_width = '+='+jQuery('.tabbed-content ul.nav li').css('width'); 296jQuery('.tabbed-content ul.nav').animate({ 297 scrollLeft: product_width 298 }, "slow"); 299}); 300 301/*============================================ 302// Custom product search 303============================================*/ 304if(jQuery(".custom-search-form").length){ 305 306 //handle form input 307 let typingTimer; 308 let doneTypingInterval = 1250; 309 let $input = jQuery('.custom-search-form .input-cont input') 310 let formLang = jQuery('.custom-search-form').attr('data-lang') 311 let loadingText = 'Mencari Produk ...' 312 let failedText = 'Gagal menemukan produk.' 313 let notfoundText = 'Produk tidak ditemukan.' 314 if(formLang == 'EN'){ 315 loadingText = 'Searching Product ...' 316 failedText = 'Failed to find product.' 317 notfoundText = 'Product not found.' 318 } 319 //on keyup, start the countdown 320 $input.each(function(){ 321 let val = jQuery(this) 322 val.on('keyup', function () { 323 if (val.val()) { 324 jQuery('.custom-search-form .input-cont .input-result').html('<p class="product-item load">'+loadingText+'</p>') 325 jQuery('.custom-search-form .input-cont .input-result').css('display','flex') 326 }else{ 327 jQuery('.custom-search-form .input-cont .input-result').removeAttr('style') 328 } 329 clearTimeout(typingTimer) 330 typingTimer = setTimeout(doneTyping, doneTypingInterval) 331 }) 332 //on keydown, clear the countdown 333 val.on('keydown', function () { 334 clearTimeout(typingTimer) 335 }) 336 // finish typing 337 function doneTyping () { 338 if (val.val()) { 339 loadResult(val.val(), failedText, notfoundText) 340 } 341 } 342 }) 343 344 const formA = document.forms['custom-search-form'] 345 jQuery('.custom-search-form .address-submit').click(function(){ 346 if(formA.reportValidity()){ 347 let search = jQuery('.custom-search-form').find('#product').val() 348 loadResult(search, failedText) 349 } 350 }) 351} 352 353function loadResult(search, failedText, notfoundText) { 354 jQuery.ajax({ 355 // use the ajax object url 356 url: ajax_object.ajax_url, 357 data: { 358 action: "product_search", // ajax function in php 359 query: search // send value (can mix by jQuery script) 360 }, 361 success: function(data) { 362 if(search==''){ 363 jQuery('.custom-search-form .input-cont .input-result').html('') 364 }else if(data==''){ 365 jQuery('.custom-search-form .input-cont .input-result').html('<p class="product-item load">'+notfoundText+'</p>') 366 }else{ 367 jQuery('.custom-search-form .input-cont .input-result').html('') 368 jQuery('.custom-search-form .input-cont .input-result').html(data) 369 } 370 }, 371 error: function(data) { 372 // test to see what you get back on error 373 jQuery('.custom-search-form .input-cont .input-result').html('<p class="product-item error">'+failedText+'</p>') 374 console.log(data) 375 } 376 }); 377}; 378 379function getGeoAPI() { 380 if (navigator.geolocation) { 381 navigator.geolocation.getCurrentPosition(showPosition); 382 } else { 383 jQuery(".cur-loc-container").html( 384 "Browser anda tidak mendukung untuk fitur ini." 385 ); 386 } 387} 388 389function showPosition(position) { 390 const HERE_API_KEY = "3O06gmsnebTzvJv6IxmoE_IXDAdnIgTa53VpjQL9kfI"; 391 if (position) { 392 fetch( 393 "https://revgeocode.search.hereapi.com/v1/revgeocode?at=" + 394 position.coords.latitude + 395 "%2C" + 396 position.coords.longitude + 397 "&lang=en-US&apiKey=" + 398 HERE_API_KEY 399 ) 400 .then((response) => { 401 return response.json(); 402 }) 403 .then((data) => { 404 const lang = jQuery('.address-form').attr('data-lang'); 405 console.log(lang); 406 407 let locationSlug = ""; 408 if (lang == 'ID') { 409 locationSlug = "/lokasi-dealer/"; 410 } else { 411 locationSlug = "/en/dealer-location/"; 412 } 413 jQuery(".address-form .input-cont .input-result").html(""); 414 window.location = 415 locationSlug + "?address=" + data.items[0].address?.label; 416 }) 417 .catch((error) => { 418 jQuery(".cur-loc-container").html("Gagal memuat lokasi");
419 console.log("catch error: " + error); 420 }); 421 } 422}
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.