Created
March 2, 2016 15:17
-
-
Save KristerV/796261e98dd25a85fa0d 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
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>) | |
} | |
}) |
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
// 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