@@ -4,11 +4,12 @@ var React = require('react');
44
55var Gist = React . createClass ( {
66 propTypes : {
7- id : React . PropTypes . string . isRequired
7+ id : React . PropTypes . string . isRequired ,
8+ file : React . PropTypes . string
89 } ,
910
1011 shouldComponentUpdate : function ( nextProps ) {
11- return this . props . id !== nextProps . id ;
12+ return ( this . props . id !== nextProps . id ) || ( this . props . file != nextProps . file ) ;
1213 } ,
1314
1415 componentDidMount : function ( ) {
@@ -18,14 +19,23 @@ var Gist = React.createClass({
1819 this . _updateIframeContent ( ) ;
1920 } ,
2021
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+
2130 _updateIframeContent : function ( ) {
2231 var iframe = this . refs . iframe . getDOMNode ( ) ;
2332
2433 var doc = iframe . document ;
2534 if ( iframe . contentDocument ) doc = iframe . contentDocument ;
2635 else if ( iframe . contentWindow ) doc = iframe . contentWindow . document ;
2736
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>' ;
2939 var styles = '<style>*{font-size:12px;}</style>' ;
3040 var resizeScript = 'onload="parent.document.getElementById(\'gist-' + this . props . id + '\').style.height=document.body.scrollHeight + \'px\'"' ;
3141 var iframeHtml = '<html><head><base target="_parent">' + styles + '</head><body ' + resizeScript + '>' + gistScript + '</body></html>' ;
0 commit comments