diff --git a/core/modules/node/node.preview.js b/core/modules/node/node.preview.js index f864179..2cd1b04 100644 --- a/core/modules/node/node.preview.js +++ b/core/modules/node/node.preview.js @@ -8,41 +8,44 @@ "use strict"; /** - * Provides a modal confirmation before leaving node previews. + * Provides a modal confirmation before leaving a node preview. */ Drupal.behaviors.nodePreviewDestroyLinks = { attach: function (context) { // Display a modal confirmation for all links within preview, except // for local fragment identifiers such as href="#frag". - $('a:not([href^=#])', context).on('click.preview', function (event) { + $(context).find('.node').on('click.preview', 'a:not([href^=#])', function (event) { // Only confirm leaving previews when left-clicking and user is not // pressing the ALT, CTRL, META (Command key on the Macintosh keyboard) // or SHIFT key. if (event.button === 0 && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) { event.preventDefault(); - event.stopPropagation(); - var previewElementId = 'node-preview-dialog'; - // Create the preview dialog element. - $('

' + Drupal.t('Are you sure you want to leave the preview? If you navigate away without saving, your changes will be lost.') + '

').appendTo('body'); - var dialogOptions = { + var $previewDialog = $('
') + .text(Drupal.t('Leaving the preview will cause unsaved changes to be lost. Are you sure you want to leave the preview?')) + .appendTo('body'); + Drupal.dialog($previewDialog, { title: Drupal.t('Leave preview?'), - buttons: { - Cancel: function() { - $(this).dialog('close'); + buttons: [ + { + text: Drupal.t('Cancel'), + click: function() { + $(this).dialog('close'); + } }, - 'Leave preview': function() { - window.top.location.href = event.target.href; + { + text: Drupal.t('Leave preview'), + click: function() { + window.top.location.href = event.target.href; + } } - } - }; - var previewDialog = Drupal.dialog('#' + previewElementId, dialogOptions); - previewDialog.showModal(); + ] + }).showModal(); } }); }, detach: function (context, settings, trigger) { if (trigger === 'unload') { - $('a:not([href^=#])', context).off('click.preview'); + $(context).find('.node').off('click.preview', 'a:not([href^=#])'); } } };