summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2018-01-29 12:46:11 (GMT)
committerNathaniel Catchpole2018-01-29 12:46:11 (GMT)
commit3b304d23cc8457cd0c4bc7dc5e554b0707ed7aa6 (patch)
tree2352321c7acf066c18ddc15f6485ce358b81af07
parente455822008faaa9acf466f015db24e46471beed4 (diff)
Issue #2939885 by samuel.mortenson: UX regression (again): Prevent links in node preview from being clicked
-rw-r--r--core/modules/node/node.libraries.yml1
-rw-r--r--core/modules/node/node.preview.es6.js4
-rw-r--r--core/modules/node/node.preview.js4
-rw-r--r--core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php60
4 files changed, 65 insertions, 4 deletions
diff --git a/core/modules/node/node.libraries.yml b/core/modules/node/node.libraries.yml
index 59947a2..a420112 100644
--- a/core/modules/node/node.libraries.yml
+++ b/core/modules/node/node.libraries.yml
@@ -20,6 +20,7 @@ drupal.node.preview:
- core/jquery
- core/jquery.once
- core/drupal
+ - core/drupal.dialog
- core/drupal.form
drupal.content_types:
diff --git a/core/modules/node/node.preview.es6.js b/core/modules/node/node.preview.es6.js
index abd670a..ef67b68 100644
--- a/core/modules/node/node.preview.es6.js
+++ b/core/modules/node/node.preview.es6.js
@@ -45,9 +45,9 @@
}
}
- const $preview = $(context).find('.content').once('node-preview');
+ const $preview = $(context).once('node-preview');
if ($(context).find('.node-preview-container').length) {
- $preview.on('click.preview', 'a:not([href^=#], #edit-backlink, #toolbar-administration a)', clickPreviewModal);
+ $preview.on('click.preview', 'a:not([href^="#"], .node-preview-container a)', clickPreviewModal);
}
},
detach(context, settings, trigger) {
diff --git a/core/modules/node/node.preview.js b/core/modules/node/node.preview.js
index f18af28..60c8dfd 100644
--- a/core/modules/node/node.preview.js
+++ b/core/modules/node/node.preview.js
@@ -29,9 +29,9 @@
}
}
- var $preview = $(context).find('.content').once('node-preview');
+ var $preview = $(context).once('node-preview');
if ($(context).find('.node-preview-container').length) {
- $preview.on('click.preview', 'a:not([href^=#], #edit-backlink, #toolbar-administration a)', clickPreviewModal);
+ $preview.on('click.preview', 'a:not([href^="#"], .node-preview-container a)', clickPreviewModal);
}
},
detach: function detach(context, settings, trigger) {
diff --git a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php
new file mode 100644
index 0000000..8eb7a26
--- /dev/null
+++ b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\Tests\node\FunctionalJavascript;
+
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+
+/**
+ * Tests the JavaScript prevention of navigation away from node previews.
+ *
+ * @group node
+ */
+class NodePreviewLinkTest extends JavascriptTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['node', 'filter'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setUp() {
+ parent::setUp();
+
+ $filtered_html_format = FilterFormat::create([
+ 'format' => 'filtered_html',
+ 'name' => 'Filtered HTML',
+ ]);
+ $filtered_html_format->save();
+
+ $this->drupalCreateContentType(['type' => 'test']);
+
+ $user = $this->drupalCreateUser([
+ 'access content',
+ 'edit own test content',
+ 'create test content',
+ $filtered_html_format->getPermissionName(),
+ ]);
+ $this->drupalLogin($user);
+ }
+
+ /**
+ * Test the behavior of clicking preview links.
+ */
+ public function testPreviewLinks() {
+ $assertSession = $this->assertSession();
+ $this->drupalPostForm('node/add/test', [
+ 'title[0][value]' => 'Test node',
+ 'body[0][value]' => '<a href="#foo">Anchor link</a><a href="/foo">Normal link</a>',
+ ], t('Preview'));
+ $this->clickLink('Anchor link');
+ $assertSession->pageTextNotContains('Leave preview?');
+ $this->clickLink('Normal link');
+ $assertSession->pageTextContains('Leave preview?');
+ $this->click('button:contains("Leave preview")');
+ $this->assertStringEndsWith('/foo', $this->getUrl());
+ }
+
+}