Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebPreview: Allow externalUrl to be set for the external link button #5550

Merged
merged 1 commit into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/components/web-preview/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const WebPreview = React.createClass( {
showDeviceSwitcher: React.PropTypes.bool,
// The URL that should be displayed in the iframe
previewUrl: React.PropTypes.string,
// The URL for the external link button
externalUrl: React.PropTypes.string,
// The markup to display in the iframe
previewMarkup: React.PropTypes.string,
// The viewport device to show initially
Expand Down Expand Up @@ -61,7 +63,7 @@ const WebPreview = React.createClass( {
previewMarkup: null,
onLoad: noop,
onClose: noop,
}
};
},

getInitialState() {
Expand Down
2 changes: 1 addition & 1 deletion client/components/web-preview/toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PreviewToolbar = React.createClass( {
</button>
}
{ this.props.showExternal &&
<a className="web-preview__external" href={ this.props.previewUrl } target="_blank">
<a className="web-preview__external" href={ this.props.externalUrl || this.props.previewUrl } target="_blank">
<Gridicon icon="external" />
</a>
}
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/design-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const DesignPreview = React.createClass( {
<WebPreview
className={ this.props.className }
previewUrl={ useEndpoint ? null : this.getPreviewUrl( this.props.selectedSite ) }
externalUrl={ this.props.selectedSite ? this.props.selectedSite.URL : null }
showExternal={ true }
showClose={ this.props.showClose }
showPreview={ this.props.showPreview }
Expand Down
18 changes: 15 additions & 3 deletions client/post-editor/editor-preview/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* External dependencies
*/
const React = require( 'react' ),
url = require( 'url' );
import React from 'react';
import url from 'url';
import omit from 'lodash/omit';

/**
* Internal dependencies
*/
const WebPreview = require( 'components/web-preview' );
import WebPreview from 'components/web-preview';

const EditorPreview = React.createClass( {

Expand Down Expand Up @@ -79,13 +80,24 @@ const EditorPreview = React.createClass( {
return url.format( parsed );
},

cleanExternalUrl( externalUrl ) {
if ( ! externalUrl ) {
return null;
}
const parsed = url.parse( externalUrl, true );
parsed.query = omit( parsed.query, 'preview', 'iframe', 'frame-nonce' );
delete parsed.search;
return url.format( parsed );
},

render() {
return (
<WebPreview
showPreview={ this.props.showPreview }
defaultViewportDevice="tablet"
onClose={ this.props.onClose }
previewUrl={ this.state.iframeUrl }
externalUrl={ this.cleanExternalUrl( this.props.externalUrl ) }
loadingMessage="Beep beep boop…"
/>
);
Expand Down
1 change: 1 addition & 0 deletions client/post-editor/post-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ const PostEditor = React.createClass( {
isSaving={ this.state.isSaving || this.state.isAutosaving }
isLoading={ this.state.isLoading }
previewUrl={ this.state.previewUrl }
externalUrl={ this.state.previewUrl }
/>
: null }
</div>
Expand Down