@@ -4,11 +4,12 @@ var React = require('react');
4
4
5
5
var Gist = React . createClass ( {
6
6
propTypes : {
7
- id : React . PropTypes . string . isRequired
7
+ id : React . PropTypes . string . isRequired ,
8
+ file : React . PropTypes . string
8
9
} ,
9
10
10
11
shouldComponentUpdate : function ( nextProps ) {
11
- return this . props . id !== nextProps . id ;
12
+ return ( this . props . id !== nextProps . id ) || ( this . props . file != nextProps . file ) ;
12
13
} ,
13
14
14
15
componentDidMount : function ( ) {
@@ -18,14 +19,23 @@ var Gist = React.createClass({
18
19
this . _updateIframeContent ( ) ;
19
20
} ,
20
21
22
+ _calculateUrl : function ( ) {
23
+ if ( this . props . file ) {
24
+ return 'https://gist.github.com/' + this . props . id + '.js?file=' + this . props . file
25
+ } else {
26
+ return 'https://gist.github.com/' + this . props . id + '.js'
27
+ }
28
+ } ,
29
+
21
30
_updateIframeContent : function ( ) {
22
31
var iframe = this . refs . iframe . getDOMNode ( ) ;
23
32
24
33
var doc = iframe . document ;
25
34
if ( iframe . contentDocument ) doc = iframe . contentDocument ;
26
35
else if ( iframe . contentWindow ) doc = iframe . contentWindow . document ;
27
36
28
- var gistScript = '<script type="text/javascript" src="https://gist.github.com/' + this . props . id + '.js"></script>' ;
37
+ var gistLink = this . _calculateUrl ( )
38
+ var gistScript = '<script type="text/javascript" src="' + gistLink + '"></script>' ;
29
39
var styles = '<style>*{font-size:12px;}</style>' ;
30
40
var resizeScript = 'onload="parent.document.getElementById(\'gist-' + this . props . id + '\').style.height=document.body.scrollHeight + \'px\'"' ;
31
41
var iframeHtml = '<html><head><base target="_parent">' + styles + '</head><body ' + resizeScript + '>' + gistScript + '</body></html>' ;
0 commit comments