mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(directory) add ability to upload directories via drag n drop in Chrome
This commit is contained in:
parent
2790799b98
commit
44531adfc6
27 changed files with 1137 additions and 4 deletions
35
modules/emitify/.bower.json
Normal file
35
modules/emitify/.bower.json
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "emitify",
|
||||
"version": "1.2.0",
|
||||
"homepage": "https://github.com/coderaiser/emitify",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Dead simple event emitter",
|
||||
"main": "lib/emitify.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"event",
|
||||
"emitter"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"_release": "1.2.0",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.2.0",
|
||||
"commit": "5dd1685840ba4905c7fcbd7b00202bed4baeb1ad"
|
||||
},
|
||||
"_source": "git://github.com/coderaiser/emitify.git",
|
||||
"_target": "~1.2.0",
|
||||
"_originalSource": "emitify"
|
||||
}
|
||||
47
modules/emitify/ChangeLog
Normal file
47
modules/emitify/ChangeLog
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
2015.06.16, v1.2.0
|
||||
|
||||
feature:
|
||||
- (emitify) add instanceof check
|
||||
|
||||
|
||||
2015.02.24, v1.1.2
|
||||
|
||||
fix:
|
||||
- (emitify) once: do not remove callback after emit
|
||||
|
||||
|
||||
2015.02.11, v1.1.1
|
||||
|
||||
fix:
|
||||
- (emitify) emit throw: data -> args[0]
|
||||
|
||||
feature:
|
||||
- (package) v1.1.0
|
||||
|
||||
|
||||
2015.02.11, v1.1.0
|
||||
|
||||
feature:
|
||||
- (emitify) emit: add ability to use more then two arguments
|
||||
|
||||
|
||||
2015.02.10, v1.0.3
|
||||
|
||||
fix:
|
||||
- (emitify) "event should be function"
|
||||
|
||||
|
||||
2015.02.10, v1.0.2
|
||||
|
||||
feature:
|
||||
- (emitify) add arguments check
|
||||
|
||||
|
||||
2015.02.10, v1.0.1
|
||||
|
||||
fix:
|
||||
- (emitify) off: index do not changed
|
||||
|
||||
feature:
|
||||
- (bower) add
|
||||
|
||||
21
modules/emitify/LICENSE
Normal file
21
modules/emitify/LICENSE
Normal 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.
|
||||
63
modules/emitify/README.md
Normal file
63
modules/emitify/README.md
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# Emitify
|
||||
|
||||
Dead simple event emitter.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm i emitify --save
|
||||
bower i emitify --save
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
What you should do first is create new instance of `emitify` with
|
||||
|
||||
```js
|
||||
var emitify = Emitify();
|
||||
```
|
||||
|
||||
Than you could just use API as it is.
|
||||
|
||||
### emitter.on(event, callback)
|
||||
|
||||
Add `callback` listener to `event`.
|
||||
|
||||
### emitter.off(event, callback)
|
||||
|
||||
Remove `callback` listener from `event`.
|
||||
|
||||
### emitter.emit(event [, data1, data2, ..., dataN])
|
||||
|
||||
Emit `event` with (or without) data.
|
||||
|
||||
### emitter.addListener(event, callback)
|
||||
|
||||
Alias to `emitter.on`.
|
||||
|
||||
### emitter.removeListener(event, callback)
|
||||
|
||||
Alias to `emitter.off`.
|
||||
|
||||
## How to use?
|
||||
|
||||
```js
|
||||
var Emitify = require('emitify'),
|
||||
emitter = new Emitify(),
|
||||
log = function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
emitter.on('data', log);
|
||||
|
||||
emitter.emit('data', 'hello');
|
||||
// result
|
||||
'hello'
|
||||
|
||||
emitter.off('data', log);
|
||||
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
26
modules/emitify/bower.json
Normal file
26
modules/emitify/bower.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "emitify",
|
||||
"version": "1.2.0",
|
||||
"homepage": "https://github.com/coderaiser/emitify",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Dead simple event emitter",
|
||||
"main": "lib/emitify.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"event",
|
||||
"emitter"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
82
modules/emitify/lib/emitify.js
Normal file
82
modules/emitify/lib/emitify.js
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports)
|
||||
module.exports = Emitify;
|
||||
else
|
||||
global.Emitify = Emitify;
|
||||
|
||||
function Emitify() {
|
||||
if (this instanceof Emitify)
|
||||
this._all = {};
|
||||
else
|
||||
return new Emitify();
|
||||
}
|
||||
|
||||
Emitify.prototype._check = function(event, callback) {
|
||||
var isTwo = arguments.length === 2;
|
||||
|
||||
if (typeof event !== 'string')
|
||||
throw(Error('event should be string!'));
|
||||
|
||||
if (isTwo && typeof callback !== 'function')
|
||||
throw(Error('callback should be function!'));
|
||||
};
|
||||
|
||||
Emitify.prototype.on = function(event, callback) {
|
||||
var funcs = this._all[event];
|
||||
|
||||
this._check(event, callback);
|
||||
|
||||
if (funcs)
|
||||
funcs.push(callback);
|
||||
else
|
||||
this._all[event] = [callback];
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Emitify.prototype.addListener =
|
||||
Emitify.prototype.on;
|
||||
|
||||
Emitify.prototype.once = function(event, callback) {
|
||||
var self = this;
|
||||
|
||||
self._check(event, callback);
|
||||
|
||||
self.on(event, function fn() {
|
||||
callback();
|
||||
self.off(event, fn);
|
||||
});
|
||||
};
|
||||
|
||||
Emitify.prototype.off = function(event, callback) {
|
||||
var events = this._all[event] || [],
|
||||
index = events.indexOf(callback);
|
||||
|
||||
this._check(event, callback);
|
||||
|
||||
while (~index) {
|
||||
events.splice(index, 1);
|
||||
index = events.indexOf(callback);
|
||||
}
|
||||
};
|
||||
|
||||
Emitify.prototype.removeListener =
|
||||
Emitify.prototype.off;
|
||||
|
||||
Emitify.prototype.emit = function(event) {
|
||||
var args = [].slice.call(arguments, 1),
|
||||
funcs = this._all[event];
|
||||
|
||||
this._check(event);
|
||||
|
||||
if (funcs)
|
||||
funcs.forEach(function(fn) {
|
||||
fn.apply(null, args);
|
||||
});
|
||||
else if (event === 'error')
|
||||
throw args[0];
|
||||
};
|
||||
|
||||
})(this);
|
||||
23
modules/emitify/package.json
Normal file
23
modules/emitify/package.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "emitify",
|
||||
"version": "1.2.0",
|
||||
"description": "dead simple event emitter",
|
||||
"main": "lib/emitify.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coderaiser/emitify.git"
|
||||
},
|
||||
"keywords": [
|
||||
"event",
|
||||
"emitter"
|
||||
],
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/coderaiser/emitify/issues"
|
||||
},
|
||||
"homepage": "https://github.com/coderaiser/emitify"
|
||||
}
|
||||
38
modules/findit/.bower.json
Normal file
38
modules/findit/.bower.json
Normal 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
39
modules/findit/ChangeLog
Normal 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
21
modules/findit/LICENSE
Normal 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
55
modules/findit/README.md
Normal 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
28
modules/findit/bower.json
Normal 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"
|
||||
}
|
||||
39
modules/findit/example/index.html
Normal file
39
modules/findit/example/index.html
Normal 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>
|
||||
60
modules/findit/lib/findit.js
Normal file
60
modules/findit/lib/findit.js
Normal 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);
|
||||
27
modules/findit/package.json
Normal file
27
modules/findit/package.json
Normal 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"
|
||||
}
|
||||
38
modules/philip/.bower.json
Normal file
38
modules/philip/.bower.json
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "philip",
|
||||
"version": "1.1.1",
|
||||
"homepage": "https://github.com/coderaiser/domfs-philip",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/philip.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"modules"
|
||||
],
|
||||
"dependencies": {
|
||||
"emitify": "~1.2.0",
|
||||
"findit": "~1.1.0"
|
||||
},
|
||||
"_release": "1.1.1",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.1.1",
|
||||
"commit": "8d6fdd3fe7dece2c0760a6beada90ff4e4ff4064"
|
||||
},
|
||||
"_source": "git://github.com/coderaiser/domfs-philip.git",
|
||||
"_target": "~1.1.1",
|
||||
"_originalSource": "philip",
|
||||
"_direct": true
|
||||
}
|
||||
11
modules/philip/ChangeLog
Normal file
11
modules/philip/ChangeLog
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
2015.07.16, v1.1.1
|
||||
|
||||
feature:
|
||||
- (philip) inherit from Emitify
|
||||
|
||||
|
||||
2015.07.16, v1.1.0
|
||||
|
||||
feature:
|
||||
- (philip) add abort, pause, continue
|
||||
|
||||
21
modules/philip/LICENSE
Normal file
21
modules/philip/LICENSE
Normal 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.
|
||||
77
modules/philip/README.md
Normal file
77
modules/philip/README.md
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
# Philip
|
||||
|
||||
[Dom File System](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem "Dom File System") processing library
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
bower i philip --save
|
||||
```
|
||||
|
||||
## How to use?
|
||||
|
||||
Add `philip.js` [findit](https://github.com/coderaiser/domfs-findit "Find It") 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="modules/findit/lib/findit.js"></script>
|
||||
<script src="lib/philip.js"></script>
|
||||
```
|
||||
|
||||
```js
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var node = window;
|
||||
|
||||
node.addEventListener('drop', function (e) {
|
||||
var upload,
|
||||
entry,
|
||||
finder,
|
||||
item = e.dataTransfer.items[0];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
entry = item.webkitGetAsEntry();
|
||||
|
||||
upload = philip(entry, function(type, name, data, callback) {
|
||||
var error = null;
|
||||
|
||||
switch(type) {
|
||||
case 'file':
|
||||
console.log('file', name, data);
|
||||
break;
|
||||
|
||||
case 'directory':
|
||||
console.log('directory', name);
|
||||
break;
|
||||
}
|
||||
|
||||
callback(error);
|
||||
});
|
||||
|
||||
upload.on('error', function(error) {
|
||||
upload.abort();
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
upload.on('progress', function(count) {
|
||||
console.log(count);
|
||||
});
|
||||
|
||||
upload.on('end', function() {
|
||||
console.log('done');
|
||||
});
|
||||
});
|
||||
|
||||
node.addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
28
modules/philip/bower.json
Normal file
28
modules/philip/bower.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "philip",
|
||||
"version": "1.1.1",
|
||||
"homepage": "https://github.com/coderaiser/domfs-philip",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "Walk a directory tree in DOM File System",
|
||||
"main": "lib/philip.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"modules"
|
||||
],
|
||||
"dependencies": {
|
||||
"emitify": "~1.2.0",
|
||||
"findit": "~1.1.0"
|
||||
}
|
||||
}
|
||||
55
modules/philip/example/index.html
Normal file
55
modules/philip/example/index.html
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<body>
|
||||
<script src="../modules/emitify/lib/emitify.js"></script>
|
||||
<script src="../modules/findit/lib/findit.js"></script>
|
||||
<script src="../lib/philip.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var node = window;
|
||||
|
||||
node.addEventListener('drop', function (e) {
|
||||
var upload,
|
||||
entry,
|
||||
finder,
|
||||
item = e.dataTransfer.items[0];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
entry = item.webkitGetAsEntry();
|
||||
|
||||
upload = philip(entry, function(type, name, data, callback) {
|
||||
var error = null;
|
||||
|
||||
switch(type) {
|
||||
case 'file':
|
||||
console.log('file', name, data);
|
||||
break;
|
||||
|
||||
case 'directory':
|
||||
console.log('directory', name);
|
||||
break;
|
||||
}
|
||||
|
||||
callback(error);
|
||||
});
|
||||
|
||||
upload.on('error', function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
upload.on('progress', function(count) {
|
||||
console.log(count);
|
||||
});
|
||||
|
||||
upload.on('end', function() {
|
||||
console.log('done');
|
||||
});
|
||||
});
|
||||
|
||||
node.addEventListener('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
149
modules/philip/lib/philip.js
Normal file
149
modules/philip/lib/philip.js
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
/* global Emitify */
|
||||
/* global findit */
|
||||
|
||||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports)
|
||||
module.exports = Philip;
|
||||
else
|
||||
global.philip = Philip;
|
||||
|
||||
Philip.prototype = Object.create(Emitify.prototype);
|
||||
|
||||
function Philip(entries, processingFn) {
|
||||
var array,
|
||||
self;
|
||||
|
||||
if (!(this instanceof Philip))
|
||||
return new Philip(entries, processingFn);
|
||||
|
||||
if (typeof processingFn !== 'function')
|
||||
throw Error('processingFn should be function!');
|
||||
|
||||
Emitify.call(this);
|
||||
|
||||
if (Array.isArray(entries))
|
||||
array = entries;
|
||||
else
|
||||
array = [entries];
|
||||
|
||||
self = this;
|
||||
|
||||
this._i = 0;
|
||||
this._n = 0;
|
||||
this._processingFn = processingFn;
|
||||
this._pause = false;
|
||||
|
||||
this._find(array, function(files, dirs) {
|
||||
self._files = files;
|
||||
self._dirs = dirs;
|
||||
self._n = files.length + dirs.length;
|
||||
self._data = {};
|
||||
|
||||
self._getFiles(files, self._data, function() {
|
||||
self._process();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Philip.prototype._process = function() {
|
||||
var el,
|
||||
data,
|
||||
self = this,
|
||||
name = self._dirs.shift(),
|
||||
type = 'directory';
|
||||
|
||||
if (!name) {
|
||||
type = 'file';
|
||||
el = self._files.shift();
|
||||
|
||||
if (el) {
|
||||
name = el.fullPath;
|
||||
data = self._data[name];
|
||||
}
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
self.emit('end');
|
||||
} else if (!this._pause) {
|
||||
self._processingFn(type, name, data, function(error) {
|
||||
++self._i;
|
||||
|
||||
if (error) {
|
||||
self.emit('error', error);
|
||||
self.pause();
|
||||
}
|
||||
|
||||
self._process();
|
||||
self._progress();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Philip.prototype.pause = function() {
|
||||
this._pause = true;
|
||||
};
|
||||
|
||||
Philip.prototype.continue = function() {
|
||||
if (this._pause) {
|
||||
this._pause = false;
|
||||
this._process();
|
||||
}
|
||||
};
|
||||
|
||||
Philip.prototype.abort = function() {
|
||||
this._files = [];
|
||||
this._dirs = [];
|
||||
|
||||
this._process();
|
||||
};
|
||||
|
||||
Philip.prototype._progress = function() {
|
||||
var value = Math.round(this._i * 100 / this._n);
|
||||
|
||||
this.emit('progress', value);
|
||||
};
|
||||
|
||||
Philip.prototype._getFiles = function(files, obj, callback) {
|
||||
var current,
|
||||
self = this;
|
||||
|
||||
files = files.slice();
|
||||
current = files.shift();
|
||||
|
||||
if (!obj)
|
||||
obj = {};
|
||||
|
||||
if (!current)
|
||||
callback(null, obj);
|
||||
else
|
||||
current.file(function(file) {
|
||||
var name = current.fullPath;
|
||||
|
||||
obj[name] = file;
|
||||
|
||||
self._getFiles(files, obj, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Philip.prototype._find = function(entries, fn) {
|
||||
[].forEach.call(entries, function(entry) {
|
||||
var files = [],
|
||||
dirs = [],
|
||||
finder = findit(entry);
|
||||
|
||||
finder.on('directory', function(name) {
|
||||
dirs.push(name);
|
||||
});
|
||||
|
||||
finder.on('file', function(name, current) {
|
||||
files.push(current);
|
||||
});
|
||||
|
||||
finder.on('end', function() {
|
||||
fn(files, dirs);
|
||||
});
|
||||
});
|
||||
};
|
||||
})(this);
|
||||
27
modules/philip/package.json
Normal file
27
modules/philip/package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "philip",
|
||||
"private": true,
|
||||
"version": "1.1.1",
|
||||
"description": "Process files and directories in DOM File System",
|
||||
"main": "lib/philip.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coderaiser/domfs-philip.git"
|
||||
},
|
||||
"keywords": [
|
||||
"philip",
|
||||
"DOM",
|
||||
"File System"
|
||||
],
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/coderaiser/domfs-philip/issues"
|
||||
},
|
||||
"homepage": "https://github.com/coderaiser/domfs-philip"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue