feature(directory) add ability to upload directories via drag n drop in Chrome

This commit is contained in:
coderaiser 2015-07-16 08:24:11 -04:00
parent 2790799b98
commit 44531adfc6
27 changed files with 1137 additions and 4 deletions

View file

@ -0,0 +1,38 @@
{
"name": "findit",
"homepage": "https://github.com/coderaiser/domfs-findit",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "Walk a directory tree in DOM File System",
"main": "lib/findit.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"findit",
"DOM",
"File System"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"modules"
],
"dependencies": {
"emitify": "~1.2.0"
},
"version": "1.1.2",
"_release": "1.1.2",
"_resolution": {
"type": "version",
"tag": "v1.1.2",
"commit": "c311a97563fccb55df3129a3f93f40c0ba08aaf5"
},
"_source": "git://github.com/coderaiser/domfs-findit.git",
"_target": "~1.1.2",
"_originalSource": "findit",
"_direct": true
}

39
modules/findit/ChangeLog Normal file
View file

@ -0,0 +1,39 @@
2015.07.16, v1.1.2
fix:
- (findit) find -> self._find
2015.07.15, v1.1.1
fix:
- (dindit) enry -> entry
feature:
- (package) main: domfs-findit -> findit
2015.07.14, v1.1.0
fix:
- (findit) dirs, first could be overwriting
2015.07.14, v1.0.3
fix:
- (findit) no end when entry file
2015.07.14, v1.0.2
fix:
- (findit) dirs could be more then 0
2015.07.13, v1.0.1
fix:
- (findit) return
- (example) add ()

21
modules/findit/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 coderaiser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

55
modules/findit/README.md Normal file
View file

@ -0,0 +1,55 @@
# DOM File System Findit
Similar to [node-findit](https://github.com/substack/node-findit "Node Findit") but for [Dom File System](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem "Dom File System").
## Install
```
bower i findit --save
```
## How to use?
Add `findit.js` and [emitify](https://github.com/coderaiser/emitify "Emitify").
Or any other node-compitable [EventEmitter](https://iojs.org/api/events.html "Events") (set `window.Emitify = your_emitter` before using `findit`).
```html
<script src="modules/emitify/lib/emitify.js"></script>
<script src="lib/findit.js"></script>
```
```js
var node = window;
node.addEventListener('drop', function (e) {
var entry,
finder,
item = e.dataTransfer.items[0];
e.preventDefault();
entry = item.webkitGetAsEntry();
finder = findit(entry);
finder.on('file', function(file, entry) {
console.log('file: ', file, entry);
});
finder.on('directory', function(file, entry) {
console.log('directory: ', file, entry);
})
finder.on('end', function() {
console.log('done');
})
});
node.addEventListener('dragover', function (e) {
e.preventDefault();
});
```
## License
MIT

28
modules/findit/bower.json Normal file
View file

@ -0,0 +1,28 @@
{
"name": "findit",
"homepage": "https://github.com/coderaiser/domfs-findit",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "Walk a directory tree in DOM File System",
"main": "lib/findit.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"findit",
"DOM",
"File System"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"modules"
],
"dependencies": {
"emitify": "~1.2.0"
},
"version": "1.1.2"
}

View file

@ -0,0 +1,39 @@
<body>
<script src="../modules/emitify/lib/emitify.js"></script>
<script src="../lib/findit.js"></script>
<script>
(function() {
'use strict';
var node = window;
node.addEventListener('drop', function (e) {
var entry,
finder,
item = e.dataTransfer.items[0];
e.preventDefault();
entry = item.webkitGetAsEntry();
finder = findit(entry);
finder.on('file', function(file, entry) {
console.log('file: ', file, entry);
});
finder.on('directory', function(file, entry) {
console.log('directory: ', file, entry);
})
finder.on('end', function() {
console.log('done');
})
});
node.addEventListener('dragover', function (e) {
e.preventDefault();
});
})();
</script>
</body>

View file

@ -0,0 +1,60 @@
/* global Emitify */
(function(global) {
'use strict';
if (typeof module !== 'undefined' && module.exports)
module.exports = findit;
else
global.findit = findit;
function findit(entry) {
var emitter = Emitify();
setTimeout(function() {
FindIt(emitter, entry);
}, 0);
return emitter;
}
function FindIt(emitter, entry) {
if (!(this instanceof FindIt))
return new FindIt(emitter, entry);
this._dirs = 0;
this._first = true;
this._find(emitter, entry);
}
FindIt.prototype._find = function(emitter, entry) {
var self = this;
if (entry.isFile) {
emitter.emit('file', entry.fullPath, entry);
if (self._first)
emitter.emit('end');
} else {
if (self._first)
self._first = false;
emitter.emit('directory', entry.fullPath, entry);
++self._dirs;
entry.createReader()
.readEntries(function(entries) {
[].filter.call(entries, function(entry) {
self._find(emitter, entry);
});
--self._dirs;
if (!self._dirs)
emitter.emit('end');
});
}
};
})(this);

View file

@ -0,0 +1,27 @@
{
"name": "findit",
"private": true,
"version": "1.1.2",
"description": "Walk a directory tree in DOM File System",
"main": "lib/findit.js",
"dependencies": {},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/coderaiser/domfs-findit.git"
},
"keywords": [
"findit",
"DOM",
"File System"
],
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/coderaiser/domfs-findit/issues"
},
"homepage": "https://github.com/coderaiser/domfs-findit"
}