|
329 | 329 | } |
330 | 330 | }); |
331 | 331 |
|
332 | | - function alertPatch(message) { |
| 332 | + function alertPatch(message, titleText) { |
333 | 333 | // Create the modal container |
334 | 334 | const modal = document.createElement('div'); |
335 | 335 | modal.style.position = 'fixed'; |
|
354 | 354 |
|
355 | 355 | // Add title to the modal with the current page URL |
356 | 356 | const title = document.createElement('h3'); |
357 | | - title.textContent = "alert"; // not translated as window.alert is same in all languages. |
| 357 | + title.textContent = titleText || "alert"; // not translated as window.alert is same in all languages. |
358 | 358 | title.style.marginBottom = '10px'; |
359 | 359 |
|
360 | 360 | // Add text to the modal |
|
384 | 384 | document.body.appendChild(modal); |
385 | 385 | } |
386 | 386 |
|
387 | | - function unsupported() { |
388 | | - alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM); |
| 387 | + function unsupportedConfirm() { |
| 388 | + alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM, "window.confirm"); |
| 389 | + } |
| 390 | + function unsupportedPrompt() { |
| 391 | + alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM, "window.prompt"); |
389 | 392 | } |
390 | 393 |
|
391 | 394 | // all externally opened live previews have the phcodeLivePreview="true" query string parameter set. |
|
395 | 398 | const isTauri = TRANSPORT_CONFIG.IS_NATIVE_APP; |
396 | 399 | const platform = TRANSPORT_CONFIG.PLATFORM; |
397 | 400 |
|
398 | | - let alertQueue = [], confirmOrPromptCalled = false; |
| 401 | + let alertQueue = [], confirmCalled = false, promptCalled = false; |
399 | 402 | let addToQueue = true; |
400 | 403 | if(!isExternalBrowser){ |
401 | 404 | // this is an embedded iframe we always take hold of the alert api for better ux within the live preivew frame. |
|
411 | 414 | window.confirm = function () { |
412 | 415 | // confirm and prompt is no-op in mac, we just need to show that the api is not supported, so we just |
413 | 416 | // keep a flag. |
414 | | - confirmOrPromptCalled = true; |
| 417 | + confirmCalled = true; |
415 | 418 | }; |
416 | 419 | window.prompt = function () { |
417 | | - confirmOrPromptCalled = true; |
| 420 | + promptCalled = true; |
418 | 421 | }; |
419 | 422 | function drainAlertQueues() { |
420 | 423 | addToQueue = false; |
421 | | - if(confirmOrPromptCalled) { |
422 | | - unsupported(); |
| 424 | + if(confirmCalled) { |
| 425 | + unsupportedConfirm(); |
| 426 | + } |
| 427 | + if(promptCalled) { |
| 428 | + unsupportedPrompt(); |
423 | 429 | } |
424 | 430 | for(let i=0; i<alertQueue.length; i++) { |
425 | 431 | alertPatch(alertQueue[i]); |
426 | 432 | } |
427 | 433 | alertQueue = []; |
428 | 434 | window.alert = alertPatch; |
429 | | - window.confirm = unsupported; |
430 | | - window.prompt = unsupported; |
| 435 | + window.confirm = unsupportedConfirm; |
| 436 | + window.prompt = unsupportedPrompt; |
431 | 437 | } |
432 | 438 |
|
433 | 439 | document.addEventListener('DOMContentLoaded', function() { |
|
0 commit comments