Skip to content

Instantly share code, notes, and snippets.

@KristerV
Created March 2, 2016 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KristerV/796261e98dd25a85fa0d to your computer and use it in GitHub Desktop.
Save KristerV/796261e98dd25a85fa0d to your computer and use it in GitHub Desktop.
UserProfile = React.createClass({
componentWillMount() {
loadFilePicker()
},
filepicker(e) {
console.log("filepicker event",e)
},
render() {
return (
<div className="mdl-grid">
<div className="paper padding mdl-cell mdl-cell--4-col">
<input type="filepicker" onchange={this.filepicker}/>
</div>
</div>)
}
})
// Copied from https://github.com/nate-strauser/meteor-filepicker-plus
loadFilePicker = function(key, callback){
if(typeof filepicker === "undefined"){
if(!key && Meteor.settings && Meteor.settings.public && Meteor.settings.public.filepicker && Meteor.settings.public.filepicker.key)
key = Meteor.settings.public.filepicker.key;
if(key){
// Functions to run after the script tag has loaded
var filepickerLoadCallback = function() {
filepicker.setKey(key);
if (Object.prototype.toString.call(callback) === "[object Function]")
callback();
};
// If the script doesn't load
var filepickerErrorCallback = function(error) {
if(typeof console !== "undefined") {
console.log(error);
}
};
// Generate a script tag
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "//api.filepicker.io/v2/filepicker.js";
script.onload = filepickerLoadCallback;
script.onerror = filepickerErrorCallback;
// Load the script tag
document.getElementsByTagName('head')[0].appendChild(script);
}else{
if(typeof console !== "undefined") {
console.log("filepicker-plus - tried to load but key not supplied");
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment