diff options
| author | Peter Lejeck <peter.lejeck@gmail.com> | 2013-10-31 12:56:48 +0100 |
|---|---|---|
| committer | Peter Lejeck <peter.lejeck@gmail.com> | 2013-10-31 12:56:48 +0100 |
| commit | 1792788f5fc16f8b497351a5361649f5ce131891 (patch) | |
| tree | 981b02855329027996b9dd333dea51916a7615ec /js/cabinet.js | |
| parent | 152c0257a8ef9a8da7e45717a65578c340a7c178 (diff) | |
Move JS into js/, replace with uncompressed
Diffstat (limited to 'js/cabinet.js')
| -rw-r--r-- | js/cabinet.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/js/cabinet.js b/js/cabinet.js new file mode 100644 index 0000000..ebbae4f --- /dev/null +++ b/js/cabinet.js @@ -0,0 +1,36 @@ +;(function($){ + $.hasFileAPI = function hasFileAPI () { + return (window.FormData !== undefined) + } + $.fn.cabinet = function (input) { + input = $(input) + + var _this = this + var passthrough = function (outer, inner, prevent, fn) { + _this.on(outer, function (e) { + if (inner === 'click') + input[0].click() + else + input.trigger(inner) + if (prevent) e.preventDefault() + if (fn) fn(e) + }, false) + } + + input[0].filelist = Object.create(FileList) + + input.on('change', function (e) { + this.filelist = e.target.files + _this.change() + }) + + passthrough('dragenter', 'dragenter', true) + passthrough('dragover', 'dragover', true) + passthrough('dragleave', 'dragleave', true) + passthrough('click', 'click', false) + passthrough('drop', 'dragleave', true, function (e) { + input[0].filelist = e.dataTransfer.files + _this.change() + }) + } +})($) |
