PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.7.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.7.0
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / Gutenberg / src / document / edit.js
embedpress / Gutenberg / src / document Last commit date
edit.js 5 years ago editor.scss 5 years ago index.js 5 years ago style.scss 5 years ago
edit.js
237 lines
1 /**
2 * Internal dependencies
3 */
4
5 import Iframe from '../common/Iframe';
6 import EmbedLoading from '../common/embed-loading';
7 /**
8 * WordPress dependencies
9 */
10
11 const {__} = wp.i18n;
12 const {getBlobByURL, isBlobURL, revokeBlobURL} = wp.blob;
13 const {BlockIcon, MediaPlaceholder ,InspectorControls} = wp.editor;
14 const {Component, Fragment} = wp.element;
15 const { RangeControl,PanelBody, ExternalLink,ToggleControl } = wp.components;
16 import {DocumentIcon} from '../common/icons'
17
18 const ALLOWED_MEDIA_TYPES = [
19 'application/pdf',
20 'application/msword',
21 'application/vnd.ms-powerpoint',
22 'application/vnd.ms-excel',
23 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
24 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
25 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
26 ];
27
28 class DocumentEdit extends Component {
29 constructor() {
30 super(...arguments);
31 this.onSelectFile = this.onSelectFile.bind(this);
32
33 this.onUploadError = this.onUploadError.bind(this);
34 this.onLoad = this.onLoad.bind(this);
35 this.hideOverlay = this.hideOverlay.bind(this);
36 this.state = {
37 hasError: false,
38 fetching:false,
39 interactive: false,
40 loadPdf: true,
41 };
42 }
43
44
45 componentDidMount() {
46 const {
47 attributes,
48 mediaUpload,
49 noticeOperations
50 } = this.props;
51 const {href} = attributes;
52
53 // Upload a file drag-and-dropped into the editor
54 if (isBlobURL(href)) {
55 const file = getBlobByURL(href);
56
57 mediaUpload({
58 filesList: [file],
59 onFileChange: ([media]) => this.onSelectFile(media),
60 onError: (message) => {
61 this.setState({hasError: true});
62 noticeOperations.createErrorNotice(message);
63 },
64 });
65
66 revokeBlobURL(href);
67 }
68
69 if(this.props.attributes.href && this.props.attributes.mime === 'application/pdf' && this.state.loadPdf){
70 this.setState({loadPdf: false});
71 PDFObject.embed(this.props.attributes.href, "."+this.props.attributes.id);
72 }
73
74 }
75
76 componentDidUpdate(prevProps) {
77
78 // Reset copy confirmation state when block is deselected
79 if (prevProps.isSelected && !this.props.isSelected) {
80 this.setState({showCopyConfirmation: false});
81 }
82
83 }
84
85 static getDerivedStateFromProps(nextProps, state) {
86 if (!nextProps.isSelected && state.interactive) {
87 return {interactive: false};
88 }
89
90 return null;
91 }
92
93 hideOverlay() {
94 this.setState({interactive: true});
95 }
96
97 onLoad() {
98 this.setState({
99 fetching:false
100 })
101 }
102
103 onSelectFile(media) {
104 if (media && media.url) {
105 this.setState({hasError: false});
106 this.props.setAttributes({
107 href: media.url,
108 fileName: media.title,
109 id: 'embedpress-pdf-'+Date.now(),
110 mime: media.mime,
111 });
112
113 if(embedpressObj.embedpress_pro){
114 this.props.setAttributes({
115 powered_by: false
116 });
117 }
118 if(media.mime === 'application/pdf'){
119 this.setState({loadPdf: false});
120 PDFObject.embed(media.url, "."+this.props.attributes.id);
121 }
122 }
123
124 }
125
126 onUploadError(message) {
127 const {noticeOperations} = this.props;
128 noticeOperations.removeAllNotices();
129 noticeOperations.createErrorNotice(message);
130 }
131
132
133
134
135 render() {
136 const {attributes, noticeUI,setAttributes} = this.props;
137 const {href,mime,id,width,height,powered_by} = attributes;
138 const {hasError,interactive,fetching,loadPdf} = this.state;
139 const min = 1;
140 const max = 1000;
141 const docLink = 'https://embedpress.com/docs/embed-docuemnt/'
142 if (!href || hasError) {
143
144 return (
145 <div className={"embedpress-document-editmode"}>
146 <MediaPlaceholder
147 icon={<BlockIcon icon={DocumentIcon}/>}
148 labels={{
149 title: __('Document'),
150 instructions: __(
151 'Upload a file or pick one from your media library for embed.'
152 ),
153 }}
154 onSelect={this.onSelectFile}
155 notices={noticeUI}
156 allowedTypes={ALLOWED_MEDIA_TYPES}
157 onError={this.onUploadError}
158
159 >
160
161 <div style={{width:'100%'}} className="components-placeholder__learn-more embedpress-doc-link">
162 <ExternalLink href={docLink}>Learn more about Embedded document </ExternalLink>
163 </div>
164 </MediaPlaceholder>
165
166 </div>
167
168 );
169 } else {
170 const url = '//view.officeapps.live.com/op/embed.aspx?src='+href;
171 return (
172 <Fragment>
173 {(fetching && mime !== 'application/pdf') ? <EmbedLoading/> : null}
174 { mime === 'application/pdf' && (
175 <div style={{height:height,width:width}} className={'embedpress-embed-document-pdf'+' '+id} data-emid={id} data-emsrc={href}></div>
176
177 ) }
178 { mime !== 'application/pdf' && (
179 <Iframe onMouseUponMouseUp={ this.hideOverlay } style={{height:height,width:width,display: fetching || !loadPdf ? 'none' : ''}} onLoad={this.onLoad} src={url}
180 mozallowfullscreen="true" webkitallowfullscreen="true"/>
181 ) }
182 { ! interactive && (
183 <div
184 className="block-library-embed__interactive-overlay"
185 onMouseUp={ this.hideOverlay }
186 />
187 ) }
188 { powered_by && (
189 <p className="embedpress-el-powered">Powered By EmbedPress</p>
190 )}
191
192 <InspectorControls key="inspector">
193 <PanelBody
194 title={ __( 'Embed Size', 'embedpress' ) }
195 >
196 <RangeControl
197 label={ __(
198 'Width',
199 'embedpress'
200 ) }
201 value={ width }
202 onChange={ ( width ) =>
203 setAttributes( { width } )
204 }
205 max={ max }
206 min={ min }
207 />
208 <RangeControl
209 label={ __(
210 'Height',
211 'embedpress'
212 ) }
213 value={height }
214 onChange={ ( height ) =>
215 setAttributes( { height } )
216 }
217 max={ max }
218 min={ min }
219 />
220 <ToggleControl
221 label={ __( 'Powered By' ) }
222 onChange={ ( powered_by ) =>
223 setAttributes( { powered_by } )
224 }
225 checked={ powered_by }
226 />
227 </PanelBody>
228 </InspectorControls>
229 </Fragment>
230 );
231 }
232
233 }
234
235 };
236 export default DocumentEdit;
237