summaryrefslogtreecommitdiff
path: root/js/cabinet.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/cabinet.js')
-rw-r--r--js/cabinet.js36
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()
+ })
+ }
+})($)