node.preview.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. Drupal.behaviors.nodePreviewDestroyLinks = {
  9. attach: function attach(context) {
  10. function clickPreviewModal(event) {
  11. if (event.button === 0 && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
  12. event.preventDefault();
  13. var $previewDialog = $('<div>' + Drupal.theme('nodePreviewModal') + '</div>').appendTo('body');
  14. Drupal.dialog($previewDialog, {
  15. title: Drupal.t('Leave preview?'),
  16. buttons: [{
  17. text: Drupal.t('Cancel'),
  18. click: function click() {
  19. $(this).dialog('close');
  20. }
  21. }, {
  22. text: Drupal.t('Leave preview'),
  23. click: function click() {
  24. window.top.location.href = event.target.href;
  25. }
  26. }]
  27. }).showModal();
  28. }
  29. }
  30. var $preview = $(context).once('node-preview');
  31. if ($(context).find('.node-preview-container').length) {
  32. $preview.on('click.preview', 'a:not([href^="#"], .node-preview-container a)', clickPreviewModal);
  33. }
  34. },
  35. detach: function detach(context, settings, trigger) {
  36. if (trigger === 'unload') {
  37. var $preview = $(context).find('.content').removeOnce('node-preview');
  38. if ($preview.length) {
  39. $preview.off('click.preview');
  40. }
  41. }
  42. }
  43. };
  44. Drupal.behaviors.nodePreviewSwitchViewMode = {
  45. attach: function attach(context) {
  46. var $autosubmit = $(context).find('[data-drupal-autosubmit]').once('autosubmit');
  47. if ($autosubmit.length) {
  48. $autosubmit.on('formUpdated.preview', function () {
  49. $(this.form).trigger('submit');
  50. });
  51. }
  52. }
  53. };
  54. Drupal.theme.nodePreviewModal = function () {
  55. 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>';
  56. };
  57. })(jQuery, Drupal);