Skip to content

Commit 9e68af0

Browse files
committed
iframing things up
1 parent ee5f2e2 commit 9e68af0

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"less": "^2.7.1",
2222
"less-loader": "^2.2.3",
2323
"mocha": "^2.4.5",
24+
"raw-loader": "^0.5.1",
2425
"sinon": "^1.17.4",
2526
"style-loader": "^0.13.1",
2627
"tape": "^4.5.1",
@@ -33,10 +34,12 @@
3334
"enzyme": "^2.3.0",
3435
"history": "^2.1.1",
3536
"lodash": "^4.12.0",
37+
"iframe-resizer": "^3.5.3",
3638
"myro": "^0.6.2",
3739
"react": "^15.0.2",
3840
"react-addons-test-utils": "^15.0.2",
3941
"react-dom": "^15.0.2",
42+
"react-frame-component": "^0.6.1",
4043
"react-hot-loader": "^3.0.0-alpha.8",
4144
"showdown": "^1.3.0"
4245
}

src/Container.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class Container extends Component {
4949
: <div className="react-cards-menu">
5050
<CardList>
5151
{map(namespaces, (namespace, key) => (
52-
<Card key={key}>
52+
<Card key={key} noframe>
5353
<a className={style.nav} href={ routes.namespace({ namespace: key }) }>
5454
{ key }
5555
</a>
@@ -62,7 +62,7 @@ export default class Container extends Component {
6262
}
6363
renderNavCard(routes, ns) {
6464
return (
65-
<Card key='navcard'>
65+
<Card key='navcard' noframe>
6666
<div className={style.navCrumbs}>
6767
<a href={ routes.index() }>home</a>
6868
&nbsp;/&nbsp;

src/components.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import React from 'react'
1+
import React ,{Component} from 'react'
2+
import ReactDOM from 'react-dom'
23
import showdown from 'showdown'
34
import style from './style.less'
5+
import Frame from 'react-frame-component'
6+
import {iframeResizer} from 'iframe-resizer'
7+
import iframeResizerContentWindow from 'raw!iframe-resizer/js/iframeResizer.contentWindow.min'
48

59
const markdownToHtml = str => {
610
const conv = new showdown.Converter()
@@ -20,13 +24,48 @@ export const CardList = (props) => (
2024
</div>
2125
)
2226

23-
export const Card = (props) => (
24-
<div className={"reactcards-card "+style.card}>
25-
{props.title ? <CardHeader>{props.title}</CardHeader> : null}
26-
{props.doc ? <Markdown className={style.markdownDoc}>{props.doc}</Markdown> : null}
27-
{props.children}
28-
</div>
27+
export const MarkdownCard = (props) => (
28+
<Card><Markdown>{props.children}</Markdown></Card>
2929
)
3030

31-
export const MarkdownCard = (props) =>
32-
<Card><Markdown>{props.children}</Markdown></Card>
31+
export class Card extends Component {
32+
constructor(props) {
33+
super(props)
34+
}
35+
36+
componentDidMount() {
37+
if (!this.props.noframe) {
38+
this.iframeNode = ReactDOM.findDOMNode(this.refs.iframe)
39+
iframeResizer({checkOrigin:false},this.iframeNode)
40+
}
41+
}
42+
43+
componentWillUnmount(){
44+
if (!this.props.noframe) {
45+
this.iframeNode.iFrameResizer.close()
46+
}
47+
}
48+
49+
render() {
50+
const props = this.props;
51+
const iframeContent = `<!DOCTYPE html>
52+
<html>
53+
<head><script>${iframeResizerContentWindow}</script></head>
54+
<body><div id="content"></div></body>
55+
</html>`
56+
return (
57+
<div className={"reactcards-card "+style.card}>
58+
{props.title ? <CardHeader>{props.title}</CardHeader> : null}
59+
{props.doc ? <Markdown className={style.markdownDoc}>{props.doc}</Markdown> : null}
60+
{props.noframe ?
61+
<div>{props.children}</div> :
62+
<Frame ref="iframe"
63+
initialContent={iframeContent}
64+
mountTarget="#content">
65+
{props.children}
66+
</Frame>
67+
}
68+
</div>
69+
);
70+
}
71+
}

src/style.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ body {
2424
border-radius:2px;
2525
font-family:sans-serif;
2626
background-color:white;
27+
iframe {
28+
width: 100%;
29+
border: none;
30+
}
2731
}
2832

2933
:local(.cardHeader) {

0 commit comments

Comments
 (0)