기한 없는 목표는 탁상공론이다. 기한이 없으면 일을 진행시켜주는 에너지도 발생하지 않는다. 당신의 삶을 불발탄으로 만들지 않으려면 분명한 기한을 정하라. 기한을 정하지 않는 목표는 총알 없는 총이다. -브라이언 트레이시
목표라는 단어 자체에 기한이 포함되어 있는 것입니다. 다시 말해 기한이 있어야만 목표라 할 수 있습니다. 기한이 있어야 목표가 뚜렷해져, 에너지가 생기고 몰입하게 되며,
그 결과로 성과가 나오는 것입니다.
기한 없는 목표는
아무런 쓸모가 없는 펑크 난 타이어와 같습니다.
As web apps evolve, you might have found it handy to let users drag
and drop files from the desktop onto the browser to edit, upload, share,
etc. But unfortunately, we’ve been unable to drag and drop folders onto
web pages. Luckily, beginning with Chrome 21, this issue will be
addressed (already available in the Chrome dev channel).
Passing multiple files with drag and drop
Let’s look at a code sample of existing drag and drop.
<divid=”dropzone”></div>
var dropzone = document.getElementById('dropzone');
dropzone.ondrop = function(e) {
var length = e.dataTransfer.files.length;
for (var i = 0; i < length; i++) {
var file = e.dataTransfer.files[i];
... // do whatever you want
}
};
In this example, you can actually drag and drop
a file or files from the desktop to your browser, but when you try to
pass a folder, notice that it will be either rejected or treated as a File object resulting in a failure.
How to handle dropped folders
Chrome 21 allows you to drop a folder or multiple folders into the
browser window. To handle these, you need to change the way you handle
dropped objects.
<divid=”dropzone”></div>
var dropzone = document.getElementById('dropzone');
dropzone.ondrop = function(e) {
var length = e.dataTransfer.items.length;
for (var i = 0; i < length; i++) {
var entry = e.dataTransfer.items[i].webkitGetAsEntry();
if (entry.isFile) {
... // do whatever you want
} else if (entry.isDirectory) {
... // do whatever you want
}
}
};
Notice that a big difference here is that you can treat a dropped object as Entry (FileEntry or DirectoryEntry) by using new function called getAsEntry (webkitGetAsEntry).
After obtaining access to the Entry object, you can use
standard file handling methods that were introduced in the FileSystem
API specification. For example, this example shows how you can detect if
a dropped object is a file or a directory by examining the .isFile (or the .isDirectory) field.
For further information regarding the FileSystem API, read Exploring the FileSystem APIs, regarding new drag and drop capability, read this document. Of course, these features are open standards or are waiting to become one soon.
In a recent post, Eiji Kitamura highlighted a subtle, yet powerful new feature in the drag and drop APIs; the ability to drag in folders and retrieve them as HTML5 Filesystem API FileEntry and DirectoryEntry objects (done by accessing a new method on the DataTransferItem, .webkitGetAsEntry()).
What's remarkably cool about the .webkitGetAsEntry() extension is how elegant it makes importing files and entire folders. Once you have a FileEntry or DirectoryEntry from a drop event, it's a matter of using the Filesystem API's copyTo() to get it imported into your app.
An example of copying multiple dropped folders over to the filesystem:
var fs =null;// Cache filesystem for later.// Not shown: setup drag and drop event listeners.function onDrop(e){
e.preventDefault();
e.stopPropagation();var items = e.dataTransfer.items;for(var i =0, item; item = items[i];++i){var entry = item.webkitGetAsEntry();// Folder? Copy the DirectoryEntry over to our local filesystem.if(entry.isDirectory){
entry.copyTo(fs.root,null,function(copiedEntry){// ...}, onError);}}}
window.webkitRequestFileSystem(TEMPORARY,1024*1204,function(fileSystem){
fs = fileSystem;},function(e){
console.log('Error', e);});
Very nice! Again, the simplicity comes from integrating DnD with the Filesystem API calls.
Taking this one step further, we also have the ability to drag and drop a folder and/or files onto a normal <input type="file">, then access the entries as Filesystem directory or file entries. That is done through .webkitEntries:
<inputtype="file"multiple>
function onChange(e) {
e.stopPropagation();
e.preventDefault();
var entries = e.target.webkitEntries; // Get all dropped items as FS API entries.
[].forEach.call(entries, function(entry) {
// Copy the entry into our local filesystem.
entry.copyTo(fs.root, null, function(copiedEntry) {
...
}, onError);
});
}
document.querySelector('input[type="file"]').addEventListener('change', onChange);
I've put together a photo gallery demo to demonstrate these different techniques for importing files/folders.