| 1 |
/** |
| 2 |
* Renders a non-dismissible warning notice inside Gutenberg |
| 3 |
* when a post/page references a legacy Kit resource. |
| 4 |
* |
| 5 |
* @author ConvertKit |
| 6 |
* @since 3.3.7 |
| 7 |
*/ |
| 8 |
|
| 9 |
document.addEventListener('DOMContentLoaded', function () { |
| 10 |
// Bail if the notice data is not available. |
| 11 |
if (typeof convertkit_legacy_resource_notice === 'undefined') { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
// Bail if no warnings are found. |
| 16 |
if ( |
| 17 |
typeof convertkit_legacy_resource_notice.warnings === 'undefined' || |
| 18 |
convertkit_legacy_resource_notice.warnings.length === 0 |
| 19 |
) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
// Bail if Gutenberg is not available. |
| 24 |
if ( |
| 25 |
typeof wp === 'undefined' || |
| 26 |
typeof wp.data === 'undefined' || |
| 27 |
typeof wp.data.dispatch !== 'function' |
| 28 |
) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
// Build the notice. |
| 33 |
// Gutenberg's Notice component renders `message` as plain text with |
| 34 |
// `white-space: normal`, so `\n` collapses to a space and any leading |
| 35 |
// `- ` dashes look odd. Inline the items with `; ` separators instead — |
| 36 |
// this reads naturally on the single line the component actually renders. |
| 37 |
const message = |
| 38 |
convertkit_legacy_resource_notice.intro + |
| 39 |
' ' + |
| 40 |
convertkit_legacy_resource_notice.warnings.join('; '); |
| 41 |
|
| 42 |
// Create the notice. |
| 43 |
wp.data.dispatch('core/notices').createWarningNotice(message, { |
| 44 |
id: convertkit_legacy_resource_notice.id, |
| 45 |
isDismissible: false, |
| 46 |
}); |
| 47 |
}); |
| 48 |
|