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