Skip to content

Instantly share code, notes, and snippets.

@nickname55
Forked from scottpurdy/impress.jsx
Created January 23, 2020 21:20
Show Gist options
  • Save nickname55/0bdfcb82dc76c7971d5f3949a19bf1f2 to your computer and use it in GitHub Desktop.
Save nickname55/0bdfcb82dc76c7971d5f3949a19bf1f2 to your computer and use it in GitHub Desktop.
react-impress
/** @jsx React.DOM */
var RenderedDeck = React.createClass({
render: function() {
return <div id={this.props.id} className="deck" dangerouslySetInnerHTML={{__html:this.props.contents}}></div>;
}
});
var Deck = React.createClass({
render: function() {
var classes = this.props.className + ' Deck';
return <iframe className={classes} />;
},
componentDidMount: function() {
this.update();
},
componentDidUpdate: function(prevProps) {
if (this.props.contents != prevProps.contents) {
this.update();
} else {
this.impress.goto(this.props.slide);
}
},
update: function(cb) {
this.props.id = "deck";
React.renderComponent(
RenderedDeck(this.props),
this.getDOMNode().contentDocument.body,
function() {
var cd = this.getDOMNode().contentDocument;
var tag = cd.createElement("script");
tag.onload = function() {
this.impress = this.getDOMNode().contentWindow.impress("deck");
this.impress.init();
this.impress.goto(this.props.slide, 0);
}.bind(this);
tag.src = '/static/js/impress.js';
cd.body.appendChild(tag);
tag = cd.createElement("link");
tag.rel = "stylesheet";
tag.type = "text/css";
tag.href = '/static/css/impress-demo.css';
cd.getElementsByTagName('head')[0].appendChild(tag);
}.bind(this)
);
},
//componentDidUpdate: function() {
// this.impress.goto(this.props.slide);
//},
handleKeyUp: function(event) {
if (this.props.preventKeys) {
event.preventDefault();
}
}
});
module.exports = Deck;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment