X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fnode%2Fnode.preview.es6.js;fp=web%2Fcore%2Fmodules%2Fnode%2Fnode.preview.es6.js;h=abd670acf80c4030a68d732a27ea2d0bf858a906;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/node/node.preview.es6.js b/web/core/modules/node/node.preview.es6.js new file mode 100644 index 000000000..abd670acf --- /dev/null +++ b/web/core/modules/node/node.preview.es6.js @@ -0,0 +1,94 @@ +/** + * @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) { + // 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 = $(`
${ + Drupal.t('Leaving the preview will cause unsaved changes to be lost. Are you sure you want to leave the preview?') + }
${ + Drupal.t('CTRL+Left click will prevent this dialog from showing and proceed to the clicked link.')}`; + }; +}(jQuery, Drupal));