Created
December 10, 2013 21:34
-
-
Save TechnotronicOz/7900634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @jsx React.DOM | |
*/ | |
App.Features.instagram = (function(ig){ | |
var Instagram = React.createClass({ | |
loadApi: function() { | |
$.ajax({ | |
url: this.props.url, | |
dataType: 'jsonp', | |
success: function(data) { | |
this.setState({ data: data.data }); | |
this.loadIso(); | |
}.bind(this) | |
}); | |
}, | |
getInitialState: function() { | |
return { data: [] }; | |
}, | |
componentWillMount: function() { | |
this.loadApi(); | |
}, | |
render: function() { | |
return ( | |
<Instablock data={this.state.data} /> | |
); | |
}, | |
loadIso: function() { | |
var $container = $('#instagram'), | |
isoVars = { | |
itemSelector: '.item', | |
sortBy: 'random', | |
masonry: { | |
columnWidth: 2, | |
gutterWidth: 5 | |
} | |
}; | |
return $container.isotope(isoVars); | |
} | |
}); | |
var Instablock = React.createClass({ | |
render: function() { | |
var gramNodes = this.props.data.map(function(block) { | |
return <Block captionUser={block.caption.from.username} captionText={block.caption.text} captionTimestamp={block.caption.created_time} imageUrl={block.images.low_resolution.url} />; | |
}); | |
return ( | |
<div> | |
{gramNodes} | |
</div> | |
); | |
} | |
}); | |
var Block = React.createClass({ | |
componentWillMount: function() { | |
var rando = Math.floor( (Math.random()*20) + 1 ), | |
classStr; | |
rando < 7 ? classStr = 'item big-block' : classStr = 'item sm-block'; | |
this.props.itemClass = classStr; | |
this.props.formattedTime = moment.unix(this.props.captionTimestamp).fromNow(); | |
}, | |
render: function() { | |
return ( | |
<div className={this.props.itemClass}> | |
<div className="mask"> | |
<div className="mask-container"> | |
<div className="bottom"> | |
<h4>@{this.props.captionUser}</h4> | |
<h5>{this.props.formattedTime}</h5> | |
<p>{this.props.captionText}</p> | |
</div> | |
</div> | |
</div> | |
<img src={this.props.imageUrl} alt={this.props.captionText} /> | |
</div> | |
); | |
} | |
}); | |
ig.init = function() { | |
React.renderComponent( | |
<Instagram url="https://api.instagram.com/v1/tags/libertylinkusa/media/recent?access_token=507934427.1fb234f.f7ed0d7e60df4673a9bbc92a0ee6b1aa" />, | |
document.getElementById('instagram') | |
); | |
} | |
return ig; | |
}(App.Features.instagram || {})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment