Skip to content

Commit

Permalink
Merge pull request #5550 from Automattic/add/external-url-to-webpreview
Browse files Browse the repository at this point in the history
WebPreview: Allow externalUrl to be set for the external link button
  • Loading branch information
Leif Singer committed May 26, 2016
2 parents 8fb36b6 + fc24a4e commit f5363d1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
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

0 comments on commit f5363d1

Please sign in to comment.