]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/ui/components/embed_modal.js
1 import React
from 'react';
2 import PropTypes
from 'prop-types';
3 import ImmutablePureComponent
from 'react-immutable-pure-component';
4 import { FormattedMessage
, injectIntl
} from 'react-intl';
5 import axios
from 'axios';
8 export default class EmbedModal
extends ImmutablePureComponent
{
11 url: PropTypes
.string
.isRequired
,
12 onClose: PropTypes
.func
.isRequired
,
13 intl: PropTypes
.object
.isRequired
,
21 componentDidMount () {
22 const { url
} = this.props
;
24 this.setState({ loading: true });
26 axios
.post('/api/web/embed', { url
}).then(res
=> {
27 this.setState({ loading: false, oembed: res
.data
});
29 const iframeDocument
= this.iframe
.contentWindow
.document
;
31 iframeDocument
.open();
32 iframeDocument
.write(res
.data
.html
);
33 iframeDocument
.close();
35 iframeDocument
.body
.style
.margin
= 0;
36 this.iframe
.width
= iframeDocument
.body
.scrollWidth
;
37 this.iframe
.height
= iframeDocument
.body
.scrollHeight
;
45 handleTextareaClick
= (e
) => {
50 const { oembed
} = this.state
;
53 <div className
='modal-root__modal embed-modal'>
54 <h4
><FormattedMessage id
='status.embed' defaultMessage
='Embed' /></h4
>
56 <div className
='embed-modal__container'>
58 <FormattedMessage id
='embed.instructions' defaultMessage
='Embed this status on your website by copying the code below.' />
63 className
='embed-modal__html'
65 value
={oembed
&& oembed
.html
|| ''}
66 onClick
={this.handleTextareaClick
}
70 <FormattedMessage id
='embed.preview' defaultMessage
='Here is what it will look like:' />
74 className
='embed-modal__iframe'
76 ref
={this.setIframeRef
}
This page took 0.094294 seconds and 5 git commands to generate.