PluginProbe
CodePen Embed Block / trunk
CodePen Embed Block vtrunk
codepen-embed-block / src / utils / getPenHTML.js

getPenHTML.js in CodePen Embed Block trunk, at src/utils/getPenHTML.js

70 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import { __ } from "@wordpress/i18n";
5
6 /**
7 * Internal dependencies
8 */
9 import getNewEditorCheck from "./getNewEditorCheck";
10
11 export default function getPenHTML(attributes) {
12 const {
13 penID,
14 penTheme,
15 penHeight,
16 penURL,
17 penType,
18 clickToLoad,
19 editable,
20 isEditorURL,
21 } = attributes;
22
23 if (penID === null && penURL === "") {
24 return null;
25 }
26
27 if (null === penID) {
28 return (
29 <p className="codepen error" style={{ textAlign: "center" }}>
30 {__("The pen URL is invalid.")}
31 </p>
32 );
33 }
34
35 let embedUrlPrefix = "//codepen.io/anon/embed";
36 if (isEditorURL || getNewEditorCheck(penURL)) {
37 embedUrlPrefix = "//codepen.io/editor/anon/embed";
38 }
39 if (clickToLoad) {
40 embedUrlPrefix += "/preview";
41 }
42
43 let src = `${embedUrlPrefix}/${penID}?height=${penHeight}&theme-id=${penTheme}&slug-hash=${penID}&default-tab=${penType}`;
44
45 if (editable) {
46 src += "&editable=true";
47 }
48
49 return (
50 <div className="cp_embed_wrapper">
51 <iframe
52 id={`cp_embed_${penID}`}
53 src={src}
54 height={penHeight}
55 scrolling="no"
56 frameborder="0"
57 allowTransparency={true}
58 allowFullScreen={true}
59 allowPaymentRequest="true"
60 name={`CodePen Embed ${penID}`}
61 title={`CodePen Embed ${penID}`}
62 className={"cp_embed_iframe"}
63 style={{ width: "100%", overflow: "hidden" }}
64 >
65 CodePen Embed Fallback
66 </iframe>
67 </div>
68 );
69 }
70