1 2/* 3 * 4 * More info at [www.dropzonejs.com](http://www.dropzonejs.com) 5 * 6 * Copyright (c) 2012, Matias Meno 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 * 26 */ 27 28(function() { 29 var Dropzone, Emitter, camelize, contentLoaded, detectVerticalSquash, drawImageIOSFix, noop, without, 30 __slice = [].slice, 31 __hasProp = {}.hasOwnProperty, 32 __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; }; 33 34 noop = function() {}; 35 36 Emitter = (function() { 37 function Emitter() {} 38 39 Emitter.prototype.addEventListener = Emitter.prototype.on; 40 41 Emitter.prototype.on = function(event, fn) { 42 this._callbacks = this._callbacks || {}; 43 if (!this._callbacks[event]) { 44 this._callbacks[event] = []; 45 } 46 this._callbacks[event].push(fn); 47 return this; 48 }; 49 50 Emitter.prototype.emit = function() { 51 var args, callback, callbacks, event, _i, _len; 52 event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 53 this._callbacks = this._callbacks || {}; 54 callbacks = this._callbacks[event]; 55 if (callbacks) { 56 for (_i = 0, _len = callbacks.length; _i < _len; _i++) { 57 callback = callbacks[_i]; 58 callback.apply(this, args); 59 } 60 } 61 return this; 62 }; 63 64 Emitter.prototype.removeListener = Emitter.prototype.off; 65 66 Emitter.prototype.removeAllListeners = Emitter.prototype.off; 67 68 Emitter.prototype.removeEventListener = Emitter.prototype.off; 69 70 Emitter.prototype.off = function(event, fn) { 71 var callback, callbacks, i, _i, _len; 72 if (!this._callbacks || arguments.length === 0) { 73 this._callbacks = {}; 74 return this; 75 } 76 callbacks = this._callbacks[event]; 77 if (!callbacks) { 78 return this; 79 } 80 if (arguments.length === 1) { 81 delete this._callbacks[event]; 82 return this; 83 } 84 for (i = _i = 0, _len = callbacks.length; _i < _len; i = ++_i) { 85 callback = callbacks[i]; 86 if (callback === fn) { 87 callbacks.splice(i, 1); 88 break; 89 } 90 } 91 return this; 92 }; 93 94 return Emitter; 95 96 })(); 97 98 Dropzone = (function(_super) { 99 var extend, resolveOption; 100 101 __extends(Dropzone, _super); 102 103 Dropzone.prototype.Emitter = Emitter; 104 105 106 /* 107 This is a list of all available events you can register on a dropzone object. 108 109 You can register an event handler like this: 110 111 dropzone.on("dragEnter", function() { });
112 */ 113 114 Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"]; 115 116 Dropzone.prototype.defaultOptions = { 117 url: null, 118 method: "post", 119 withCredentials: false, 120 parallelUploads: 2, 121 uploadMultiple: false, 122 maxFilesize: 256, 123 paramName: "file", 124 createImageThumbnails: true, 125 maxThumbnailFilesize: 10, 126 thumbnailWidth: 120, 127 thumbnailHeight: 120, 128 filesizeBase: 1000, 129 maxFiles: null, 130 params: {}, 131 clickable: true, 132 ignoreHiddenFiles: true, 133 acceptedFiles: null, 134 acceptedMimeTypes: null, 135 autoProcessQueue: true, 136 autoQueue: true, 137 addRemoveLinks: false, 138 previewsContainer: null, 139 hiddenInputContainer: "body", 140 capture: null, 141 renameFilename: null, 142 dictDefaultMessage: "PDF oder Bild hierher ziehen zum hochladen", 143 dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.", 144 dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.", 145 dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.", 146 dictInvalidFileType: "You can't upload files of this type.", 147 dictResponseError: "Server responded with {{statusCode}} code.", 148 dictCancelUpload: "Cancel upload", 149 dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?", 150 dictRemoveFile: "Remove file", 151 dictRemoveFileConfirmation: null, 152 dictMaxFilesExceeded: "You can not upload any more files.", 153 accept: function(file, done) { 154 return done(); 155 }, 156 init: function() { 157 return noop; 158 }, 159 forceFallback: false, 160 fallback: function() { 161 var child, messageElement, span, _i, _len, _ref; 162 this.element.className = "" + this.element.className + " dz-browser-not-supported"; 163 _ref = this.element.getElementsByTagName("div"); 164 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 165 child = _ref[_i]; 166 if (/(^| )dz-message($| )/.test(child.className)) { 167 messageElement = child; 168 child.className = "dz-message"; 169 continue; 170 } 171 } 172 if (!messageElement) { 173 messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>"); 174 this.element.appendChild(messageElement); 175 } 176 span = messageElement.getElementsByTagName("span")[0]; 177 if (span) { 178 if (span.textContent != null) { 179 span.textContent = this.options.dictFallbackMessage; 180 } else if (span.innerText != null) { 181 span.innerText = this.options.dictFallbackMessage; 182 } 183 } 184 return this.element.appendChild(this.getFallbackForm()); 185 }, 186 resize: function(file) { 187 var info, srcRatio, trgRatio; 188 info = { 189 srcX: 0, 190 srcY: 0, 191 srcWidth: file.width, 192 srcHeight: file.height 193 }; 194 srcRatio = file.width / file.height; 195 info.optWidth = this.options.thumbnailWidth; 196 info.optHeight = this.options.thumbnailHeight; 197 if ((info.optWidth == null) && (info.optHeight == null)) { 198 info.optWidth = info.srcWidth; 199 info.optHeight = info.srcHeight; 200 } else if (info.optWidth == null) { 201 info.optWidth = srcRatio * info.optHeight; 202 } else if (info.optHeight == null) { 203 info.optHeight = (1 / srcRatio) * info.optWidth; 204 } 205 trgRatio = info.optWidth / info.optHeight; 206 if (file.height < info.optHeight || file.width < info.optWidth) { 207 info.trgHeight = info.srcHeight; 208 info.trgWidth = info.srcWidth; 209 } else { 210 if (srcRatio > trgRatio) { 211 info.srcHeight = file.height; 212 info.srcWidth = info.srcHeight * trgRatio; 213 } else { 214 info.srcWidth = file.width; 215 info.srcHeight = info.srcWidth / trgRatio; 216 } 217 } 218 info.srcX = (file.width - info.srcWidth) / 2; 219 info.srcY = (file.height - info.srcHeight) / 2; 220 return info; 221 }, 222 223 /* 224 Those functions register themselves to the events on init and handle all 225 the user interface specific stuff. Overwriting them won't break the upload 226 but can break the way it's displayed. 227 You can overwrite them if you don't like the default behavior. If you just 228 want to add an additional event handler, register it on the dropzone object 229 and don't overwrite those options. 230 */ 231 drop: function(e) { 232 return this.element.classList.remove("dz-drag-hover"); 233 }, 234 dragstart: noop, 235 dragend: function(e) { 236 return this.element.classList.remove("dz-drag-hover"); 237 }, 238 dragenter: function(e) { 239 return this.element.classList.add("dz-drag-hover"); 240 }, 241 dragover: function(e) { 242 return this.element.classList.add("dz-drag-hover"); 243 }, 244 dragleave: function(e) { 245 return this.element.classList.remove("dz-drag-hover"); 246 }, 247 paste: noop, 248 reset: function() { 249 return this.element.classList.remove("dz-started"); 250 }, 251 addedfile: function(file) { 252 var node, removeFileEvent, removeLink, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results; 253 if (this.element === this.previewsContainer) { 254 this.element.classList.add("dz-started"); 255 } 256 if (this.previewsContainer) { 257 file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim()); 258 file.previewTemplate = file.previewElement; 259 this.previewsContainer.appendChild(file.previewElement); 260 _ref = file.previewElement.querySelectorAll("[data-dz-name]"); 261 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 262 node = _ref[_i]; 263 node.textContent = this._renameFilename(file.name); 264 } 265 _ref1 = file.previewElement.querySelectorAll("[data-dz-size]"); 266 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 267 node = _ref1[_j]; 268 node.innerHTML = this.filesize(file.size); 269 } 270 if (this.options.addRemoveLinks) { 271 file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\" data-dz-remove>" + this.options.dictRemoveFile + "</a>"); 272 file.previewElement.appendChild(file._removeLink); 273 } 274 removeFileEvent = (function(_this) { 275 return function(e) { 276 e.preventDefault(); 277 e.stopPropagation(); 278 if (file.status === Dropzone.UPLOADING) { 279 return Dropzone.confirm(_this.options.dictCancelUploadConfirmation, function() { 280 return _this.removeFile(file); 281 }); 282 } else { 283 if (_this.options.dictRemoveFileConfirmation) { 284 return Dropzone.confirm(_this.options.dictRemoveFileConfirmation, function() { 285 return _this.removeFile(file); 286 }); 287 } else { 288 return _this.removeFile(file); 289 } 290 } 291 }; 292 })(this); 293 _ref2 = file.previewElement.querySelectorAll("[data-dz-remove]"); 294 _results = []; 295 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { 296 removeLink = _ref2[_k]; 297 _results.push(removeLink.addEventListener("click", removeFileEvent)); 298 } 299 return _results; 300 } 301 }, 302 removedfile: function(file) { 303 var _ref; 304 if (file.previewElement) { 305 if ((_ref = file.previewElement) != null) { 306 _ref.parentNode.removeChild(file.previewElement); 307 } 308 } 309 return this._updateMaxFilesReachedClass(); 310 }, 311 thumbnail: function(file, dataUrl) { 312 var thumbnailElement, _i, _len, _ref; 313 if (file.previewElement) { 314 file.previewElement.classList.remove("dz-file-preview"); 315 _ref = file.previewElement.querySelectorAll("[data-dz-thumbnail]"); 316 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 317 thumbnailElement = _ref[_i]; 318 thumbnailElement.alt = file.name; 319 thumbnailElement.src = dataUrl; 320 } 321 return setTimeout(((function(_this) { 322 return function() { 323 return file.previewElement.classList.add("dz-image-preview"); 324 }; 325 })(this)), 1); 326 } 327 }, 328 error: function(file, message) { 329 var node, _i, _len, _ref, _results; 330 if (file.previewElement) { 331 file.previewElement.classList.add("dz-error"); 332 if (typeof message !== "String" && message.error) { 333 message = message.error; 334 } 335 _ref = file.previewElement.querySelectorAll("[data-dz-errormessage]"); 336 _results = []; 337 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 338 node = _ref[_i]; 339 _results.push(node.textContent = message); 340 } 341 return _results; 342 } 343 }, 344 errormultiple: noop, 345 processing: function(file) { 346 if (file.previewElement) { 347 file.previewElement.classList.add("dz-processing"); 348 if (file._removeLink) { 349 return file._removeLink.textContent = this.options.dictCancelUpload; 350 } 351 } 352 }, 353 processingmultiple: noop, 354 uploadprogress: function(file, progress, bytesSent) { 355 var node, _i, _len, _ref, _results; 356 if (file.previewElement) { 357 _ref = file.previewElement.querySelectorAll("[data-dz-uploadprogress]"); 358 _results = []; 359 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 360 node = _ref[_i]; 361 if (node.nodeName === 'PROGRESS') { 362 _results.push(node.value = progress); 363 } else { 364 _results.push(node.style.width = "" + progress + "%"); 365 } 366 } 367 return _results; 368 } 369 }, 370 totaluploadprogress: noop, 371 sending: noop, 372 sendingmultiple: noop, 373 success: function(file) { 374 if (file.previewElement) { 375 return file.previewElement.classList.add("dz-success"); 376 } 377 }, 378 successmultiple: noop, 379 canceled: function(file) {
380 return this.emit("error", file, "Upload canceled."); 381 }, 382 canceledmultiple: noop, 383 complete: function(file) { 384 if (file._removeLink) { 385 file._removeLink.textContent = this.options.dictRemoveFile; 386 } 387 if (file.previewElement) { 388 return file.previewElement.classList.add("dz-complete"); 389 } 390 }, 391 completemultiple: noop, 392 maxfilesexceeded: noop, 393 maxfilesreached: noop, 394 queuecomplete: noop, 395 addedfiles: noop, 396 previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-image\"><img data-dz-thumbnail /></div>\n <div class=\"dz-details\">\n <div class=\"dz-size\"><span data-dz-size></span></div>\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n <div class=\"dz-success-mark\">\n <svg width=\"54px\" height=\"54px\" viewBox=\"0 0 54 54\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:sketch=\"http://www.bohemiancoding.com/sketch/ns\">\n <title>Check</title>\n <defs></defs>\n <g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\" sketch:type=\"MSPage\">\n <path d=\"M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z\" id=\"Oval-2\" stroke-opacity=\"0.198794158\" stroke=\"#747474\" fill-opacity=\"0.816519475\" fill=\"#FFFFFF\" sketch:type=\"MSShapeGroup\"></path>\n </g>\n </svg>\n </div>\n <div class=\"dz-error-mark\">\n <svg width=\"54px\" height=\"54px\" viewBox=\"0 0 54 54\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:sketch=\"http://www.bohemiancoding.com/sketch/ns\">\n <title>Error</title>\n <defs></defs>\n <g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\" sketch:type=\"MSPage\">\n <g id=\"Check-+-Oval-2\" sketch:type=\"MSLayerGroup\" stroke=\"#747474\" stroke-opacity=\"0.198794158\" fill=\"#FFFFFF\" fill-opacity=\"0.816519475\">\n <path d=\"M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z\" id=\"Oval-2\" sketch:type=\"MSShapeGroup\"></path>\n </g>\n </g>\n </svg>\n </div>\n</div>" 397 }; 398 399 extend = function() { 400 var key, object, objects, target, val, _i, _len; 401 target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 402 for (_i = 0, _len = objects.length; _i < _len; _i++) { 403 object = objects[_i]; 404 for (key in object) { 405 val = object[key]; 406 target[key] = val; 407 } 408 } 409 return target; 410 }; 411 412 function Dropzone(element, options) { 413 var elementOptions, fallback, _ref; 414 this.element = element; 415 this.version = Dropzone.version; 416 this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, ""); 417 this.clickableElements = []; 418 this.listeners = []; 419 this.files = []; 420 if (typeof this.element === "string") { 421 this.element = document.querySelector(this.element); 422 } 423 if (!(this.element && (this.element.nodeType != null))) { 424 throw new Error("Invalid dropzone element."); 425 } 426 if (this.element.dropzone) { 427 throw new Error("Dropzone already attached."); 428 } 429 Dropzone.instances.push(this); 430 this.element.dropzone = this; 431 elementOptions = (_ref = Dropzone.optionsForElement(this.element)) != null ? _ref : {}; 432 this.options = extend({}, this.defaultOptions, elementOptions, options != null ? options : {}); 433 if (this.options.forceFallback || !Dropzone.isBrowserSupported()) { 434 return this.options.fallback.call(this); 435 } 436 if (this.options.url == null) { 437 this.options.url = this.element.getAttribute("action"); 438 } 439 if (!this.options.url) { 440 throw new Error("No URL provided."); 441 } 442 if (this.options.acceptedFiles && this.options.acceptedMimeTypes) { 443 throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated."); 444 } 445 if (this.options.acceptedMimeTypes) { 446 this.options.acceptedFiles = this.options.acceptedMimeTypes; 447 delete this.options.acceptedMimeTypes; 448 } 449 this.options.method = this.options.method.toUpperCase(); 450 if ((fallback = this.getExistingFallback()) && fallback.parentNode) { 451 fallback.parentNode.removeChild(fallback); 452 } 453 if (this.options.previewsContainer !== false) { 454 if (this.options.previewsContainer) { 455 this.previewsContainer = Dropzone.getElement(this.options.previewsContainer, "previewsContainer"); 456 } else { 457 this.previewsContainer = this.element; 458 } 459 } 460 if (this.options.clickable) { 461 if (this.options.clickable === true) { 462 this.clickableElements = [this.element]; 463 } else { 464 this.clickableElements = Dropzone.getElements(this.options.clickable, "clickable"); 465 } 466 } 467 this.init(); 468 } 469 470 Dropzone.prototype.getAcceptedFiles = function() { 471 var file, _i, _len, _ref, _results; 472 _ref = this.files; 473 _results = []; 474 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 475 file = _ref[_i]; 476 if (file.accepted) { 477 _results.push(file); 478 } 479 } 480 return _results; 481 }; 482 483 Dropzone.prototype.getRejectedFiles = function() { 484 var file, _i, _len, _ref, _results; 485 _ref = this.files; 486 _results = []; 487 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 488 file = _ref[_i]; 489 if (!file.accepted) { 490 _results.push(file); 491 } 492 } 493 return _results; 494 }; 495 496 Dropzone.prototype.getFilesWithStatus = function(status) { 497 var file, _i, _len, _ref, _results; 498 _ref = this.files; 499 _results = []; 500 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 501 file = _ref[_i]; 502 if (file.status === status) { 503 _results.push(file); 504 } 505 } 506 return _results; 507 }; 508 509 Dropzone.prototype.getQueuedFiles = function() { 510 return this.getFilesWithStatus(Dropzone.QUEUED); 511 }; 512 513 Dropzone.prototype.getUploadingFiles = function() { 514 return this.getFilesWithStatus(Dropzone.UPLOADING); 515 }; 516 517 Dropzone.prototype.getAddedFiles = function() { 518 return this.getFilesWithStatus(Dropzone.ADDED); 519 }; 520 521 Dropzone.prototype.getActiveFiles = function() { 522 var file, _i, _len, _ref, _results; 523 _ref = this.files; 524 _results = []; 525 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 526 file = _ref[_i]; 527 if (file.status === Dropzone.UPLOADING || file.status === Dropzone.QUEUED) { 528 _results.push(file); 529 } 530 } 531 return _results; 532 }; 533 534 Dropzone.prototype.init = function() { 535 var eventName, noPropagation, setupHiddenFileInput, _i, _len, _ref, _ref1; 536 if (this.element.tagName === "form") { 537 this.element.setAttribute("enctype", "multipart/form-data"); 538 } 539 if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) { 540 this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><span>" + this.options.dictDefaultMessage + "</span></div>")); 541 } 542 if (this.clickableElements.length) { 543 setupHiddenFileInput = (function(_this) { 544 return function() { 545 if (_this.hiddenFileInput) { 546 _this.hiddenFileInput.parentNode.removeChild(_this.hiddenFileInput); 547 } 548 _this.hiddenFileInput = document.createElement("input"); 549 _this.hiddenFileInput.setAttribute("type", "file"); 550 if ((_this.options.maxFiles == null) || _this.options.maxFiles > 1) { 551 _this.hiddenFileInput.setAttribute("multiple", "multiple"); 552 } 553 _this.hiddenFileInput.className = "dz-hidden-input"; 554 if (_this.options.acceptedFiles != null) { 555 _this.hiddenFileInput.setAttribute("accept", _this.options.acceptedFiles); 556 } 557 if (_this.options.capture != null) { 558 _this.hiddenFileInput.setAttribute("capture", _this.options.capture); 559 } 560 _this.hiddenFileInput.style.visibility = "hidden"; 561 _this.hiddenFileInput.style.position = "absolute"; 562 _this.hiddenFileInput.style.top = "0"; 563 _this.hiddenFileInput.style.left = "0"; 564 _this.hiddenFileInput.style.height = "0"; 565 _this.hiddenFileInput.style.width = "0"; 566 document.querySelector(_this.options.hiddenInputContainer).appendChild(_this.hiddenFileInput); 567 return _this.hiddenFileInput.addEventListener("change", function() { 568 var file, files, _i, _len; 569 files = _this.hiddenFileInput.files; 570 if (files.length) { 571 for (_i = 0, _len = files.length; _i < _len; _i++) { 572 file = files[_i]; 573 _this.addFile(file); 574 } 575 }
576 _this.emit("addedfiles", files); 577 return setupHiddenFileInput(); 578 }); 579 }; 580 })(this); 581 setupHiddenFileInput(); 582 } 583 this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL; 584 _ref1 = this.events; 585 for (_i = 0, _len = _ref1.length; _i < _len; _i++) { 586 eventName = _ref1[_i]; 587 this.on(eventName, this.options[eventName]); 588 } 589 this.on("uploadprogress", (function(_this) { 590 return function() { 591 return _this.updateTotalUploadProgress(); 592 }; 593 })(this)); 594 this.on("removedfile", (function(_this) { 595 return function() { 596 return _this.updateTotalUploadProgress(); 597 }; 598 })(this)); 599 this.on("canceled", (function(_this) { 600 return function(file) { 601 return _this.emit("complete", file); 602 }; 603 })(this)); 604 this.on("complete", (function(_this) { 605 return function(file) { 606 if (_this.getAddedFiles().length === 0 && _this.getUploadingFiles().length === 0 && _this.getQueuedFiles().length === 0) { 607 return setTimeout((function() { 608 return _this.emit("queuecomplete"); 609 }), 0); 610 } 611 }; 612 })(this)); 613 noPropagation = function(e) { 614 e.stopPropagation(); 615 if (e.preventDefault) { 616 return e.preventDefault(); 617 } else { 618 return e.returnValue = false; 619 } 620 }; 621 this.listeners = [ 622 { 623 element: this.element, 624 events: { 625 "dragstart": (function(_this) { 626 return function(e) { 627 return _this.emit("dragstart", e); 628 }; 629 })(this), 630 "dragenter": (function(_this) { 631 return function(e) { 632 noPropagation(e); 633 return _this.emit("dragenter", e); 634 }; 635 })(this), 636 "dragover": (function(_this) { 637 return function(e) { 638 var efct; 639 try { 640 efct = e.dataTransfer.effectAllowed; 641 } catch (_error) {} 642 e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy'; 643 noPropagation(e); 644 return _this.emit("dragover", e); 645 }; 646 })(this), 647 "dragleave": (function(_this) { 648 return function(e) { 649 return _this.emit("dragleave", e); 650 }; 651 })(this), 652 "drop": (function(_this) { 653 return function(e) { 654 noPropagation(e); 655 return _this.drop(e); 656 }; 657 })(this), 658 "dragend": (function(_this) { 659 return function(e) { 660 return _this.emit("dragend", e); 661 }; 662 })(this) 663 } 664 } 665 ]; 666 this.clickableElements.forEach((function(_this) { 667 return function(clickableElement) { 668 return _this.listeners.push({ 669 element: clickableElement, 670 events: { 671 "click": function(evt) { 672 if ((clickableElement !== _this.element) || (evt.target === _this.element || Dropzone.elementInside(evt.target, _this.element.querySelector(".dz-message")))) { 673 _this.hiddenFileInput.click(); 674 } 675 return true; 676 } 677 } 678 }); 679 }; 680 })(this)); 681 this.enable(); 682 return this.options.init.call(this); 683 }; 684 685 Dropzone.prototype.destroy = function() { 686 var _ref; 687 this.disable(); 688 this.removeAllFiles(true); 689 if ((_ref = this.hiddenFileInput) != null ? _ref.parentNode : void 0) { 690 this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput); 691 this.hiddenFileInput = null; 692 } 693 delete this.element.dropzone; 694 return Dropzone.instances.splice(Dropzone.instances.indexOf(this), 1); 695 }; 696 697 Dropzone.prototype.updateTotalUploadProgress = function() { 698 var activeFiles, file, totalBytes, totalBytesSent, totalUploadProgress, _i, _len, _ref; 699 totalBytesSent = 0; 700 totalBytes = 0; 701 activeFiles = this.getActiveFiles(); 702 if (activeFiles.length) { 703 _ref = this.getActiveFiles(); 704 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 705 file = _ref[_i];
706 totalBytesSent += file.upload.bytesSent; 707 totalBytes += file.upload.total; 708 } 709 totalUploadProgress = 100 * totalBytesSent / totalBytes; 710 } else { 711 totalUploadProgress = 100; 712 } 713 return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent); 714 }; 715 716 Dropzone.prototype._getParamName = function(n) { 717 if (typeof this.options.paramName === "function") { 718 return this.options.paramName(n); 719 } else { 720 return "" + this.options.paramName + (this.options.uploadMultiple ? "[" + n + "]" : ""); 721 } 722 }; 723 724 Dropzone.prototype._renameFilename = function(name) { 725 if (typeof this.options.renameFilename !== "function") { 726 return name; 727 } 728 return this.options.renameFilename(name); 729 }; 730 731 Dropzone.prototype.getFallbackForm = function() { 732 var existingFallback, fields, fieldsString, form; 733 if (existingFallback = this.getExistingFallback()) { 734 return existingFallback; 735 } 736 fieldsString = "<div class=\"dz-fallback\">"; 737 if (this.options.dictFallbackText) { 738 fieldsString += "<p>" + this.options.dictFallbackText + "</p>"; 739 } 740 fieldsString += "<input type=\"file\" name=\"" + (this._getParamName(0)) + "\" " + (this.options.uploadMultiple ? 'multiple="multiple"' : void 0) + " /><input type=\"submit\" value=\"Upload!\"></div>"; 741 fields = Dropzone.createElement(fieldsString); 742 if (this.element.tagName !== "FORM") { 743 form = Dropzone.createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"" + this.options.method + "\"></form>"); 744 form.appendChild(fields); 745 } else { 746 this.element.setAttribute("enctype", "multipart/form-data"); 747 this.element.setAttribute("method", this.options.method); 748 } 749 return form != null ? form : fields; 750 }; 751 752 Dropzone.prototype.getExistingFallback = function() { 753 var fallback, getFallback, tagName, _i, _len, _ref; 754 getFallback = function(elements) { 755 var el, _i, _len; 756 for (_i = 0, _len = elements.length; _i < _len; _i++) { 757 el = elements[_i]; 758 if (/(^| )fallback($| )/.test(el.className)) { 759 return el; 760 } 761 } 762 }; 763 _ref = ["div", "form"]; 764 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 765 tagName = _ref[_i]; 766 if (fallback = getFallback(this.element.getElementsByTagName(tagName))) { 767 return fallback; 768 } 769 } 770 }; 771 772 Dropzone.prototype.setupEventListeners = function() { 773 var elementListeners, event, listener, _i, _len, _ref, _results; 774 _ref = this.listeners; 775 _results = []; 776 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 777 elementListeners = _ref[_i]; 778 _results.push((function() { 779 var _ref1, _results1; 780 _ref1 = elementListeners.events; 781 _results1 = []; 782 for (event in _ref1) { 783 listener = _ref1[event]; 784 _results1.push(elementListeners.element.addEventListener(event, listener, false)); 785 } 786 return _results1; 787 })()); 788 } 789 return _results; 790 }; 791 792 Dropzone.prototype.removeEventListeners = function() { 793 var elementListeners, event, listener, _i, _len, _ref, _results; 794 _ref = this.listeners; 795 _results = []; 796 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 797 elementListeners = _ref[_i]; 798 _results.push((function() { 799 var _ref1, _results1; 800 _ref1 = elementListeners.events; 801 _results1 = []; 802 for (event in _ref1) { 803 listener = _ref1[event]; 804 _results1.push(elementListeners.element.removeEventListener(event, listener, false)); 805 } 806 return _results1; 807 })()); 808 } 809 return _results; 810 }; 811 812 Dropzone.prototype.disable = function() { 813 var file, _i, _len, _ref, _results;
814 this.clickableElements.forEach(function(element) { 815 return element.classList.remove("dz-clickable"); 816 }); 817 this.removeEventListeners(); 818 _ref = this.files; 819 _results = []; 820 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 821 file = _ref[_i]; 822 _results.push(this.cancelUpload(file)); 823 } 824 return _results; 825 }; 826 827 Dropzone.prototype.enable = function() { 828 this.clickableElements.forEach(function(element) { 829 return element.classList.add("dz-clickable"); 830 }); 831 return this.setupEventListeners(); 832 }; 833 834 Dropzone.prototype.filesize = function(size) { 835 var cutoff, i, selectedSize, selectedUnit, unit, units, _i, _len; 836 selectedSize = 0; 837 selectedUnit = "b"; 838 if (size > 0) { 839 units = ['TB', 'GB', 'MB', 'KB', 'b']; 840 for (i = _i = 0, _len = units.length; _i < _len; i = ++_i) { 841 unit = units[i]; 842 cutoff = Math.pow(this.options.filesizeBase, 4 - i) / 10; 843 if (size >= cutoff) { 844 selectedSize = size / Math.pow(this.options.filesizeBase, 4 - i); 845 selectedUnit = unit; 846 break; 847 } 848 } 849 selectedSize = Math.round(10 * selectedSize) / 10; 850 } 851 return "<strong>" + selectedSize + "</strong> " + selectedUnit; 852 }; 853 854 Dropzone.prototype._updateMaxFilesReachedClass = function() { 855 if ((this.options.maxFiles != null) && this.getAcceptedFiles().length >= this.options.maxFiles) { 856 if (this.getAcceptedFiles().length === this.options.maxFiles) { 857 this.emit('maxfilesreached', this.files); 858 } 859 return this.element.classList.add("dz-max-files-reached"); 860 } else { 861 return this.element.classList.remove("dz-max-files-reached"); 862 } 863 }; 864 865 Dropzone.prototype.drop = function(e) { 866 var files, items; 867 if (!e.dataTransfer) { 868 return; 869 } 870 this.emit("drop", e); 871 files = e.dataTransfer.files; 872 this.emit("addedfiles", files); 873 if (files.length) { 874 items = e.dataTransfer.items; 875 if (items && items.length && (items[0].webkitGetAsEntry != null)) { 876 this._addFilesFromItems(items); 877 } else { 878 this.handleFiles(files); 879 } 880 } 881 }; 882 883 Dropzone.prototype.paste = function(e) { 884 var items, _ref; 885 if ((e != null ? (_ref = e.clipboardData) != null ? _ref.items : void 0 : void 0) == null) { 886 return; 887 } 888 this.emit("paste", e); 889 items = e.clipboardData.items; 890 if (items.length) { 891 return this._addFilesFromItems(items); 892 } 893 }; 894 895 Dropzone.prototype.handleFiles = function(files) { 896 var file, _i, _len, _results; 897 _results = []; 898 for (_i = 0, _len = files.length; _i < _len; _i++) { 899 file = files[_i]; 900 _results.push(this.addFile(file)); 901 } 902 return _results; 903 }; 904 905 Dropzone.prototype._addFilesFromItems = function(items) { 906 var entry, item, _i, _len, _results; 907 _results = []; 908 for (_i = 0, _len = items.length; _i < _len; _i++) { 909 item = items[_i]; 910 if ((item.webkitGetAsEntry != null) && (entry = item.webkitGetAsEntry())) { 911 if (entry.isFile) { 912 _results.push(this.addFile(item.getAsFile())); 913 } else if (entry.isDirectory) { 914 _results.push(this._addFilesFromDirectory(entry, entry.name)); 915 } else { 916 _results.push(void 0); 917 } 918 } else if (item.getAsFile != null) { 919 if ((item.kind == null) || item.kind === "file") { 920 _results.push(this.addFile(item.getAsFile())); 921 } else { 922 _results.push(void 0); 923 } 924 } else { 925 _results.push(void 0); 926 } 927 } 928 return _results; 929 }; 930 931 Dropzone.prototype._addFilesFromDirectory = function(directory, path) { 932 var dirReader, errorHandler, readEntries; 933 dirReader = directory.createReader(); 934 errorHandler = function(error) { 935 return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log(error) : void 0 : void 0; 936 }; 937 readEntries = (function(_this) { 938 return function() { 939 return dirReader.readEntries(function(entries) { 940 var entry, _i, _len; 941 if (entries.length > 0) { 942 for (_i = 0, _len = entries.length; _i < _len; _i++) { 943 entry = entries[_i]; 944 if (entry.isFile) { 945 entry.file(function(file) { 946 if (_this.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') { 947 return; 948 } 949 file.fullPath = "" + path + "/" + file.name; 950 return _this.addFile(file); 951 }); 952 } else if (entry.isDirectory) { 953 _this._addFilesFromDirectory(entry, "" + path + "/" + entry.name); 954 } 955 } 956 readEntries(); 957 } 958 return null; 959 }, errorHandler); 960 }; 961 })(this); 962 return readEntries(); 963 }; 964 965 Dropzone.prototype.accept = function(file, done) { 966 if (file.size > this.options.maxFilesize * 1024 * 1024) { 967 return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize)); 968 } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) { 969 return done(this.options.dictInvalidFileType); 970 } else if ((this.options.maxFiles != null) && this.getAcceptedFiles().length >= this.options.maxFiles) { 971 done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
972 return this.emit("maxfilesexceeded", file); 973 } else { 974 return this.options.accept.call(this, file, done); 975 } 976 }; 977 978 Dropzone.prototype.addFile = function(file) { 979 file.upload = { 980 progress: 0, 981 total: file.size, 982 bytesSent: 0 983 }; 984 this.files.push(file); 985 file.status = Dropzone.ADDED; 986 this.emit("addedfile", file); 987 this._enqueueThumbnail(file); 988 return this.accept(file, (function(_this) { 989 return function(error) { 990 if (error) { 991 file.accepted = false; 992 _this._errorProcessing([file], error); 993 } else { 994 file.accepted = true; 995 if (_this.options.autoQueue) { 996 _this.enqueueFile(file); 997 } 998 } 999 return _this._updateMaxFilesReachedClass(); 1000 }; 1001 })(this)); 1002 }; 1003 1004 Dropzone.prototype.enqueueFiles = function(files) { 1005 var file, _i, _len; 1006 for (_i = 0, _len = files.length; _i < _len; _i++) { 1007 file = files[_i]; 1008 this.enqueueFile(file); 1009 } 1010 return null; 1011 }; 1012 1013 Dropzone.prototype.enqueueFile = function(file) { 1014 if (file.status === Dropzone.ADDED && file.accepted === true) { 1015 file.status = Dropzone.QUEUED; 1016 if (this.options.autoProcessQueue) { 1017 return setTimeout(((function(_this) { 1018 return function() { 1019 return _this.processQueue(); 1020 }; 1021 })(this)), 0); 1022 } 1023 } else { 1024 throw new Error("This file can't be queued because it has already been processed or was rejected."); 1025 } 1026 }; 1027 1028 Dropzone.prototype._thumbnailQueue = []; 1029 1030 Dropzone.prototype._processingThumbnail = false; 1031 1032 Dropzone.prototype._enqueueThumbnail = function(file) { 1033 if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) { 1034 this._thumbnailQueue.push(file); 1035 return setTimeout(((function(_this) { 1036 return function() { 1037 return _this._processThumbnailQueue(); 1038 }; 1039 })(this)), 0); 1040 } 1041 }; 1042 1043 Dropzone.prototype._processThumbnailQueue = function() { 1044 if (this._processingThumbnail || this._thumbnailQueue.length === 0) { 1045 return; 1046 } 1047 this._processingThumbnail = true; 1048 return this.createThumbnail(this._thumbnailQueue.shift(), (function(_this) { 1049 return function() { 1050 _this._processingThumbnail = false; 1051 return _this._processThumbnailQueue(); 1052 }; 1053 })(this)); 1054 }; 1055 1056 Dropzone.prototype.removeFile = function(file) { 1057 if (file.status === Dropzone.UPLOADING) { 1058 this.cancelUpload(file); 1059 } 1060 this.files = without(this.files, file); 1061 this.emit("removedfile", file); 1062 if (this.files.length === 0) { 1063 return this.emit("reset"); 1064 } 1065 }; 1066 1067 Dropzone.prototype.removeAllFiles = function(cancelIfNecessary) { 1068 var file, _i, _len, _ref; 1069 if (cancelIfNecessary == null) { 1070 cancelIfNecessary = false; 1071 } 1072 _ref = this.files.slice(); 1073 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1074 file = _ref[_i]; 1075 if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) { 1076 this.removeFile(file); 1077 } 1078 } 1079 return null; 1080 }; 1081 1082 Dropzone.prototype.createThumbnail = function(file, callback) { 1083 var fileReader; 1084 fileReader = new FileReader; 1085 fileReader.onload = (function(_this) { 1086 return function() { 1087 if (file.type === "image/svg+xml") {
1088 _this.emit("thumbnail", file, fileReader.result); 1089 if (callback != null) { 1090 callback(); 1091 } 1092 return; 1093 } 1094 return _this.createThumbnailFromUrl(file, fileReader.result, callback); 1095 }; 1096 })(this); 1097 return fileReader.readAsDataURL(file); 1098 }; 1099 1100 Dropzone.prototype.createThumbnailFromUrl = function(file, imageUrl, callback, crossOrigin) { 1101 var img; 1102 img = document.createElement("img"); 1103 if (crossOrigin) { 1104 img.crossOrigin = crossOrigin; 1105 } 1106 img.onload = (function(_this) { 1107 return function() { 1108 var canvas, ctx, resizeInfo, thumbnail, _ref, _ref1, _ref2, _ref3; 1109 file.width = img.width; 1110 file.height = img.height; 1111 resizeInfo = _this.options.resize.call(_this, file); 1112 if (resizeInfo.trgWidth == null) { 1113 resizeInfo.trgWidth = resizeInfo.optWidth; 1114 } 1115 if (resizeInfo.trgHeight == null) { 1116 resizeInfo.trgHeight = resizeInfo.optHeight; 1117 } 1118 canvas = document.createElement("canvas"); 1119 ctx = canvas.getContext("2d"); 1120 canvas.width = resizeInfo.trgWidth; 1121 canvas.height = resizeInfo.trgHeight; 1122 drawImageIOSFix(ctx, img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight); 1123 thumbnail = canvas.toDataURL("image/png"); 1124 _this.emit("thumbnail", file, thumbnail); 1125 if (callback != null) { 1126 return callback(); 1127 } 1128 }; 1129 })(this); 1130 if (callback != null) { 1131 img.onerror = callback; 1132 } 1133 return img.src = imageUrl; 1134 }; 1135 1136 Dropzone.prototype.processQueue = function() { 1137 var i, parallelUploads, processingLength, queuedFiles; 1138 parallelUploads = this.options.parallelUploads; 1139 processingLength = this.getUploadingFiles().length; 1140 i = processingLength; 1141 if (processingLength >= parallelUploads) { 1142 return; 1143 } 1144 queuedFiles = this.getQueuedFiles(); 1145 if (!(queuedFiles.length > 0)) { 1146 return; 1147 } 1148 if (this.options.uploadMultiple) { 1149 return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength)); 1150 } else { 1151 while (i < parallelUploads) { 1152 if (!queuedFiles.length) { 1153 return; 1154 } 1155 this.processFile(queuedFiles.shift()); 1156 i++; 1157 } 1158 } 1159 }; 1160 1161 Dropzone.prototype.processFile = function(file) { 1162 return this.processFiles([file]); 1163 }; 1164 1165 Dropzone.prototype.processFiles = function(files) { 1166 var file, _i, _len; 1167 for (_i = 0, _len = files.length; _i < _len; _i++) { 1168 file = files[_i]; 1169 file.processing = true; 1170 file.status = Dropzone.UPLOADING; 1171 this.emit("processing", file); 1172 } 1173 if (this.options.uploadMultiple) { 1174 this.emit("processingmultiple", files); 1175 } 1176 return this.uploadFiles(files); 1177 }; 1178 1179 Dropzone.prototype._getFilesWithXhr = function(xhr) { 1180 var file, files; 1181 return files = (function() { 1182 var _i, _len, _ref, _results; 1183 _ref = this.files; 1184 _results = []; 1185 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1186 file = _ref[_i]; 1187 if (file.xhr === xhr) { 1188 _results.push(file); 1189 } 1190 } 1191 return _results; 1192 }).call(this); 1193 }; 1194 1195 Dropzone.prototype.cancelUpload = function(file) { 1196 var groupedFile, groupedFiles, _i, _j, _len, _len1, _ref; 1197 if (file.status === Dropzone.UPLOADING) { 1198 groupedFiles = this._getFilesWithXhr(file.xhr); 1199 for (_i = 0, _len = groupedFiles.length; _i < _len; _i++) { 1200 groupedFile = groupedFiles[_i]; 1201 groupedFile.status = Dropzone.CANCELED; 1202 } 1203 file.xhr.abort(); 1204 for (_j = 0, _len1 = groupedFiles.length; _j < _len1; _j++) { 1205 groupedFile = groupedFiles[_j];
1206 this.emit("canceled", groupedFile); 1207 } 1208 if (this.options.uploadMultiple) { 1209 this.emit("canceledmultiple", groupedFiles); 1210 } 1211 } else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.QUEUED) { 1212 file.status = Dropzone.CANCELED; 1213 this.emit("canceled", file); 1214 if (this.options.uploadMultiple) { 1215 this.emit("canceledmultiple", [file]); 1216 } 1217 } 1218 if (this.options.autoProcessQueue) { 1219 return this.processQueue(); 1220 } 1221 }; 1222 1223 resolveOption = function() { 1224 var args, option; 1225 option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 1226 if (typeof option === 'function') { 1227 return option.apply(this, args); 1228 } 1229 return option; 1230 }; 1231 1232 Dropzone.prototype.uploadFile = function(file) { 1233 return this.uploadFiles([file]); 1234 }; 1235 1236 Dropzone.prototype.uploadFiles = function(files) { 1237 var file, formData, handleError, headerName, headerValue, headers, i, input, inputName, inputType, key, method, option, progressObj, response, updateProgress, url, value, xhr, _i, _j, _k, _l, _len, _len1, _len2, _len3, _m, _ref, _ref1, _ref2, _ref3, _ref4, _ref5; 1238 xhr = new XMLHttpRequest(); 1239 for (_i = 0, _len = files.length; _i < _len; _i++) { 1240 file = files[_i]; 1241 file.xhr = xhr; 1242 } 1243 method = resolveOption(this.options.method, files); 1244 var questionmark = "?"; 1245 if(this.options.url.indexOf("?") > 0){ 1246 questionmark = "&"; 1247 } 1248 1249 var uploadDir = "&dir="+$("input[name=dir]").val()+"&"; 1250 if(this.options.url.indexOf("dir") > 0){ 1251 uploadDir = "&"; 1252 } 1253 var width = "&width="+$("input[name=width]").val(); 1254 if(this.options.url.indexOf("width") > 0){ 1255 width = "&"; 1256 } 1257 var height = "&height="+$("input[name=height]").val(); 1258 if(this.options.url.indexOf("height") > 0){ 1259 width = "&"; 1260 } 1261 1262 url = resolveOption(this.options.url, files)+questionmark+uploadDir+"id="+$("input[name=id]").val()+"&filename="+$("input[name=filename]").val()+width+height; 1263 xhr.open(method, url, true); 1264 xhr.withCredentials = !!this.options.withCredentials; 1265 response = null; 1266 handleError = (function(_this) { 1267 return function() { 1268 var _j, _len1, _results; 1269 _results = []; 1270 for (_j = 0, _len1 = files.length; _j < _len1; _j++) { 1271 file = files[_j]; 1272 _results.push(_this._errorProcessing(files, response || _this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr)); 1273 } 1274 return _results; 1275 }; 1276 })(this); 1277 updateProgress = (function(_this) { 1278 return function(e) { 1279 var allFilesFinished, progress, _j, _k, _l, _len1, _len2, _len3, _results; 1280 if (e != null) { 1281 progress = 100 * e.loaded / e.total; 1282 for (_j = 0, _len1 = files.length; _j < _len1; _j++) { 1283 file = files[_j]; 1284 file.upload = { 1285 progress: progress, 1286 total: e.total, 1287 bytesSent: e.loaded 1288 }; 1289 } 1290 } else { 1291 allFilesFinished = true; 1292 progress = 100; 1293 for (_k = 0, _len2 = files.length; _k < _len2; _k++) { 1294 file = files[_k]; 1295 if (!(file.upload.progress === 100 && file.upload.b
1295ytesSent === file.upload.total)) { 1296 allFilesFinished = false; 1297 } 1298 file.upload.progress = progress; 1299 file.upload.bytesSent = file.upload.total; 1300 } 1301 if (allFilesFinished) { 1302 return; 1303 } 1304 } 1305 _results = []; 1306 for (_l = 0, _len3 = files.length; _l < _len3; _l++) { 1307 file = files[_l]; 1308 _results.push(_this.emit("uploadprogress", file, progress, file.upload.bytesSent)); 1309 } 1310 return _results; 1311 }; 1312 })(this); 1313 xhr.onload = (function(_this) { 1314 return function(e) { 1315 var _ref; 1316 if (files[0].status === Dropzone.CANCELED) { 1317 return; 1318 } 1319 if (xhr.readyState !== 4) { 1320 return; 1321 } 1322 response = xhr.responseText; 1323 if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) { 1324 try { 1325 response = JSON.parse(response); 1326 } catch (_error) { 1327 e = _error; 1328 response = "Invalid JSON response from server."; 1329 } 1330 } 1331 updateProgress(); 1332 if (!((200 <= (_ref = xhr.status) && _ref < 300))) { 1333 return handleError(); 1334 } else { 1335 return _this._finished(files, response, e); 1336 } 1337 }; 1338 })(this); 1339 xhr.onerror = (function(_this) { 1340 return function() { 1341 if (files[0].status === Dropzone.CANCELED) { 1342 return; 1343 } 1344 return handleError(); 1345 }; 1346 })(this); 1347 progressObj = (_ref = xhr.upload) != null ? _ref : xhr; 1348 progressObj.onprogress = updateProgress; 1349 headers = { 1350 "Accept": "application/json", 1351 "Cache-Control": "no-cache", 1352 "X-Requested-With": "XMLHttpRequest" 1353 }; 1354 if (this.options.headers) { 1355 extend(headers, this.options.headers); 1356 } 1357 for (headerName in headers) { 1358 headerValue = headers[headerName]; 1359 if (headerValue) { 1360 xhr.setRequestHeader(headerName, headerValue); 1361 } 1362 } 1363 formData = new FormData(); 1364 if (this.options.params) { 1365 _ref1 = this.options.params; 1366 for (key in _ref1) { 1367 value = _ref1[key]; 1368 formData.append(key, value); 1369 } 1370 } 1371 for (_j = 0, _len1 = files.length; _j < _len1; _j++) { 1372 file = files[_j]; 1373 this.emit("sending", file, xhr, formData); 1374 } 1375 if (this.options.uploadMultiple) { 1376 this.emit("sendingmultiple", files, xhr, formData); 1377 } 1378 if (this.element.tagName === "FORM") { 1379 _ref2 = this.element.querySelectorAll("input, textarea, select, button"); 1380 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { 1381 input = _ref2[_k]; 1382 inputName = input.getAttribute("name"); 1383 inputType = input.getAttribute("type"); 1384 if (input.tagName === "SELECT" && input.hasAttribute("multiple")) { 1385 _ref3 = input.options; 1386 for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { 1387 option = _ref3[_l]; 1388 if (option.selected) { 1389 formData.append(inputName, option.value); 1390 } 1391 } 1392 } else if (!inputType || ((_ref4 = inputType.toLowerCase()) !== "checkbox" && _ref4 !== "radio") || input.checked) { 1393 formData.append(inputName, input.value); 1394 } 1395 } 1396 } 1397 for (i = _m = 0, _ref5 = files.length - 1; 0 <= _ref5 ? _m <= _ref5 : _m >= _ref5; i = 0 <= _ref5 ? ++_m : --_m) { 1398 formData.append(this._getParamName(i), files[i], this._renameFilename(files[i].name)); 1399 } 1400 return this.submitRequest(xhr, formData, files); 1401 }; 1402 1403 Dropzone.prototype.submitRequest = function(xhr, formData, files) { 1404 return xhr.send(formData); 1405 }; 1406 1407 Dropzone.prototype._finished = function(files, responseText, e) { 1408 var file, _i, _len; 1409 for (_i = 0, _len = files.length; _i < _len; _i++) { 1410 file = files[_i]; 1411 file.status = Dropzone.SUCCESS;
1412 this.emit("success", file, responseText, e); 1413 this.emit("complete", file); 1414 } 1415 if (this.options.uploadMultiple) { 1416 this.emit("successmultiple", files, responseText, e); 1417 this.emit("completemultiple", files); 1418 } 1419 if (this.options.autoProcessQueue) { 1420 return this.processQueue(); 1421 } 1422 }; 1423 1424 Dropzone.prototype._errorProcessing = function(files, message, xhr) { 1425 var file, _i, _len; 1426 for (_i = 0, _len = files.length; _i < _len; _i++) { 1427 file = files[_i]; 1428 file.status = Dropzone.ERROR; 1429 this.emit("error", file, message, xhr); 1430 this.emit("complete", file); 1431 } 1432 if (this.options.uploadMultiple) { 1433 this.emit("errormultiple", files, message, xhr); 1434 this.emit("completemultiple", files); 1435 } 1436 if (this.options.autoProcessQueue) { 1437 return this.processQueue(); 1438 } 1439 }; 1440 1441 return Dropzone; 1442 1443 })(Emitter); 1444 1445 Dropzone.version = "4.3.0"; 1446 1447 Dropzone.options = {}; 1448 1449 Dropzone.optionsForElement = function(element) { 1450 if (element.getAttribute("id")) { 1451 return Dropzone.options[camelize(element.getAttribute("id"))]; 1452 } else { 1453 return void 0; 1454 } 1455 }; 1456 1457 Dropzone.instances = []; 1458 1459 Dropzone.forElement = function(element) { 1460 if (typeof element === "string") { 1461 element = document.querySelector(element); 1462 } 1463 if ((element != null ? element.dropzone : void 0) == null) { 1464 throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone."); 1465 } 1466 return element.dropzone; 1467 }; 1468 1469 Dropzone.autoDiscover = true; 1470 1471 Dropzone.discover = function() { 1472 var checkElements, dropzone, dropzones, _i, _len, _results; 1473 if (document.querySelectorAll) { 1474 dropzones = document.querySelectorAll(".dropzone"); 1475 } else { 1476 dropzones = []; 1477 checkElements = function(elements) { 1478 var el, _i, _len, _results; 1479 _results = []; 1480 for (_i = 0, _len = elements.length; _i < _len; _i++) { 1481 el = elements[_i]; 1482 if (/(^| )dropzone($| )/.test(el.className)) { 1483 _results.push(dropzones.push(el)); 1484 } else { 1485 _results.push(void 0); 1486 } 1487 } 1488 return _results; 1489 }; 1490 checkElements(document.getElementsByTagName("div")); 1491 checkElements(document.getElementsByTagName("form")); 1492 } 1493 _results = []; 1494 for (_i = 0, _len = dropzones.length; _i < _len; _i++) { 1495 dropzone = dropzones[_i]; 1496 if (Dropzone.optionsForElement(dropzone) !== false) { 1497 _results.push(new Dropzone(dropzone)); 1498 } else { 1499 _results.push(void 0); 1500 } 1501 } 1502 return _results; 1503 }; 1504 1505 Dropzone.blacklistedBrowsers = [/opera.*Macintosh.*version\/12/i]; 1506 1507 Dropzone.isBrowserSupported = function() { 1508 var capableBrowser, regex, _i, _len, _ref; 1509 capableBrowser = true; 1510 if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) { 1511 if (!("classList" in document.createElement("a"))) { 1512 capableBrowser = false; 1513 } else { 1514 _ref = Dropzone.blacklistedBrowsers; 1515 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 1516 regex = _ref[_i]; 1517 if (regex.test(navigator.userAgent)) { 1518 capableBrowser = false; 1519 continue; 1520 } 1521 } 1522 } 1523 } else { 1524 capableBrowser = false; 1525 } 1526 return capableBrowser; 1527 }; 1528 1529 without = function(list, rejectedItem) { 1530 var item, _i, _len, _results; 1531 _results = []; 1532 for (_i = 0, _len = list.length; _i < _len; _i++) { 1533 item = list[_i];
1534 if (item !== rejectedItem) { 1535 _results.push(item); 1536 } 1537 } 1538 return _results; 1539 }; 1540 1541 camelize = function(str) { 1542 return str.replace(/[\-_](\w)/g, function(match) { 1543 return match.charAt(1).toUpperCase(); 1544 }); 1545 }; 1546 1547 Dropzone.createElement = function(string) { 1548 var div; 1549 div = document.createElement("div"); 1550 div.innerHTML = string; 1551 return div.childNodes[0]; 1552 }; 1553 1554 Dropzone.elementInside = function(element, container) { 1555 if (element === container) { 1556 return true; 1557 } 1558 while (element = element.parentNode) { 1559 if (element === container) { 1560 return true; 1561 } 1562 } 1563 return false; 1564 }; 1565 1566 Dropzone.getElement = function(el, name) { 1567 var element; 1568 if (typeof el === "string") { 1569 element = document.querySelector(el); 1570 } else if (el.nodeType != null) { 1571 element = el; 1572 } 1573 if (element == null) { 1574 throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector or a plain HTML element."); 1575 } 1576 return element; 1577 }; 1578 1579 Dropzone.getElements = function(els, name) { 1580 var e, el, elements, _i, _j, _len, _len1, _ref; 1581 if (els instanceof Array) { 1582 elements = []; 1583 try { 1584 for (_i = 0, _len = els.length; _i < _len; _i++) { 1585 el = els[_i]; 1586 elements.push(this.getElement(el, name)); 1587 } 1588 } catch (_error) { 1589 e = _error; 1590 elements = null; 1591 } 1592 } else if (typeof els === "string") { 1593 elements = []; 1594 _ref = document.querySelectorAll(els); 1595 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { 1596 el = _ref[_j]; 1597 elements.push(el); 1598 } 1599 } else if (els.nodeType != null) { 1600 elements = [els]; 1601 } 1602 if (!((elements != null) && elements.length)) { 1603 throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector, a plain HTML element or a list of those."); 1604 } 1605 return elements; 1606 }; 1607 1608 Dropzone.confirm = function(question, accepted, rejected) { 1609 if (window.confirm(question)) { 1610 return accepted(); 1611 } else if (rejected != null) { 1612 return rejected(); 1613 } 1614 }; 1615 1616 Dropzone.isValidFile = function(file, acceptedFiles) { 1617 var baseMimeType, mimeType, validType, _i, _len; 1618 if (!acceptedFiles) { 1619 return true; 1620 } 1621 acceptedFiles = acceptedFiles.split(","); 1622 mimeType = file.type; 1623 baseMimeType = mimeType.replace(/\/.*$/, ""); 1624 for (_i = 0, _len = acceptedFiles.length; _i < _len; _i++) { 1625 validType = acceptedFiles[_i]; 1626 validType = validType.trim(); 1627 if (validType.charAt(0) === ".") { 1628 if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) { 1629 return true; 1630 } 1631 } else if (/\/\*$/.test(validType)) { 1632 if (baseMimeType === validType.replace(/\/.*$/, "")) { 1633 return true; 1634 } 1635 } else { 1636 if (mimeType === validType) { 1637 return true; 1638 } 1639 } 1640 } 1641 return false; 1642 }; 1643 1644 if (typeof jQuery !== "undefined" && jQuery !== null) { 1645 jQuery.fn.dropzone = function(options) { 1646 return this.each(function() { 1647 return new Dropzone(this, options); 1648 }); 1649 }; 1650 } 1651 1652 if (typeof module !== "undefined" && module !== null) { 1653 module.exports = Dropzone; 1654 } else { 1655 window.Dropzone = Dropzone; 1656 } 1657 1658 Dropzone.ADDED = "added"; 1659 1660 Dropzone.QUEUED = "queued"; 1661 1662 Dropzone.ACCEPTED = Dropzone.QUEUED; 1663 1664 Dropzone.UPLOADING = "uploading"; 1665 1666 Dropzone.PROCESSING = Dropzone.UPLOADING; 1667 1668 Dropzone.CANCELED = "canceled"; 1669 1670 Dropzone.ERROR = "error"; 1671 1672 Dropzone.SUCCESS = "success"; 1673 1674 1675 /* 1676 1677 Bugfix for iOS 6 and 7 1678 Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios 1679 based on the work of https://github.com/stomita/ios-imagefile-megapixel 1680 */ 1681 1682 detectVerticalSquash = function(img) { 1683 var alpha, canvas, ctx, data, ey, ih, iw, py, ratio, sy;
1684 iw = img.naturalWidth; 1685 ih = img.naturalHeight; 1686 canvas = document.createElement("canvas"); 1687 canvas.width = 1; 1688 canvas.height = ih; 1689 ctx = canvas.getContext("2d"); 1690 ctx.drawImage(img, 0, 0); 1691 data = ctx.getImageData(0, 0, 1, ih).data; 1692 sy = 0; 1693 ey = ih; 1694 py = ih; 1695 while (py > sy) { 1696 alpha = data[(py - 1) * 4 + 3]; 1697 if (alpha === 0) { 1698 ey = py; 1699 } else { 1700 sy = py; 1701 } 1702 py = (ey + sy) >> 1; 1703 } 1704 ratio = py / ih; 1705 if (ratio === 0) { 1706 return 1; 1707 } else { 1708 return ratio; 1709 } 1710 }; 1711 1712 drawImageIOSFix = function(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) { 1713 var vertSquashRatio; 1714 vertSquashRatio = detectVerticalSquash(img); 1715 return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio); 1716 }; 1717 1718 1719 /* 1720 * contentloaded.js 1721 * 1722 * Author: Diego Perini (diego.perini at gmail.com) 1723 * Summary: cross-browser wrapper for DOMContentLoaded 1724 * Updated: 20101020 1725 * License: MIT 1726 * Version: 1.2 1727 * 1728 * URL: 1729 * http://javascript.nwbox.com/ContentLoaded/ 1730 * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE 1731 */ 1732 1733 contentLoaded = function(win, fn) { 1734 var add, doc, done, init, poll, pre, rem, root, top; 1735 done = false; 1736 top = true; 1737 doc = win.document; 1738 root = doc.documentElement; 1739 add = (doc.addEventListener ? "addEventListener" : "attachEvent"); 1740 rem = (doc.addEventListener ? "removeEventListener" : "detachEvent"); 1741 pre = (doc.addEventListener ? "" : "on"); 1742 init = function(e) { 1743 if (e.type === "readystatechange" && doc.readyState !== "complete") { 1744 return; 1745 } 1746 (e.type === "load" ? win : doc)[rem](pre + e.type, init, false); 1747 if (!done && (done = true)) { 1748 return fn.call(win, e.type || e); 1749 } 1750 }; 1751 poll = function() { 1752 var e; 1753 try { 1754 root.doScroll("left"); 1755 } catch (_error) { 1756 e = _error; 1757 setTimeout(poll, 50); 1758 return; 1759 } 1760 return init("poll"); 1761 }; 1762 if (doc.readyState !== "complete") { 1763 if (doc.createEventObject && root.doScroll) { 1764 try { 1765 top = !win.frameElement; 1766 } catch (_error) {} 1767 if (top) { 1768 poll(); 1769 } 1770 } 1771 doc[add](pre + "DOMContentLoaded", init, false); 1772 doc[add](pre + "readystatechange", init, false); 1773 return win[add](pre + "load", init, false); 1774 } 1775 }; 1776 1777 Dropzone._autoDiscoverFunction = function() { 1778 if (Dropzone.autoDiscover) { 1779 return Dropzone.discover(); 1780 } 1781 }; 1782 1783 contentLoaded(window, Dropzone._autoDiscoverFunction); 1784 1785}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.