From 7658b07caed34eb6795b99ae5c36f7763628566a Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Jun 2018 14:54:46 -0400 Subject: [PATCH] Preview Button: Use preview link as href if available --- editor/components/post-preview-button/index.js | 13 ++++++++++--- editor/components/post-preview-button/test/index.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/editor/components/post-preview-button/index.js b/editor/components/post-preview-button/index.js index d0ad6111bf663..bda9f811babb4 100644 --- a/editor/components/post-preview-button/index.js +++ b/editor/components/post-preview-button/index.js @@ -50,12 +50,19 @@ export class PostPreviewButton extends Component { } saveForPreview( event ) { - const { isDirty, isNew } = this.props; + const { previewLink, isDirty, isNew } = this.props; + // Let default link behavior occur if no changes to saved post if ( ! isDirty && ! isNew ) { return; } + // Likewise, if a preview URL is available and already assigned as + // the href of the clicked link, there's no need for the interstitial. + if ( previewLink && event.target.href === previewLink ) { + return; + } + // Save post prior to opening window this.props.autosave(); @@ -100,13 +107,13 @@ export class PostPreviewButton extends Component { } render() { - const { currentPostLink, isSaveable } = this.props; + const { previewLink, currentPostLink, isSaveable } = this.props; return (