1var multiUploadEnabled = true; 2var DebugInfo = window.location.href.includes("debug=true") || window.location.href.includes("testing"); 3var reuploadImage = false; 4var reuploadImage3D = false; 5var isWindowsOS = navigator.userAgent.indexOf('Windows') !== -1; 6 7/** 8 * Clean up old localStorage entries (imgDims_ and imglyInfo_) older than 30 days 9 * Prevents localStorage from filling up with unused image data 10 */ 11function cleanupOldLocalStorageEntries() { 12 try { 13 var now = Date.now(); 14 var thirtyDaysMs = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds 15 var keysToRemove = []; 16 var debugMode = window.location.href.includes("debug=true"); 17 18 // Scan localStorage for our entries 19 for (var i = 0; i < localStorage.length; i++) { 20 var key = localStorage.key(i); 21 if (!key) continue; 22 23 // Check imgDims_ entries (have timestamp) 24 if (key.startsWith('imgDims_')) { 25 try { 26 var data = JSON.parse(localStorage.getItem(key)); 27 var age = now - (data.timestamp || 0); 28 if (age > thirtyDaysMs) { 29 keysToRemove.push(key); 30 } 31 } catch (e) { 32 // Invalid JSON, remove it 33 keysToRemove.push(key); 34 } 35 } 36 37 // Check imglyInfo_ entries (linked to imgDims_) 38 if (key.startsWith('imglyInfo_')) { 39 var imageId = key.replace('imglyInfo_', ''); 40 var dimsKey = 'imgDims_' + imageId; 41 var dimsData = localStorage.getItem(dimsKey); 42 43 if (!dimsData) { 44 // No corresponding imgDims_, safe to remove 45 keysToRemove.push(key); 46 } else { 47 try { 48 var dims = JSON.parse(dimsData); 49 var age = now - (dims.timestamp || 0); 50 if (age > thirtyDaysMs) { 51 // imgDims is old, remove both 52 keysToRemove.push(key); 53 } 54 } catch (e) { 55 keysToRemove.push(key); 56 } 57 } 58 } 59 } 60 61 // Remove old entries 62 if (keysToRemove.length > 0) { 63 if (debugMode) { 64 console.log('Cleaning up ' + keysToRemove.length + ' old localStorage entries (>30 days old)'); 65 } 66 for (var j = 0; j < keysToRemove.length; j++) { 67 localStorage.removeItem(keysToRemove[j]); 68 } 69 } 70 } catch (error) { 71 console.warn('Failed to cleanup old localStorage entries:', error); 72 } 73} 74 75// Run cleanup once per session (prevents repeated cleanup on every page load
75) 76if (!sessionStorage.getItem('localStorage_cleaned_session')) { 77 cleanupOldLocalStorageEntries(); 78 sessionStorage.setItem('localStorage_cleaned_session', 'true'); 79} 80 81// Function to convert HEIC/HEIF to JPEG - only load when needed 82function loadHeic2Any(callback) { 83 if (typeof heic2any !== 'undefined') { 84 callback(); 85 return; 86 } 87 88 const script = document.createElement('script'); 89 script.src = '/components/file-upload/js/heic2any.min.js'; 90 script.onload = callback; 91 script.onerror = function () { 92 console.error('Failed to load heic2any library'); 93 }; 94 document.head.appendChild(script); 95} 96 97 98var instaConfigRedirectLater = false; 99var instaConfigRedirectUrl = ""; 100 101var mixPixIDs = [ 102 4061, 3239, 3722, 3423, 3438, 4189, 4019, 4179, 3248, 3417, 103 4093, 4152, 4166, 4168, 4238, 4284, 2231, 2236, 2381, 104 2382, 2389, 2393, 2394, 2395, 2396, 2397, 2405, 2406, 2407, 105 2468, 2609, 2695, 2697, 2698, 2711, 2714, 2715, 2736, 2850, 106 2946, 3097 107]; 108 109var mixPixIDsCOS = [ 110 2670 111]; 112 113var memoryGameIDs = [ 114 4298 115]; 116 117var multiImageIDs = [ 118 2728 119]; 120 121var mixBloxIDs = [ 122 2569, 2701, 2702, 2707, 2708, 2710, 2721, 2722, 2723, 2724, 123 2833, 2951, 3126, 3253, 3424, 3426, 3436, 3437, 3467, 3471, 3938, 124 3996, 4277, 4349 125]; 126 127var mixBloxIDsCOS = [ 128 2709 129]; 130 131// Default max upload limit (most products) 132var maxUploadLimit = 25; 133// Product-specific overrides 134var memoryGameUploadLimit = 12; // Foto Memo-Spiel: 12 motifs 135 136// Function to check if the product ID is for multi-upload scenarios 137function isMultiUpload(productId) { 138 return mixPixIDs.includes(productId) || 139 mixPixIDsCOS.includes(productId) || 140 mixBloxIDsCOS.includes(productId) || 141 memoryGameIDs.includes(productId) || 142 multiImageIDs.includes(productId) || 143 mixBloxIDs.includes(productId); 144} 145 146function getMaxUploadLimit(productId) { 147 if (memoryGameIDs.includes(productId)) return memoryGameUploadLimit; 148 return maxUploadLimit; 149} 150 151function SetReuploadImage() { 152 multiUploadEnabled = false; 153 reuploadImage = true; 154 CallUploadButtonEvents(); 155} 156 157function SetReuploadImage3D() { 158 multiUploadEnabled = false; 159 reuploadImage3D = true; 160 CallUploadButtonEvents(); 161} 162 163var SetSingleUploadButtonEvents = function () { 164 multiUploadEnabled = false; 165 CallUploadButtonEvents(); 166} 167 168var CallUploadButtonEvents = function () { 169 170 var uploadButtons = document.querySelectorAll('.direct-upload'), 171 uploadform = $('.js-du'); 172 for (var i = 0; i < uploadButtons.length; i++) { 173 uploadButtons[i].addEventListener('click', function (e) { 174 uploadform.find('.js-du-productid').val(this.dataset.product); 175 uploadform.find('input[type="file"]').trigger('click'); 176 }) 177 } 178 179 if (!$('.js-du').length) return; 180 181 var $file = $('.js-du-file'), 182 $button = $('.js-du-button'), 183 $cover = $('.js-up'), 184 $abort = $('.js-up-abort'), 185 $size = $('.js-up-file-size'), 186 $indicator = $('.js-up-indicator'), 187 $icon = $('.js-up-indicator-icon'), 188 $msgOngoing = $('.js-up-ongoing'), 189 $msgRedirect = $('.js-up-redirect'), 190 $msgPrepare = $('.js-up-prepare'), 191 $percentage = $('.js-up-percentage'), 192 $perc = $('.js-up-percentage-value'); 193 194 var redirectURL = "", 195 inboxItem = "", 196 mainUrl = '/externalAPI?' + 197 'action=uploadImage' + 198 '&jsonExtended=true'; 199 200 var jqXHR = null, 201 isAborted = false, 202 filesCount = 0, 203 uploadSucess = 0, 204 errorTooBig = 0, 205 errorTooMany = 0, 206 errorWrongFile = 0, 207 errorTooSmall = 0, 208 errorOther = 0, 209 errorResolution = 0, 210 uploadData = []; 211 212 if ($cover.is(":visible")) { 213 hideUploader(); 214 } 215 216 if (window.ie <= 9) { 217 $file.css('display', 'none'); 218 $button.on('click', function (e) { 219 window.location = '/singleupload.jsf'; 220 }); 221 } 222 223 $($file).each(function () { 224 var multiUploadEnabledItem = multiUploadEnabled; 225 226 // Check if the parent has specific classes to determine upload settings 227 if ($(this).parents('.js-du').find(".js-up-single").length) { 228 multiUploadEnabledItem = false; // Disable multi-upload for single uploads 229 } else if ($(this).parents('.js-du').find(".js-up-ar").length) { 230 multiUploadEnabledItem = false; // Disable multi-upload for AR uploads 231 } 232 233 // Additional condition to check if a specific attribute is present 234 if ($(this).data('disable-multi-upload')) { 235 multiUploadEnabledItem = false; // Disable multi-upload if the attribute is set 236 } 237 238 // Check the product ID to enforce the maximum limit only for specific IDs 239 var productId = parseInt($(this).parents('.js-du').find('.js-du-productid').val(), 10); // Ensure productId is an integer 240 241 if (multiUploadEnabledItem) { 242 $(this).prop("multiple", true); // Allow multiple file selection 243 $(this).on('change', function () { 244 // Check if the product ID is in the specified arrays 245 if ( 246 mixPixIDs.includes(productId) || 247 mixPixIDsCOS.includes(productId) || 248 memoryGameIDs.includes(productId) || 249 multiImageIDs.includes(productId) || 250 mixBloxIDs.includes(productId) 251 ) { 252 var limit = getMaxUploadLimit(productId); 253 if (this.files.length > limit) { 254 try { $('#fileTooManyDynamic #fileLimitNr').text(limit); } catch (e) {} 255 Modal.open('#fileTooManyDynamic'); // Alert user if limit exceeded 256 $(this).val(''); // Clear the file input 257 } 258 } 259 }); 260 } else { 261 $(this).removeAttr('multiple'); // Remove multiple file selection 262 } 263 264 var $fileClick = $(this), 265 $form = $fileClick.parents('.js-du'), 266 $ar = $form.find('.js-up-ar').val(), 267 $formInput = $form.find('.js-du-file'), 268 $itemsGallery = $form.find('.js-rm-item').val() || 0, 269 $bundleId = $form.find('.js-du-bundleid').val(), 270 finishingId = $form.find('.js-du-finishingid').val(), 271 productId = parseInt($form.find('.js-du-productid').val()), // Ensure productId is an integer 272 discountParam = $form.find('.js-du-discountParam').val(), 273 textFunktion = $form.find('.js-du-textFunktion').val(), 274 externalData = $form.find('input[name=externalData]').val(), 275 filesStart = 0, 276 filesCurrent = 1, 277 file, 278 isCorrectType, 279 isCorrectSize, 280 maxFileSize,
281 maxFileCount, 282 percValueUnit = 0, 283 percValueAll = 0; 284 285 // Assign isMixPixConfig value 286 var isMixPixConfig = $form.data('is-mix-pix-config'); 287 288 // Check if productId is in the mixPixIDs array 289 var isMixPixID = mixPixIDs.includes(productId); 290 291 // Check if productId is in the mixPixIDsCOS array 292 var isMixPixIDCOS = mixPixIDsCOS.includes(productId); 293 294 // Check if productId is in the mixBloxIDsCOS array 295 var isMixBloxIDCOS = mixBloxIDsCOS.includes(productId); 296 297 // Check if productId is in the mixBloxIDs array 298 var isMemoryGameID = memoryGameIDs.includes(productId); 299 300 // Check if productId is in the multiImageIDs array 301 var isMultiImageID = multiImageIDs.includes(productId); 302 303 // Check if productId is in the mixBloxIDs array 304 var isMixBloxID = mixBloxIDs.includes(productId); 305 306 var productId = parseInt($form.find('.js-du-productid').val(), 10) || 0; // Ensure productId is an integer 307 308 $form.find('.js-du-productid').change(function () { 309 productId = parseInt($(this).val(), 10) || 0; // Convert to integer on change 310 isMixPixID = mixPixIDs.includes(productId); 311 isMemoryGameID = memoryGameIDs.includes(productId); 312 isMultiImageID = multiImageIDs.includes(productId); 313 isMixBloxID = mixBloxIDs.includes(productId); 314 }); 315 316 $($form).find('.js-du-file').change(function () { 317 $formInput = $form.find('.js-du-file'); 318 isAborted = false; 319 percValueAll = 0; 320 percValueUnit = 0; 321 322 uploadSucess = 0; 323 filesCurrent = 1; 324 325 errorTooBig = 0; 326 errorTooMany = 0; 327 errorWrongFile = 0; 328 errorTooSmall = 0; 329 errorOther = 0; 330 errorResolution = 0; 331 }); 332 333 uploadData.push($fileClick.fileupload({ 334 url: mainUrl + (isMultiUpload(productId) ? '&addToUploadMultiImage=true' : '') + '&addToInbox=' + multiUploadEnabledItem + '&product=' + productId + (typeof designKey !== 'undefined' ? '&designKey=' + designKey : ''), 335 type: 'POST', 336 dataType: 'json', 337 paramName: 'imageData', 338 change: function (e, data) { 339 if (DebugInfo) console.log("0 - CHANGE"); 340 341 maxFileCount = 100; 342 filesCount = data.files.length; 343 344 if (filesCount > maxFileCount) { 345 errorTooMany++; 346 file = null; 347 isAborted = true; 348 349 CheckErrorOrRedirect(redirectURL, $itemsGallery, $bundleId, $ar, multiUploadEnabledItem, isMixPixConfig, isMixPixID, isMixPixIDCOS, isMixBloxIDCOS, isMixBloxID, isMemoryGameID, isMultiImageID); 350 return; 351 } 352 }, 353 start: function (e, data) { 354 if (DebugInfo) console.log("1 - START"); 355 percValueAll = 0; 356 $msgOngoing.removeClass('-hidden'); 357 $msgPrepare.addClass('-hidden'); 358 $percentage.removeClass('-hidden'); 359 $msgRedirect.addClass('-hidden'); 360 $indicator.removeClass('-indeterminate'); 361 $indicator.css('height', ''); 362 $icon.css('top', ''); 363 }, 364 add: function (e, data) { 365 if (DebugInfo) console.log("2 - ADD"); 366 367 if (discountParam !== undefined) { 368 data.url = mainUrl + '&discountCode=' + discountParam; 369 } else if (externalData !== undefined) { 370 data.url = mainUrl + '&externalData=' + externalData; 371 } 372 373 try { 374 maxFileSize = 62914560; 375 file = data.files[0]; 376 377 // Handle HEIC/HEIF files on Windows 378 if (isWindowsOS && 379 (file.type === 'image/heic' || file.type === 'image/heif' || 380 file.type === 'image/heif-sequence' || file.type === 'image/heic-sequence' || 381 file.name.toLowerCase().endsWith('.heic') || file.name.toLowerCase().endsWith('.heif'))) { 382 383 if (DebugInfo) console.log("Detected HEIC/HEIF file on Windows, attempting conversion"); 384 385 if (typeof showUploaderFake === "function") { 386 showUploaderFake(); 387 } else { 388 showUploader(); 389 } 390 391 // Only load heic2any library when a HEIC/HEIF file is detected on Windows 392 loadHeic2Any(function () { 393 if (DebugInfo) { 394 console.log('heic2any library loaded for Windows HEIC/HEIF conversion'); 395 } 396 convertAndUpload(data, file); 397 }); 398 return; // Stop processing until library is loaded and conversion is complete 399 } 400 401 // Normal processing for non-HEIC files or non-Windows OS 402 isCorrectType = file.type === 'image/jpeg' || 403 file.type === 'image/png' || 404 file.type === 'image/gif' || 405 file.type === 'image/webp' || 406 file.type === 'image/tiff' || 407 file.type === 'image/heif' || 408 file.type === 'image/heic' || 409 file.type === 'image/heif-sequence' || 410 file.type === 'image/heic-sequence'; 411 isCorrectSize = (maxFileSize >= file.size); 412 } catch (e) { 413 console.warn(e); 414 } finally { 415 data.fileInput = $formInput; 416 $size.removeClass("-hidden"); 417 } 418 419 if (!isAborted) { 420 if (isCorrectType && isCorrectSize) { 421 showUploader(); 422 jqXHR = data.submit(); 423 } else { 424 if (!isCorrectType) { 425 errorWrongFile++; 426 } 427 if (!isCorrectSize) { 428 errorTooBig++; 429 } 430 jqXHR = data.abort(); 431 } 432 } 433 434 // Function to convert HEIC/HEIF to JPEG and continue upload 435 function convertAndUpload(data, heicFile) { 436 if (DebugInfo) console.log("Starting HEIC/HEIF conversion"); 437 438 try { 439 heic2any({ 440 blob: heicFile, 441 toType: 'image/jpeg', 442 quality: 0.8 443 }) 444 .then(function (jpegBlob) { 445 if (DebugInfo) console.log("HEIC/HEIF conversion successful"); 446 447 // Create new file with proper type 448 const jpegFile = new File([jpegBlob], 449 heicFile.name.replace(/\.(heic|heif)$/i, '.jpg'), 450 { type: 'image/jpeg' } 451 ); 452 453 // Replace the original file in data.files 454 data.files[0] = jpegFile; 455 file = jpegFile; 456 457 // Re-run validation with converted file 458 isCorrectType = true; // It's now a JPEG 459 isCorrectSize = (maxFileSize >= jpegFile.size); 460 461 if (!isAborted && isCorrectSize) { 462 showUploader(); 463 jqXHR = data.submit(); 464 } else { 465 if (!isCorrectSize) { 466 errorTooBig++; 467 } 468 jqXHR = data.abort(); 469 } 470 }) 471 .catch(function (err) { 472 console.error("HEIC/HEIF conversion failed", err); 473 // If conversion fails, try normal upload and let server handle it 474 isCorrectType = false; // Mark as incorrect type to show proper error 475 errorWrongFile++; 476 jqXHR = data.abort(); 477 }); 478 } catch (err) { 479 console.error("Error during HEIC/HEIF conversion:", err); 480 // If conversion throws error, try normal upload and let server handle it 481 isCorrectType = false; // Mark as incorrect type to show proper error 482 errorWrongFile++; 483 jqXHR = data.abort(); 484 } 485 } 486 }, 487 always: function (e, data) { 488 if (DebugInfo) console.log("3 - ALWAYS"); 489 filesCurrent++; 490 }, 491 progress: function (e, data) { 492 if (DebugInfo) console.log("4 - PROGRESS"); 493 file = data.files[0]; 494 percValueUnit = parseInt(data.loaded / data.total * 100, 10); 495 if (filesCount > 1) { 496 $size.find("small").text(filesCurrent + " / " + filesCount + " - " + formatFileSize(data.loaded) + ' | ' + formatFileSize(data.total) + " (" + percValueUnit + "%)"); 497 } else { 498 $size.find("small").text(formatFileSize(data.loaded) + ' | ' + formatFileSize(data.total)); 499 } 500 }, 501 progressall: function (e, data) { 502 if (DebugInfo) console.log("5 - PROGRESSALL"); 503 percValueAll = parseInt(data.loaded / data.total * 100, 10); 504 $indicator.css('height', (data.loaded / data.total * 150) + 'px'); 505 $icon.css('top', -150 + (data.loaded / data.total * 150) + 'px'); 506 $perc.text(percValueAll); 507 508 if (percValueAll === 100) { 509 $size.addClass("-hidden"); 510 $percentage.addClass('-hidden'); 511 $msgOngoing.addClass('-hidden'); 512 $msgPrepare.removeClass('-hidden'); 513 $msgRedirect.addClass('-hidden'); 514 $indicator.addClass('-indeterminate'); 515 } 516 }, 517 done: function (e, data) { 518 if (DebugInfo) console.log("6 - DONE"); 519 if (data.result.status === 'failure') { 520 errorOther++; 521 } else { 522 uploadSucess++; 523 localStorage.setItem('imglyInfo_' + data.result.imageId, data.result.accessCode); 524 525 // Set dimensions in localStorage 526 // Convert from mm to pixels: pixels = (mm / 25.4) * DPI 527 var pixelWidth = Math.round((data.result.imageWidth / 25.4) * data.result.imageResolutionX); 528 var pixelHeight = Math.round((data.result.imageHeight / 25.4) * data.result.imageResolutionY); 529 530 localStorage.setItem( 531 'imgDims_' + data.result.imageId, 532 JSON.stringify({ 533 width: pixelWidth, 534 height: pixelHeight, 535 resolutionX: data.result.imageResolutionX, 536 resolutionY: data.result.imageResolutionY, 537 timestamp: Date.now() 538 }) 539 ); 540 } 541 542 543 if (!isAborted) { 544 if (!redirectURL && !reuploadImage) { 545 redirectURL = data.result.redirect; 546 try { 547 inboxItem = parseInt(data.result.inboxItem, 10) || 0; // Ensure inboxItem is an integer 548 } catch (err) { } 549 550 if ($form.find('.js-up-url-params').val()) { 551 redirectURL = updateRedirect(redirectURL, $form); 552 } 553 var currentFinishingId = $form.find('.js-du-finishingid').val() || finishingId; 554 if (currentFinishingId) { 555 redirectURL = redirectURL.replace(/[?&]finishing=[^&]*/g, ''); 556 redirectURL = redirectURL + '&finishing=' + encodeURIComponent(currentFinishingId); 557 } 558 if ($form.find('.js-up-other-page-redirect').val()) { 559 redirectURL = otherPageRedirect(redirectURL, $form); 560 } 561 562 if (window.location.href.indexOf('configurator-insta') > -1) { 563 redirectURL = redirectURL.replace(/configurator/ig, 'configurator-insta'); 564 } 565 566 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 567 redirectURL = redirectURL.replace(/\/configurator\.jsf/ig, '/configurator-nv.jsf'); 568 } 569 570 if (window.location.href.indexOf('configurator-mpuk-test') > -1) { 571 redirectURL = redirectURL.replace(/configurator/ig, 'configurator-mpuk-test'); 572 } 573 } 574 if (reuploadImage) { 575 var ImageURL = data.result.redirect; 576 var oldUrl = new URL(ImageURL); 577 var imageId = parseInt(oldUrl.searchParams.get('image'), 10) || 0; // Ensure imageId is an integer 578 changeImage([{ name: 'imageId', value: imageId }]); 579 hideUploader(); 580 } 581 582 if (reuploadImage3D) { 583 var ImageURL = data.result.redirect; 584 var oldUrl = new URL(ImageURL); 585 var imageId = parseInt(oldUrl.searchParams.get('image'), 10) || 0; // Ensure imageId is an integer 586 changeImage([{ name: 'imageId', value: imageId }]); 587 const myArg = document.querySelector("#myAr"); 588 myArg.addEventListener("model-visibility", (event) => { 589 setTimeout(applyTexture, 1000); 590 HideFakePreview(); 591 }, true); 592 hideUploader(); 593 } 594 } 595 }, 596 fail: function (e, data) { 597 if (DebugInfo) console.log("7 - FAIL"); 598 if (data.errorThrown !== 'abort') { 599 $(document).trigger('uploadFail'); 600 601 // Initialize error variables 602 var errorMessage = ""; 603 var errorDetails = ""; 604 var response = null; 605 606 try { 607 // First try to get response from responseJSON 608 if (data.jqXHR && data.jqXHR.responseJSON) { 609 response = data.jqXHR.responseJSON; 610 } 611 // If not available, try to parse responseText 612 else if (data.jqXHR && data.jqXHR.responseText) { 613 response = JSON.parse(data.jqXHR.responseText); 614 } 615 616 if (response) { 617 errorMessage = response.message || ''; 618 errorDetails = response.details && response.details.length > 0 ? response.details[0] : ''; 619 } 620 } catch (err) { 621 // If parsing fails, set default error message 622 errorMessage = "error"; 623 errorDetails = "Image resolution is too low"; 624 console.log("Error parsing response:", err); 625 } 626 627 // Handle different error types 628 if (errorDetails.toLowerCase().includes("bitmap file is invali
628d")) { 629 errorWrongFile++; 630 } else if (errorDetails.toLowerCase().includes("resolution")) { 631 errorResolution++; 632 } else if (errorMessage.toLowerCase().includes("error")) { 633 errorOther++; 634 } else { 635 errorTooSmall++; 636 } 637 638 // Show error modal 639 ShowErrorModal(); 640 hideUploader(); 641 } else { 642 if (filesCount == 1) { 643 ShowErrorModal(); 644 } 645 } 646 return; 647 }, 648 stop: function (e) { 649 if (DebugInfo) console.log("8 - STOP"); 650 $size.addClass("-hidden"); 651 $msgOngoing.addClass('-hidden'); 652 $msgPrepare.addClass('-hidden'); 653 $percentage.addClass('-hidden'); 654 $msgRedirect.removeClass('-hidden'); 655 656 CheckErrorOrRedirect(redirectURL, $itemsGallery, $bundleId, $ar, multiUploadEnabledItem, isMixPixConfig, isMixPixID, isMixPixIDCOS, isMixBloxIDCOS, isMixBloxID, isMemoryGameID, isMultiImageID); 657 } 658 })); 659 660 661 }); 662 663 var ShowErrorModal = function () { 664 if (errorTooBig) { 665 pushErrorTooBig(); 666 if (typeof Modal !== 'undefined' && Modal.open) { 667 Modal.open('#fileTooBig'); 668 } else { 669 $('#fileTooBig').modal('show'); 670 } 671 } else if (errorWrongFile) { 672 pushErrorWrongFile(); 673 if (typeof Modal !== 'undefined' && Modal.open) { 674 Modal.open('#fileWrongType'); 675 } else { 676 $('#fileWrongType').modal('show'); 677 } 678 } else if (errorOther) { 679 pushErrorOther(); 680 if (typeof Modal !== 'undefined' && Modal.open) { 681 Modal.open('#fileUploadError'); 682 } else { 683 $('#fileUploadError').modal('show'); 684 } 685 } else if (errorResolution) { 686 pushErrorResolution(); 687 if (typeof Modal !== 'undefined' && Modal.open) { 688 Modal.open('#fileUploadErrorResolution'); 689 } else { 690 $('#fileUploadErrorResolution').modal('show'); 691 } 692 } else if (errorTooSmall) { 693 pushErrorTooSmall(); 694 if (typeof Modal !== 'undefined' && Modal.open) { 695 Modal.open('#fileTooSmall'); 696 } else { 697 $('#fileTooSmall').modal('show'); 698 } 699 } 700 }; 701 702 var CheckErrorOrRedirect = function (redirectURL, itemsGallery, $bundleId, $ar, multiUploadEnabledItem, isMixPixConfig, isMixPixID, isMixPixIDCOS, isMixBloxIDCOS, isMixBloxID, isMemoryGameID, isMultiImageID) { 703 704 if (errorTooMany) { 705 Modal.open('#fileTooMany'); 706 hideUploader(); 707 return; 708 } 709 710 if (!uploadSucess) { 711 ShowErrorModal(); 712 hideUploader(); 713 return; 714 } 715 716 if (!isAborted) { 717 if (redirectURL != "") { 718 var totalImgRemain = parseInt(filesCount) + parseInt(itemsGallery); 719 var url = redirectURL; 720 if ((window.location.href.indexOf("meinfoto") != -1 || 721 window.location.href.indexOf("my-picture") != -1 || 722 window.location.href.indexOf("canvasdiscount") != -1 || 723 window.location.href.indexOf("monoeuvre") != -1) && 724 !isMixPixConfig && 725 !isMixPixID && 726 !isMixBloxID && 727 !isMemoryGameID && 728 !isMultiImageID) { 729 url += "&imgly=true"; 730 } 731 732 let params = new URLSearchParams(document.location.search); 733 let designKey = params.get("designKey"); 734 735 if (typeof designKey !== 'undefined' && designKey !== null) { 736 url += '&designKey=' + designKey; 737 } 738 739 if (typeof designCategory !== 'undefined') { 740 url += '&designCategory=' + designCategory; 741 } 742 743 if ($bundleId) { 744 url = url.newParamURL("bundleId", $bundleId); 745 } 746 747 if (multiUploadEnabledItem) { 748 console.log('is multi: ' + isMixPixConfig); 749 console.log('is mixpix: ' + isMixPixID); 750 console.log('is mixblox: ' + isMixBloxID); 751 console.log('is memory game: ' + isMemoryGameID); 752 console.log('is multi image: ' + isMultiImageID); 753 754 if (filesCount != 1 && totalImgRemain > 1) { 755 if (errorTooBig) { 756 url = url.newParamURL("errorTooBig", errorTooBig); 757 } 758 if (errorWrongFile) { 759 url = url.newParamURL("errorWrongFile", errorWrongFile); 760 } 761 if (errorTooSmall) { 762 url = url.newParamURL("errorTooSmall", errorTooSmall); 763 } 764 if (errorOther) { 765 url = url.newParamURL("errorOther", errorOther); 766 } 767 if (errorResolution) { 768 url = url.newParamURL("errorResolution", errorResolution); 769 } 770 771 if (isMixPixConfig) { 772 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 773 location.href = url.replace(/configurator-nv/ig, isMixPixConfig); 774 } else { 775 location.href = url.replace(/configurator/ig, isMixPixConfig); 776 } 777 return; 778 } 779 780 if (isMixPixID) { 781 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 782 location.href = url.replace(/configurator-nv/ig, 'multiimage_mixpix'); 783 } else { 784 location.href = url.replace(/configurator/ig, 'multiimage_mixpix'); 785 } 786 return; 787 } 788 if (isMixPixIDCOS) { 789 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 790 location.href = url.replace(/configurator-nv/ig, 'multiimage_phototiles'); 791 } else { 792 location.href = url.replace(/configurator/ig, 'multiimage_phototiles'); 793 } 794 return; 795 } 796 if (isMixBloxIDCOS) { 797 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 798 location.href = url.replace(/configurator-nv/ig, 'multiimage_miniacrylicblock'); 799 } else { 800 location.href = url.replace(/configurator/ig, 'multiimage_miniacrylicblock'); 801 } 802 return; 803 } 804 if (isMixBloxID) { 805 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 806 location.href = url.replace(/configurator-nv/ig, 'multiimage_mixblox'); 807 } else { 808 location.href = url.replace(/configurator/ig, 'multiimage_mixblox'); 809 } 810 return; 811 } 812 if (isMemoryGameID) { 813 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 814 location.href = url.replace(/multiimage-nv/ig, 'multiimage_memorygame'); 815 } else { 816 location.href = url.replace(/multiimage/ig, 'multiimage_memorygame'); 817 } 818 return; 819 } 820 if (isMultiImageID) { 821 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 822 location.href = url.replace(/configurator-nv/ig, 'multiimage'); 823 } else { 824 location.href = url.replace(/configurator/ig, 'multiimage'); 825 } 826 return; 827 } 828 829 $(document).trigger('uploadDone'); 830 831 if (instaConfigRedirectLater == true) { 832 instaConfigRedirectUrl = "/gallery.jsf"; 833 } else { 834 if (window.location.href.indexOf('configurator-insta') > -1) { 835 location.href = url.replace(/configurator-insta/ig, 'gallery'); 836 } else if (window.location.href.indexOf('configurator-mpuk-test') > -1) { 837 location.href = url.replace(/configurator-mpuk-test/ig, 'gallery'); 838 } else if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 839 location.href = url.replace(/configurator-nv/ig, 'gallery'); 840 } else { 841 location.href = url.replace(/configurator/ig, 'gallery'); 842 } 843 } 844 845 return; 846 847 } else { 848 if (isMixPixConfig) { 849 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 850 location.href = url.replace(/configurator-nv/ig, isMixPixConfig); 851 } else { 852 location.href = url.replace(/configurator/ig, isMixPixConfig); 853 } 854 return; 855 } 856 if (isMixPixID) { 857 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 858 location.href = url.replace(/configurator-nv/ig, 'multiimage_mixpix'); 859 } else { 860 location.href = url.replace(/configurator/ig, 'multiimage_mixpix'); 861 } 862 return; 863 } 864 if (isMixPixIDCOS) { 865 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 866 location.href = url.replace(/configurator-nv/ig, 'multiimage_phototiles'); 867 } else { 868 location.href = url.replace(/configurator/ig, 'multiimage_phototiles'); 869 } 870 return; 871 } 872 if (isMixBloxIDCOS) { 873 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 874 location.href = url.replace(/configurator-nv/ig, 'multiimage_miniacrylicblock'); 875 } else { 876 location.href = url.replace(/configurator/ig, 'multiimage_miniacrylicblock'); 877 } 878 return; 879 } 880 if (isMixBloxID) { 881 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 882 location.href = url.replace(/configurator-nv/ig, 'multiimage_mixblox'); 883 } else { 884 location.href = url.replace(/configurator/ig, 'multiimage_mixblox'); 885 } 886 return; 887 } 888 if (isMemoryGameID) { 889 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 890 location.href = url.replace(/multiimage-nv/ig, 'multiimage_memorygame'); 891 } else { 892 location.href = url.replace(/multiimage/ig, 'multiimage_memorygame'); 893 } 894 return; 895 } 896 if (isMultiImageID) { 897 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 898 location.href = url.replace(/configurator-nv/ig, 'multiimage'); 899 } else { 900 location.href = url.replace(/configurator/ig, 'multiimage'); 901 } 902 return; 903 } 904 905 url = url.newParamURL("action", "rm-inbox-item"); 906 url = url.newParamURL("inboxItem", inboxItem); 907 908 $(document).trigger('uploadDone'); 909 910 // Check for VWOnewCONFI variable 911 if (typeof VWOnewCONFI !== 'undefined' && VWOnewCONFI === true) { 912 location.href = url.replace(/\/configurator\.jsf/ig, '/configurator-nv.jsf'); 913 } else { 914 location.href = url; 915 } 916 917 918 return; 919 } 920 921 } else { 922 if ($ar) { 923 AR.onCompleteUploadAr(url); 924 } else { 925 location.href = url; 926 return; 927 } 928 } 929 } 930 } 931 }; 932 933 String.prototype.newParamURL = function (paramName, paramValue) { 934 var newParam = ""; 935 936 if (this.indexOf("?") < 0) { 937 newParam = "?"; 938 } else { 939 newParam = "&"; 940 } 941 942 newParam = newParam + paramName + "=" + paramValue; 943 return this + newParam; 944 }; 945 946 var formatFileSize = function (bytes) { 947 if (typeof bytes !== 'number') { 948 return ''; 949 } 950 if (bytes >= 1000000000) { 951 return (bytes / 1000000000).toFixed(2) + ' GB'; 952 } 953 if (bytes >= 1000000) { 954 return (bytes / 1000000).toFixed(2) + ' MB'; 955 } 956 return (bytes / 1000).toFixed(2) + ' KB'; 957 }; 958 959 function showUploader() { 960 $button.prop('disabled', true); 961 $file.prop('disabled', true); 962 963 $cover.detach().appendTo('body'); 964 965 $("body").addClass("sp-no-js"); 966 967 $cover.addClass('-visible').delay(1).queue(function () { 968 $(this).addClass('-fade-in'); 969 $(this).dequeue(); 970 }); 971 } 972 973 function hideUploader() { 974 $button.prop('disabled', false); 975 $file.prop('disabled', false); 976 977 $("body").removeClass("sp-no-js"); 978 979 $cover.removeClass('-fade-in').delay(200).queue(function () { 980 $(this).removeClass('-visible'); 981 $msgOngoing.removeClass('-hidden'); 982 $msgPrepare.addClass('-hidden'); 983 $percentage.removeClass('-hidden'); 984 $msgRedirect.addClass('-hidden'); 985 $indicator.removeClass('-indeterminate'); 986 $indicator.css('height', ''); 987 $icon.css('top', ''); 988 $(this).dequeue(); 989 }); 990 } 991 992 function updateRedirect(redirectUrl, element) { 993 var params = element.find('.js-up-url-params').val().split('x'), 994 width = params[0], 995 height = params[1]; 996 return redirectUrl + "&formatWidth=" + width + "&formatHeight=" + height; 997 } 998 999 function otherPageRedirect(oldRedirectURL, element) { 1000 var newUrl = element.find('.js-up-other-page-redirect').val(); 1001 var oldUrl = new URL(oldRedirectURL); 1002 var imageId = oldUrl.searchParams.get('image'); 1003 1004 if (newUrl[0] != '/') { 1005 newUrl = '/' + newUrl; 1006 } 1007 1008 return oldUrl.origin + newUrl + '&image=' + imageId; 1009 } 1010 1011 $abort.on('click', function () { 1012 window.stop(); 1013 isAborted = true; 1014 hideUploader(); 1015 jqXHR.abort(); 1016 }); 1017 1018 $file.on('mouseenter mouseleave', function (e) { 1019 if (e.type === 'mouseenter') 1020 $(this).next(".action").addClass('-hover'); 1021 else 1022 $(this).next(".action").removeClass('-hover'); 1023 }); 1024}; 1025 1026$(document).ready(function () { 1027 CallUploadButtonEvents(); 1028}); 1029 1030var CallPreUploadImg = function (productId) { 1031 var productIdDefault = 2566; 1032 try { 1033 if (typeof productId !== "undefined") { 1034 productIdDefault = productId; 1035 } 1036 } catch (err) { } 1037 1038 CallPreUpload("init_gray.jpg", productIdDefault); 1039}; 1040 1041var CallPreUploadImgMulti = function (productId, galleryItem, image) { 1042 location.href = "/configurator.jsf?product=" + productId + "&galleryItem=" + galleryItem + "&image=" + image; 1043}; 1044 1045var CallPreUpload = function (ImageName, productId, preImg) { 1046 showUploaderFake(); 1047 $.ajax({ 1048 url: "/externalAPI?image=" + window.location.origin.toLowerCase().replace("testing", "www") + "/assets/img/checkout/configurator/shapy/" + ImageName + "&action=uploadImage&product=" + productId + "&shared=true&addToUploadMultiImage=true&json", 1049 dataType: "json", 1050 contentType: "application/json", 1051 success: function (jsonSuccess) { 1052 var url = jsonSuccess.redirect; 1053 url = url + "&init=true"; 1054 location.href = url; 1055 }, 1056 error: function (jsonError) { 1057 console.log(jsonError); 1058 hideUploaderFake(); 1059 } 1060 }); 1061}; 1062 1063var CallCMSPreUpload = function (productId, preImg) { 1064 showUploaderFake(); 1065 $.ajax({ 1066 url: "/externalAPI?image=" + preImg + "&action=uploadImage&product=" + productId + "&shared=true&addToUploadMultiImage=true&json", 1067 dataType: "json", 1068 contentType: "application/json", 1069 success: function (jsonSuccess) { 1070 var url = jsonSuccess.redirect; 1071 url = url + "&init=true"; 1072 location.href = url; 1073 }, 1074 error: function (jsonError) { 1075 console.log(jsonError); 1076 hideUploaderFake(); 1077 } 1078 }); 1079}; 1080 1081var onUploadCompleteShapy = function (component) { 1082 var multiple = false;
1083 var missedFiles = component.files.length; 1084 if (missedFiles == 0) { 1085 redirectOrError(); 1086 } 1087}; 1088 1089var onUploadCompleteMaskLP = function (component) { 1090 var multiple = false; 1091 var missedFiles = component.files.length; 1092 if (missedFiles == 0) { 1093 redirectOrError(); 1094 } 1095}; 1096 1097var onUploadCompleteMaskConfigurator = function (component) { 1098 var multiple = false; 1099 var missedFiles = component.files.length; 1100 if (missedFiles == 0) { 1101 ForceUploadTabTrue(); 1102 changeToUnusedInboxItem(); 1103 } 1104}; 1105 1106var onUploadCompleteShapix = function (component) { 1107 var multiple = false; 1108 var missedFiles = component.files.length; 1109 if (missedFiles == 0) { 1110 changeToUnusedInboxItem(); 1111 } 1112}; 1113 1114window.onpageshow = function (event) { 1115 if (event.persisted) { 1116 CallUploadButtonEvents(); 1117 } 1118};
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.