Last active
December 19, 2015 08:39
-
-
Save Leko/5927638 to your computer and use it in GitHub Desktop.
jquery.filedrop.jsのデモデモ用HTMLです。
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>HTML5 でドラッグ&ドロップ</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script src="jquery.drop-file.js"></script> | |
<script> | |
// strを指定の長さで切り取りtailをくっつける | |
function cutoff(str, len, tail) { | |
tail = tail || ""; | |
return str.slice(0, len) + tail; | |
} | |
$(function() { | |
$("#droppable").fileDrop({ | |
dragEnter: function(e) { | |
console.log("ドラッグされて上にあります"); | |
}, | |
dragLeave: function(e) { | |
console.log("ドラッグされて上からはずれました"); | |
}, | |
drop: function(files) { | |
console.log("ファイルがドロップされました"); | |
console.log(files); | |
}, | |
dropEach: function(f, val) { | |
if ( /image/.test(f.type) ) { | |
$(this).append( $("<p></p>").text("画像です")); | |
var binUrl = window.URL.createObjectURL(f); | |
$(this).append( $("<img/>").attr({"src": "" + binUrl}) ); | |
window.URL.revokeObjectURL(binUrl); | |
} else if ( f.type.indexOf("text") >= 0 || /javascript/.test(f.type) ) { | |
$(this).append( $("<pre></pre>").text( cutoff(val, 80, "..[略]") )); | |
} else { | |
$(this).append( $("<p></p>").text("無効なファイルです")); | |
} | |
} | |
}) | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="droppable" style="border: gray solid 1em; padding: 2em;"> | |
ファイルをドロップしてください。 | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment