update dropzone

This commit is contained in:
Jörg Thalheim 2013-04-05 12:34:37 +02:00
parent 5364810e93
commit d649e1649d
3 changed files with 79 additions and 24 deletions

View File

@ -10,9 +10,9 @@ compass_config do |config|
config.output_style = :compact config.output_style = :compact
end end
configure :build do #configure :build do
ignore "source/images/companies/*.png" # ignore "source/images/companies/*.png"
end #end
## ##
# Slim # Slim

View File

@ -1,5 +1,6 @@
== javascript_include_tag "dropzone.js" == javascript_include_tag "dropzone.js"
h1 Inbox h1 Inbox
p All uploaded files are sent to us
p p
form#my-awesome-dropzone.dropzone.clickable action="/upload" form#my-awesome-dropzone.dropzone.clickable action="/upload"

View File

@ -368,8 +368,6 @@ module.exports = require("./lib/dropzone.js");
}); });
require.register("dropzone/lib/dropzone.js", function(exports, require, module){ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
// Generated by CoffeeScript 1.4.0
/* /*
# #
# More info at [www.dropzonejs.com](http://www.dropzonejs.com) # More info at [www.dropzonejs.com](http://www.dropzonejs.com)
@ -401,22 +399,22 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
var Dropzone, Em, camelize, contentLoaded, createElement, noop, without, var Dropzone, Em, camelize, contentLoaded, createElement, noop, without,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice; __slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Em = typeof Emitter !== "undefined" && Emitter !== null ? Emitter : require("emitter"); Em = typeof Emitter !== "undefined" && Emitter !== null ? Emitter : require("emitter");
noop = function() {}; noop = function() {};
Dropzone = (function(_super) { Dropzone = (function(_super) {
__extends(Dropzone, _super); __extends(Dropzone, _super);
/* /*
This is a list of all available events you can register on a dropzone object. This is a list of all available events you can register on a dropzone object.
You can register an event handler like this: You can register an event handler like this:
dropzone.on("dragEnter", function() { }); dropzone.on("dragEnter", function() { });
*/ */
@ -424,6 +422,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.defaultOptions = { Dropzone.prototype.defaultOptions = {
url: null, url: null,
method: "post",
parallelUploads: 2, parallelUploads: 2,
maxFilesize: 256, maxFilesize: 256,
paramName: "file", paramName: "file",
@ -446,6 +445,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
}, },
fallback: function() { fallback: function() {
var child, messageElement, span, _i, _len, _ref; var child, messageElement, span, _i, _len, _ref;
this.element.className = "" + this.element.className + " browser-not-supported"; this.element.className = "" + this.element.className + " browser-not-supported";
_ref = this.element.getElementsByTagName("div"); _ref = this.element.getElementsByTagName("div");
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -467,12 +467,12 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
return this.element.appendChild(this.getFallbackForm()); return this.element.appendChild(this.getFallbackForm());
}, },
/* /*
Those functions register themselves to the events on init and handle all Those functions register themselves to the events on init and handle all
the user interface specific stuff. Overwriting them won't break the upload the user interface specific stuff. Overwriting them won't break the upload
but can break the way it's displayed. but can break the way it's displayed.
You can overwrite them if you don't like the default behavior. If you just You can overwrite them if you don't like the default behavior. If you just
want to add an additional event handler, register it on the dropzone object want to add an additional event handler, register it on the dropzone object
and don't overwrite those options. and don't overwrite those options.
*/ */
drop: function(e) { drop: function(e) {
@ -533,6 +533,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
function Dropzone(element, options) { function Dropzone(element, options) {
var elementId, elementOptions, extend, fallback, _ref; var elementId, elementOptions, extend, fallback, _ref;
this.element = element; this.element = element;
this.version = Dropzone.version; this.version = Dropzone.version;
this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, ""); this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, "");
@ -550,6 +551,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
elementOptions = (_ref = (elementId ? Dropzone.options[camelize(elementId)] : void 0)) != null ? _ref : {}; elementOptions = (_ref = (elementId ? Dropzone.options[camelize(elementId)] : void 0)) != null ? _ref : {};
extend = function() { extend = function() {
var key, object, objects, target, val, _i, _len; var key, object, objects, target, val, _i, _len;
target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : []; target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
for (_i = 0, _len = objects.length; _i < _len; _i++) { for (_i = 0, _len = objects.length; _i < _len; _i++) {
object = objects[_i]; object = objects[_i];
@ -567,19 +569,32 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
if (!this.options.url) { if (!this.options.url) {
throw new Error("No URL provided."); throw new Error("No URL provided.");
} }
this.options.method = this.options.method.toUpperCase();
if (!Dropzone.isBrowserSupported()) { if (!Dropzone.isBrowserSupported()) {
return this.options.fallback.call(this); return this.options.fallback.call(this);
} }
if ((fallback = this.getExistingFallback()) && fallback.parentNode) { if ((fallback = this.getExistingFallback()) && fallback.parentNode) {
fallback.parentNode.removeChild(fallback); fallback.parentNode.removeChild(fallback);
} }
this.previewsContainer = this.options.previewsContainer ? createElement(this.options.previewsContainer) : this.element; if (this.options.previewsContainer) {
if (typeof this.options.previewsContainer === "string") {
this.previewsContainer = document.querySelector(this.options.previewsContainer);
} else if (this.options.previewsContainer.nodeType != null) {
this.previewsContainer = this.options.previewsContainer;
}
if (this.previewsContainer == null) {
throw new Error("Invalid `previewsContainer` option provided. Please provide a CSS selector or a plain HTML element.");
}
} else {
this.previewsContainer = this.element;
}
this.init(); this.init();
} }
Dropzone.prototype.init = function() { Dropzone.prototype.init = function() {
var eventName, noPropagation, _i, _len, _ref, _ref1, var eventName, noPropagation, _i, _len, _ref, _ref1,
_this = this; _this = this;
if (this.element.tagName === "form") { if (this.element.tagName === "form") {
this.element.setAttribute("enctype", "multipart/form-data"); this.element.setAttribute("enctype", "multipart/form-data");
} }
@ -594,6 +609,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
document.body.appendChild(this.hiddenFileInput); document.body.appendChild(this.hiddenFileInput);
this.hiddenFileInput.addEventListener("change", function() { this.hiddenFileInput.addEventListener("change", function() {
var files; var files;
files = _this.hiddenFileInput.files; files = _this.hiddenFileInput.files;
if (files.length) { if (files.length) {
_this.emit("selectedfiles", files); _this.emit("selectedfiles", files);
@ -656,6 +672,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.getFallbackForm = function() { Dropzone.prototype.getFallbackForm = function() {
var existingFallback, fields, fieldsString, form; var existingFallback, fields, fieldsString, form;
if (existingFallback = this.getExistingFallback()) { if (existingFallback = this.getExistingFallback()) {
return existingFallback; return existingFallback;
} }
@ -666,19 +683,21 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
fieldsString += "<input type=\"file\" name=\"" + this.options.paramName + "\" multiple=\"multiple\" /><button type=\"submit\">Upload!</button></div>"; fieldsString += "<input type=\"file\" name=\"" + this.options.paramName + "\" multiple=\"multiple\" /><button type=\"submit\">Upload!</button></div>";
fields = createElement(fieldsString); fields = createElement(fieldsString);
if (this.element.tagName !== "FORM") { if (this.element.tagName !== "FORM") {
form = createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"post\"></form>"); form = createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"" + this.options.method + "\"></form>");
form.appendChild(fields); form.appendChild(fields);
} else { } else {
this.element.setAttribute("enctype", "multipart/form-data"); this.element.setAttribute("enctype", "multipart/form-data");
this.element.setAttribute("method", "post"); this.element.setAttribute("method", this.options.method);
} }
return form != null ? form : fields; return form != null ? form : fields;
}; };
Dropzone.prototype.getExistingFallback = function() { Dropzone.prototype.getExistingFallback = function() {
var fallback, getFallback, tagName, _i, _len, _ref; var fallback, getFallback, tagName, _i, _len, _ref;
getFallback = function(elements) { getFallback = function(elements) {
var el, _i, _len; var el, _i, _len;
for (_i = 0, _len = elements.length; _i < _len; _i++) { for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i]; el = elements[_i];
if (/(^| )fallback($| )/.test(el.className)) { if (/(^| )fallback($| )/.test(el.className)) {
@ -697,6 +716,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.setupEventListeners = function() { Dropzone.prototype.setupEventListeners = function() {
var event, listener, _ref, _results; var event, listener, _ref, _results;
_ref = this.listeners; _ref = this.listeners;
_results = []; _results = [];
for (event in _ref) { for (event in _ref) {
@ -708,6 +728,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.removeEventListeners = function() { Dropzone.prototype.removeEventListeners = function() {
var event, listener, _ref, _results; var event, listener, _ref, _results;
_ref = this.listeners; _ref = this.listeners;
_results = []; _results = [];
for (event in _ref) { for (event in _ref) {
@ -735,6 +756,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.filesize = function(size) { Dropzone.prototype.filesize = function(size) {
var string; var string;
if (size >= 100000000000) { if (size >= 100000000000) {
size = size / 100000000000; size = size / 100000000000;
string = "TB"; string = "TB";
@ -756,6 +778,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.drop = function(e) { Dropzone.prototype.drop = function(e) {
var files; var files;
if (!e.dataTransfer) { if (!e.dataTransfer) {
return; return;
} }
@ -768,6 +791,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.handleFiles = function(files) { Dropzone.prototype.handleFiles = function(files) {
var file, _i, _len, _results; var file, _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) { for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i]; file = files[_i];
@ -786,6 +810,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.addFile = function(file) { Dropzone.prototype.addFile = function(file) {
var _this = this; var _this = this;
this.files.push(file); this.files.push(file);
this.emit("addedfile", file); this.emit("addedfile", file);
if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) { if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
@ -815,15 +840,31 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
} }
}; };
Dropzone.prototype.removeAllFiles = function() {
var file, _i, _len, _ref;
_ref = this.files.slice();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
file = _ref[_i];
if (__indexOf.call(this.filesProcessing, file) < 0) {
this.removeFile(file);
}
}
return null;
};
Dropzone.prototype.createThumbnail = function(file) { Dropzone.prototype.createThumbnail = function(file) {
var fileReader, var fileReader,
_this = this; _this = this;
fileReader = new FileReader; fileReader = new FileReader;
fileReader.onload = function() { fileReader.onload = function() {
var img; var img;
img = new Image; img = new Image;
img.onload = function() { img.onload = function() {
var canvas, ctx, srcHeight, srcRatio, srcWidth, srcX, srcY, thumbnail, trgHeight, trgRatio, trgWidth, trgX, trgY; var canvas, ctx, srcHeight, srcRatio, srcWidth, srcX, srcY, thumbnail, trgHeight, trgRatio, trgWidth, trgX, trgY;
canvas = document.createElement("canvas"); canvas = document.createElement("canvas");
ctx = canvas.getContext("2d"); ctx = canvas.getContext("2d");
srcX = 0; srcX = 0;
@ -865,6 +906,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.processQueue = function() { Dropzone.prototype.processQueue = function() {
var i, parallelUploads, processingLength; var i, parallelUploads, processingLength;
parallelUploads = this.options.parallelUploads; parallelUploads = this.options.parallelUploads;
processingLength = this.filesProcessing.length; processingLength = this.filesProcessing.length;
i = processingLength; i = processingLength;
@ -887,13 +929,15 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.prototype.uploadFile = function(file) { Dropzone.prototype.uploadFile = function(file) {
var formData, handleError, input, inputName, inputType, key, progressObj, value, xhr, _i, _len, _ref, _ref1, _ref2, var formData, handleError, input, inputName, inputType, key, progressObj, value, xhr, _i, _len, _ref, _ref1, _ref2,
_this = this; _this = this;
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
xhr.open("POST", this.options.url, true); xhr.open(this.options.method, this.options.url, true);
handleError = function() { handleError = function() {
return _this.errorProcessing(file, xhr.responseText || ("Server responded with " + xhr.status + " code.")); return _this.errorProcessing(file, xhr.responseText || ("Server responded with " + xhr.status + " code."));
}; };
xhr.onload = function(e) { xhr.onload = function(e) {
var response, _ref; var response, _ref;
if (!((200 <= (_ref = xhr.status) && _ref < 300))) { if (!((200 <= (_ref = xhr.status) && _ref < 300))) {
return handleError(); return handleError();
} else { } else {
@ -924,7 +968,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
formData.append(key, value); formData.append(key, value);
} }
} }
if (this.element.tagName = "FORM") { if (this.element.tagName === "FORM") {
_ref2 = this.element.querySelectorAll("input, textarea, select, button"); _ref2 = this.element.querySelectorAll("input, textarea, select, button");
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
input = _ref2[_i]; input = _ref2[_i];
@ -961,7 +1005,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
})(Em); })(Em);
Dropzone.version = "2.0.3"; Dropzone.version = "2.0.10";
Dropzone.options = {}; Dropzone.options = {};
@ -969,6 +1013,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.forElement = function(element) { Dropzone.forElement = function(element) {
var instance, _i, _len, _ref; var instance, _i, _len, _ref;
if (typeof element === "string") { if (typeof element === "string") {
element = document.querySelector(element); element = document.querySelector(element);
} }
@ -986,8 +1031,9 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
Dropzone.isBrowserSupported = function() { Dropzone.isBrowserSupported = function() {
var capableBrowser, regex, _i, _len, _ref; var capableBrowser, regex, _i, _len, _ref;
capableBrowser = true; capableBrowser = true;
if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData) { if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
if (!("classList" in document.createElement("a"))) { if (!("classList" in document.createElement("a"))) {
capableBrowser = false; capableBrowser = false;
} else { } else {
@ -1008,6 +1054,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
without = function(list, rejectedItem) { without = function(list, rejectedItem) {
var item, _i, _len, _results; var item, _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) { for (_i = 0, _len = list.length; _i < _len; _i++) {
item = list[_i]; item = list[_i];
@ -1026,6 +1073,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
createElement = function(string) { createElement = function(string) {
var div; var div;
div = document.createElement("div"); div = document.createElement("div");
div.innerHTML = string; div.innerHTML = string;
return div.childNodes[0]; return div.childNodes[0];
@ -1047,6 +1095,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
contentLoaded = function(win, fn) { contentLoaded = function(win, fn) {
var add, doc, done, init, poll, pre, rem, root, top; var add, doc, done, init, poll, pre, rem, root, top;
done = false; done = false;
top = true; top = true;
doc = win.document; doc = win.document;
@ -1064,9 +1113,12 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
} }
}; };
poll = function() { poll = function() {
var e;
try { try {
root.doScroll("left"); root.doScroll("left");
} catch (e) { } catch (_error) {
e = _error;
setTimeout(poll, 50); setTimeout(poll, 50);
return; return;
} }
@ -1089,12 +1141,14 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
contentLoaded(window, function() { contentLoaded(window, function() {
var checkElements, dropzone, dropzones, _i, _len, _results; var checkElements, dropzone, dropzones, _i, _len, _results;
if (false) { if (false) {
dropzones = document.querySelectorAll(".dropzone"); dropzones = document.querySelectorAll(".dropzone");
} else { } else {
dropzones = []; dropzones = [];
checkElements = function(elements) { checkElements = function(elements) {
var el, _i, _len, _results; var el, _i, _len, _results;
_results = []; _results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) { for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i]; el = elements[_i];