summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/node/node.preview.js
diff options
context:
space:
mode:
authorcatch <catch@35733.no-reply.drupal.org>2022-09-09 07:26:42 +0100
committercatch <catch@35733.no-reply.drupal.org>2022-09-09 07:26:42 +0100
commit8aa8ce1ffbcca9c727f46e58c714e1d351f7ef88 (patch)
tree27be6908992c340ba0b4c0bd3f4339670aa71e90 /core/modules/node/node.preview.js
parent09f8f13d8a72b8e482cc689fcd10f023df41b899 (diff)
downloaddrupal-8aa8ce1ffbcca9c727f46e58c714e1d351f7ef88.tar.gz
drupal-8aa8ce1ffbcca9c727f46e58c714e1d351f7ef88.zip
Issue #3278415 by nod_, lauriii, catch, Wim Leers, longwave, xjm, claudiu.cristea: Remove usages of the JavaScript ES6 build step, the build step itself, and associated dev dependencies
Diffstat (limited to 'core/modules/node/node.preview.js')
-rw-r--r--core/modules/node/node.preview.js114
1 files changed, 80 insertions, 34 deletions
diff --git a/core/modules/node/node.preview.js b/core/modules/node/node.preview.js
index dff9d0984629..071d190fd8f3 100644
--- a/core/modules/node/node.preview.js
+++ b/core/modules/node/node.preview.js
@@ -1,34 +1,55 @@
/**
-* DO NOT EDIT THIS FILE.
-* See the following change record for more information,
-* https://www.drupal.org/node/2815083
-* @preserve
-**/
+ * @file
+ * Preview behaviors.
+ */
(function ($, Drupal) {
+ /**
+ * Disables all non-relevant links in node previews.
+ *
+ * Destroys links (except local fragment identifiers such as href="#frag") in
+ * node previews to prevent users from leaving the page.
+ *
+ * @type {Drupal~behavior}
+ *
+ * @prop {Drupal~behaviorAttach} attach
+ * Attaches confirmation prompt for clicking links in node preview mode.
+ * @prop {Drupal~behaviorDetach} detach
+ * Detaches confirmation prompt for clicking links in node preview mode.
+ */
Drupal.behaviors.nodePreviewDestroyLinks = {
attach(context) {
function clickPreviewModal(event) {
- if (event.button === 0 && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
+ // 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();
- const $previewDialog = $(`<div>${Drupal.theme('nodePreviewModal')}</div>`).appendTo('body');
+ const $previewDialog = $(
+ `<div>${Drupal.theme('nodePreviewModal')}</div>`,
+ ).appendTo('body');
Drupal.dialog($previewDialog, {
title: Drupal.t('Leave preview?'),
- buttons: [{
- text: Drupal.t('Cancel'),
-
- click() {
- $(this).dialog('close');
- }
-
- }, {
- text: Drupal.t('Leave preview'),
-
- click() {
- window.top.location.href = event.target.href;
- }
-
- }]
+ buttons: [
+ {
+ text: Drupal.t('Cancel'),
+ click() {
+ $(this).dialog('close');
+ },
+ },
+ {
+ text: Drupal.t('Leave preview'),
+ click() {
+ window.top.location.href = event.target.href;
+ },
+ },
+ ],
}).showModal();
}
}
@@ -36,35 +57,60 @@
if (!context.querySelector('.node-preview-container')) {
return;
}
-
if (once('node-preview', 'html').length) {
- $(document).on('click.preview', 'a:not([href^="#"], .node-preview-container a)', clickPreviewModal);
+ $(document).on(
+ 'click.preview',
+ 'a:not([href^="#"], .node-preview-container a)',
+ clickPreviewModal,
+ );
}
},
-
detach(context, settings, trigger) {
if (trigger === 'unload') {
- if (context.querySelector('.node-preview-container') && once.remove('node-preview', 'html').length) {
+ if (
+ context.querySelector('.node-preview-container') &&
+ once.remove('node-preview', 'html').length
+ ) {
$(document).off('click.preview');
}
}
- }
-
+ },
};
+
+ /**
+ * Switch view mode.
+ *
+ * @type {Drupal~behavior}
+ *
+ * @prop {Drupal~behaviorAttach} attach
+ * Attaches automatic submit on `formUpdated.preview` events.
+ */
Drupal.behaviors.nodePreviewSwitchViewMode = {
attach(context) {
- const autosubmit = once('autosubmit', '[data-drupal-autosubmit]', context);
-
+ const autosubmit = once(
+ 'autosubmit',
+ '[data-drupal-autosubmit]',
+ context,
+ );
if (autosubmit.length) {
$(autosubmit).on('formUpdated.preview', function () {
$(this.form).trigger('submit');
});
}
- }
-
+ },
};
+ /**
+ * Theme function for node preview modal.
+ *
+ * @return {string}
+ * Markup for the node preview modal.
+ */
Drupal.theme.nodePreviewModal = function () {
- return `<p>${Drupal.t('Leaving the preview will cause unsaved changes to be lost. Are you sure you want to leave the preview?')}</p><small class="description">${Drupal.t('CTRL+Left click will prevent this dialog from showing and proceed to the clicked link.')}</small>`;
+ return `<p>${Drupal.t(
+ 'Leaving the preview will cause unsaved changes to be lost. Are you sure you want to leave the preview?',
+ )}</p><small class="description">${Drupal.t(
+ 'CTRL+Left click will prevent this dialog from showing and proceed to the clicked link.',
+ )}</small>`;
};
-})(jQuery, Drupal); \ No newline at end of file
+})(jQuery, Drupal);