Skip to content

Instantly share code, notes, and snippets.

@Ivanca
Created December 12, 2012 04:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanca/4264971 to your computer and use it in GitHub Desktop.
Save Ivanca/4264971 to your computer and use it in GitHub Desktop.
Drag and drop functionality for "requirements.txt" files for http://python3wos.appspot.com/ Tested in latest Google Chrome and Firefox-
(function(){
document.addEventListener("drop", function( e ) {
e.preventDefault();
var blob = e.dataTransfer.files[0].slice();
var binaryReader = new FileReader();
$('.req').removeClass('.req');
binaryReader.addEventListener("load", function( file ) {
var notFound = '';
file.target.result.trim().replace(/==.*/g,'').split(/\n/).forEach(function(pack){
$('#'+pack).addClass('req').add('tr:first').prependTo('table');
if($('#'+pack).length === 0){
notFound += pack + "\r\n";
}
});
if(notFound){
var warning = "There is no data about this packages: " + notFound;
alert(warning);
console.log(warning);
}
window.scrollTo(0,0);
});
binaryReader.readAsText( blob, 'UTF-8' );
}, false);
// Firefox...
document.addEventListener("dragover", function( e ) {
e.preventDefault();
}, false);
$('<style>' +
'.req::after{ ' +
'content: "ʘ"; ' +
'position: absolute; ' +
'color: #FFCF99; ' +
'margin-top: 13px; ' +
'margin-left: -280px; ' +
'font-size: 11px; ' +
'} ' +
'</style>').appendTo('head');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment