Created
December 12, 2012 04:57
-
-
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-
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
(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