From 1792788f5fc16f8b497351a5361649f5ce131891 Mon Sep 17 00:00:00 2001 From: Peter Lejeck Date: Thu, 31 Oct 2013 04:56:48 -0700 Subject: Move JS into js/, replace with uncompressed --- js/cabinet.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 js/cabinet.js (limited to 'js/cabinet.js') 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() + }) + } +})($) -- cgit v1.2.3