diff --git a/README.md b/README.md index 4207f35..26ce456 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ [jQuery-File-Plugin](https://github.com/blueimp/jQuery-File-Upload) is a file upload plugin written by [Sebastian Tschan](https://github.com/blueimp). jQuery File Upload features multiple file selection, drag&drop support, progress bars and preview images for jQuery. Supports cross-domain, chunked and resumable file uploads and client-side image resizing. -jquery-fileupload-rails is a library that integrates jQuery File Upload for Rails 3.1 Asset Pipeline (Rails 3.2 supported). +jquery-fileupload-rails is a library that integrates jQuery Fule Upload for Rails 3.1 and higher. ## Plugin versions -* jQuery File Upload User Interface Plugin 6.11 -* jQuery File Upload Plugin 5.19.3 -* jQuery UI Widget 1.9.1+amd +* jQuery File Upload User Interface Plugin 8.8.5 +* jQuery File Upload Plugin 5.32.6 +* jQuery UI Widget 1.10.3+amd ## Installing Gem @@ -22,15 +22,13 @@ Require jquery-fileupload in your app/assets/application.js file. The snippet above will add the following js files to the mainfest file. - //= require jquery-fileupload/vendor/jquery.ui.widget - //= require jquery-fileupload/vendor/load-image - //= require jquery-fileupload/vendor/canvas-to-blob - //= require jquery-fileupload/vendor/tmpl - //= require jquery-fileupload/jquery.iframe-transport - //= require jquery-fileupload/jquery.fileupload - //= require jquery-fileupload/jquery.fileupload-fp - //= require jquery-fileupload/jquery.fileupload-ui - //= require jquery-fileupload/locale + //=require jquery-fileupload/vendor/jquery.ui.widget + //=require jquery-fileupload/vendor/load-image/load-image + //=require jquery-fileupload/vendor/canvas-to-blob + //=require jquery-fileupload/vendor/tmpl + //=require jquery-fileupload/jquery.iframe-transport + //=require jquery-fileupload/jquery.fileupload + //=require jquery-fileupload/jquery.fileupload-ui If you only need the basic files, just add the code below to your application.js file. [Basic setup guide](https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin) @@ -42,12 +40,31 @@ The basic setup only includes the following files: //= require jquery-fileupload/jquery.iframe-transport //= require jquery-fileupload/jquery.fileupload -## Using the stylesheet +## Usign the stylesheet Require the stylesheet file to app/assets/stylesheets/application.css + *= require jquery.fileupload + +Or, if you are using jQuery UI + *= require jquery.fileupload-ui +## Using the load-image + +You can use full version of load-image library: + + //= require jquery-fileupload/vendor/load-image + +or use some parts: + + //= require ./load-image + //= require ./load-image-orientation + //= require ./load-image-meta + //= require ./load-image-ios + //= require ./load-image-exif + //= require ./load-image-exif-map + ## Using the middleware The `jquery.iframe-transport` fallback transport has some special caveats regarding the response data type, http status, and character encodings. `jquery-fileupload-rails` includes a middleware that handles these inconsistencies seamlessly. If you decide to use it, create an initializer that adds the middleware to your application's middleware stack. @@ -65,7 +82,7 @@ need a pro account to watch it though. Thanks to [Sebastian Tschan](https://github.com/blueimp) for writing an awesome file upload plugin. ## License -Copyright (c) 2012 Tors Dalid +Copyright (c) 2013 Tors Dalid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. diff --git a/vendor/assets/images/loading.gif b/app/assets/images/loading.gif old mode 100755 new mode 100644 similarity index 100% rename from vendor/assets/images/loading.gif rename to app/assets/images/loading.gif diff --git a/vendor/assets/images/progressbar.gif b/app/assets/images/progressbar.gif old mode 100755 new mode 100644 similarity index 100% rename from vendor/assets/images/progressbar.gif rename to app/assets/images/progressbar.gif diff --git a/vendor/assets/javascripts/jquery-fileupload/basic.js b/app/assets/javascripts/jquery-fileupload/basic.js similarity index 100% rename from vendor/assets/javascripts/jquery-fileupload/basic.js rename to app/assets/javascripts/jquery-fileupload/basic.js diff --git a/vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js b/app/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js old mode 100755 new mode 100644 similarity index 96% rename from vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js rename to app/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js index 931b635..2b4cbc5 --- a/vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +++ b/app/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js @@ -1,5 +1,5 @@ /* - * jQuery postMessage Transport Plugin 1.1 + * jQuery postMessage Transport Plugin 1.1.1 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2011, Sebastian Tschan @@ -64,8 +64,9 @@ xhrUpload = options.xhr().upload; return { send: function (_, completeCallback) { + counter += 1; var message = { - id: 'postmessage-transport-' + (counter += 1) + id: 'postmessage-transport-' + counter }, eventName = 'message.' + message.id; iframe = $( diff --git a/vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js b/app/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js old mode 100755 new mode 100644 similarity index 100% rename from vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js rename to app/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js diff --git a/vendor/assets/javascripts/jquery-fileupload/index.js b/app/assets/javascripts/jquery-fileupload/index.js similarity index 68% rename from vendor/assets/javascripts/jquery-fileupload/index.js rename to app/assets/javascripts/jquery-fileupload/index.js index 0cda385..532d1bc 100644 --- a/vendor/assets/javascripts/jquery-fileupload/index.js +++ b/app/assets/javascripts/jquery-fileupload/index.js @@ -1,9 +1,7 @@ //=require jquery-fileupload/vendor/jquery.ui.widget -//=require jquery-fileupload/vendor/load-image +//=require jquery-fileupload/vendor/load-image/load-image //=require jquery-fileupload/vendor/canvas-to-blob //=require jquery-fileupload/vendor/tmpl //=require jquery-fileupload/jquery.iframe-transport //=require jquery-fileupload/jquery.fileupload -//=require jquery-fileupload/jquery.fileupload-fp //=require jquery-fileupload/jquery.fileupload-ui -//=require jquery-fileupload/locale diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js old mode 100755 new mode 100644 similarity index 66% rename from vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js rename to app/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js index e7ba784..572be29 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload AngularJS Plugin 1.0.1 + * jQuery File Upload AngularJS Plugin 1.4.5 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2013, Sebastian Tschan @@ -10,20 +10,42 @@ */ /*jslint nomen: true, unparam: true */ -/*global angular */ +/*global define, angular */ -(function () { +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'angular', + './jquery.fileupload-image', + './jquery.fileupload-audio', + './jquery.fileupload-video', + './jquery.fileupload-validate' + ], factory); + } else { + factory(); + } +}(function () { 'use strict'; angular.module('blueimp.fileupload', []) + // The fileUpload service provides configuration options + // for the fileUpload directive and default handlers for + // File Upload events: .provider('fileUpload', function () { var scopeApply = function () { var scope = angular.element(this) - .fileupload('option', 'scope')(); - if (!scope.$$phase) { + .fileupload('option', 'scope')(), + $timeout = angular.injector(['ng']) + .get('$timeout'); + // Safe apply, makes sure $apply is called + // asynchronously outside of the $digest cycle: + $timeout(function () { scope.$apply(); - } + }); }, $config; $config = this.defaults = { @@ -47,19 +69,22 @@ submit = function () { return data.submit(); }; + angular.forEach(data.files, function (file, index) { + file._index = index; + file.$state = function () { + return data.state(); + }; + file.$progress = function () { + return data.progress(); + }; + file.$response = function () { + return data.response(); + }; + }); file.$cancel = function () { scope.clear(data.files); return data.abort(); }; - file.$state = function () { - return data.state(); - }; - file.$progress = function () { - return data.progress(); - }; - file.$response = function () { - return data.response(); - }; if (file.$state() === 'rejected') { file._$submit = submit; } else { @@ -96,10 +121,11 @@ if (data.errorThrown === 'abort') { return; } - if (data.dataType.indexOf('json') === data.dataType.length - 4) { + if (data.dataType && + data.dataType.indexOf('json') === data.dataType.length - 4) { try { data.result = angular.fromJson(data.jqXHR.responseText); - } catch (err) {} + } catch (ignore) {} } data.scope().$apply(function () { data.handleResponse.call(that, e, data); @@ -112,7 +138,6 @@ return this.scope().queue.length; }, dataType: 'json', - prependFiles: true, autoUpload: false }; this.$get = [ @@ -124,8 +149,9 @@ ]; }) + // Format byte numbers to readable presentations: .provider('formatFileSizeFilter', function () { - var $config = this.defaults = { + var $config = { // Byte units following the IEC format // http://en.wikipedia.org/wiki/Kilobyte units: [ @@ -134,28 +160,58 @@ {size: 1000, suffix: ' KB'} ] }; + this.defaults = $config; this.$get = function () { return function (bytes) { if (!angular.isNumber(bytes)) { return ''; } var unit = true, - i = -1; + i = 0, + prefix, + suffix; while (unit) { - unit = $config.units[i += 1]; + unit = $config.units[i]; + prefix = unit.prefix || ''; + suffix = unit.suffix || ''; if (i === $config.units.length - 1 || bytes >= unit.size) { - return (bytes / unit.size).toFixed(2) + unit.suffix; + return prefix + (bytes / unit.size).toFixed(2) + suffix; } + i += 1; } }; }; }) + // The FileUploadController initializes the fileupload widget and + // provides scope methods to control the File Upload functionality: .controller('FileUploadController', [ - '$scope', '$element', '$attrs', 'fileUpload', - function ($scope, $element, $attrs, fileUpload) { - $scope.disabled = angular.element('') - .prop('disabled'); + '$scope', '$element', '$attrs', '$window', 'fileUpload', + function ($scope, $element, $attrs, $window, fileUpload) { + var uploadMethods = { + progress: function () { + return $element.fileupload('progress'); + }, + active: function () { + return $element.fileupload('active'); + }, + option: function (option, data) { + return $element.fileupload('option', option, data); + }, + add: function (data) { + return $element.fileupload('add', data); + }, + send: function (data) { + return $element.fileupload('send', data); + }, + process: function (data) { + return $element.fileupload('process', data); + }, + processing: function (data) { + return $element.fileupload('processing', data); + } + }; + $scope.disabled = !$window.jQuery.support.fileInput; $scope.queue = $scope.queue || []; $scope.clear = function (files) { var queue = this.queue, @@ -167,7 +223,8 @@ length = files.length; } while (i) { - if (queue[i -= 1] === file) { + i -= 1; + if (queue[i] === file) { return queue.splice(i, length); } } @@ -186,27 +243,6 @@ } } }; - $scope.progress = function () { - return $element.fileupload('progress'); - }; - $scope.active = function () { - return $element.fileupload('active'); - }; - $scope.option = function (option, data) { - return $element.fileupload('option', option, data); - }; - $scope.add = function (data) { - return $element.fileupload('add', data); - }; - $scope.send = function (data) { - return $element.fileupload('send', data); - }; - $scope.process = function (data) { - return $element.fileupload('process', data); - }; - $scope.processing = function (data) { - return $element.fileupload('processing', data); - }; $scope.applyOnQueue = function (method) { var list = this.queue.slice(0), i, @@ -224,6 +260,8 @@ $scope.cancel = function () { this.applyOnQueue('$cancel'); }; + // Add upload methods to the scope: + angular.extend($scope, uploadMethods); // The fileupload widget will initialize with // the options provided via "data-"-parameters, // as well as those given via options object: @@ -260,12 +298,23 @@ 'fileuploadprocessalways', 'fileuploadprocessstop' ].join(' '), function (e, data) { - $scope.$emit(e.type, data); + if ($scope.$emit(e.type, data).defaultPrevented) { + e.preventDefault(); + } + }).on('remove', function () { + // Remove upload methods from the scope, + // when the widget is removed: + var method; + for (method in uploadMethods) { + if (uploadMethods.hasOwnProperty(method)) { + delete $scope[method]; + } + } }); // Observe option changes: $scope.$watch( - $attrs.fileupload, - function (newOptions, oldOptions) { + $attrs.fileUpload, + function (newOptions) { if (newOptions) { $element.fileupload('option', newOptions); } @@ -274,10 +323,11 @@ } ]) + // Provide File Upload progress feedback: .controller('FileUploadProgressController', [ '$scope', '$attrs', '$parse', function ($scope, $attrs, $parse) { - var fn = $parse($attrs.progress), + var fn = $parse($attrs.fileUploadProgress), update = function () { var progress = fn($scope); if (!progress || !progress.total) { @@ -289,7 +339,7 @@ }; update(); $scope.$watch( - $attrs.progress + '.loaded', + $attrs.fileUploadProgress + '.loaded', function (newValue, oldValue) { if (newValue !== oldValue) { update(); @@ -299,10 +349,11 @@ } ]) + // Display File Upload previews: .controller('FileUploadPreviewController', [ '$scope', '$element', '$attrs', '$parse', function ($scope, $element, $attrs, $parse) { - var fn = $parse($attrs.preview), + var fn = $parse($attrs.fileUploadPreview), file = fn($scope); if (file.preview) { $element.append(file.preview); @@ -310,26 +361,30 @@ } ]) - .directive('fileupload', function () { + .directive('fileUpload', function () { return { - controller: 'FileUploadController' + controller: 'FileUploadController', + scope: true }; }) - .directive('progress', function () { + .directive('fileUploadProgress', function () { return { - controller: 'FileUploadProgressController' + controller: 'FileUploadProgressController', + scope: true }; }) - .directive('preview', function () { + .directive('fileUploadPreview', function () { return { controller: 'FileUploadPreviewController' }; }) + // Enhance the HTML5 download attribute to + // allow drag&drop of files to the desktop: .directive('download', function () { - return function (scope, elm, attrs) { + return function (scope, elm) { elm.on('dragstart', function (e) { try { e.originalEvent.dataTransfer.setData( @@ -340,9 +395,9 @@ elm.prop('href') ].join(':') ); - } catch (err) {} + } catch (ignore) {} }); }; }); -}()); +})); diff --git a/app/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js new file mode 100644 index 0000000..f59c2fa --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js @@ -0,0 +1,106 @@ +/* + * jQuery File Upload Audio Preview Plugin 1.0.3 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window, document */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'load-image', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery, + window.loadImage + ); + } +}(function ($, loadImage) { + 'use strict'; + + // Prepend to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.unshift( + { + action: 'loadAudio', + // Use the action as prefix for the "@" options: + prefix: true, + fileTypes: '@', + maxFileSize: '@', + disabled: '@disableAudioPreview' + }, + { + action: 'setAudio', + name: '@audioPreviewName', + disabled: '@disableAudioPreview' + } + ); + + // The File Upload Audio Preview plugin extends the fileupload widget + // with audio preview functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + // The regular expression for the types of audio files to load, + // matched against the file type: + loadAudioFileTypes: /^audio\/.*$/ + }, + + _audioElement: document.createElement('audio'), + + processActions: { + + // Loads the audio file given via data.files and data.index + // as audio element if the browser supports playing it. + // Accepts the options fileTypes (regular expression) + // and maxFileSize (integer) to limit the files to load: + loadAudio: function (data, options) { + if (options.disabled) { + return data; + } + var file = data.files[data.index], + url, + audio; + if (this._audioElement.canPlayType && + this._audioElement.canPlayType(file.type) && + ($.type(options.maxFileSize) !== 'number' || + file.size <= options.maxFileSize) && + (!options.fileTypes || + options.fileTypes.test(file.type))) { + url = loadImage.createObjectURL(file); + if (url) { + audio = this._audioElement.cloneNode(false); + audio.src = url; + audio.controls = true; + data.audio = audio; + return data; + } + } + return data; + }, + + // Sets the audio element as a property of the file object: + setAudio: function (data, options) { + if (data.audio && !options.disabled) { + data.files[data.index][options.name || 'preview'] = data.audio; + } + return data; + } + + } + + }); + +})); diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-resize.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js old mode 100755 new mode 100644 similarity index 56% rename from vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-resize.js rename to app/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js index ae5c5be..9e6d699 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-resize.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Image Resize Plugin 1.1.2 + * jQuery File Upload Image Preview & Resize Plugin 1.3.0 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2013, Sebastian Tschan @@ -10,7 +10,7 @@ */ /*jslint nomen: true, unparam: true, regexp: true */ -/*global define, window */ +/*global define, window, document, DataView, Blob, Uint8Array */ (function (factory) { 'use strict'; @@ -19,6 +19,9 @@ define([ 'jquery', 'load-image', + 'load-image-meta', + 'load-image-exif', + 'load-image-ios', 'canvas-to-blob', './jquery.fileupload-process' ], factory); @@ -34,41 +37,61 @@ // Prepend to the default processQueue: $.blueimp.fileupload.prototype.options.processQueue.unshift( + { + action: 'loadImageMetaData', + disableImageHead: '@', + disableExif: '@', + disableExifThumbnail: '@', + disableExifSub: '@', + disableExifGps: '@', + disabled: '@disableImageMetaDataLoad' + }, { action: 'loadImage', - fileTypes: '@loadImageFileTypes', - maxFileSize: '@loadImageMaxFileSize', - noRevoke: '@loadImageNoRevoke', + // Use the action as prefix for the "@" options: + prefix: true, + fileTypes: '@', + maxFileSize: '@', + noRevoke: '@', disabled: '@disableImageLoad' }, { action: 'resizeImage', - maxWidth: '@imageMaxWidth', - maxHeight: '@imageMaxHeight', - minWidth: '@imageMinWidth', - minHeight: '@imageMinHeight', - crop: '@imageCrop', + // Use "image" as prefix for the "@" options: + prefix: 'image', + maxWidth: '@', + maxHeight: '@', + minWidth: '@', + minHeight: '@', + crop: '@', + orientation: '@', disabled: '@disableImageResize' }, { action: 'saveImage', disabled: '@disableImageResize' }, + { + action: 'saveImageMetaData', + disabled: '@disableImageMetaDataSave' + }, { action: 'resizeImage', - maxWidth: '@previewMaxWidth', - maxHeight: '@previewMaxHeight', - minWidth: '@previewMinWidth', - minHeight: '@previewMinHeight', - crop: '@previewCrop', - canvas: '@previewAsCanvas', + // Use "preview" as prefix for the "@" options: + prefix: 'preview', + maxWidth: '@', + maxHeight: '@', + minWidth: '@', + minHeight: '@', + crop: '@', + orientation: '@', + thumbnail: '@', + canvas: '@', disabled: '@disableImagePreview' }, { action: 'setImage', - // The name of the property the resized image - // is saved as on the associated file object: - name: 'preview', + name: '@imagePreviewName', disabled: '@disableImagePreview' } ); @@ -82,11 +105,14 @@ // matched against the file type: loadImageFileTypes: /^image\/(gif|jpeg|png)$/, // The maximum file size of images to load: - loadImageMaxFileSize: 5000000, // 5MB + loadImageMaxFileSize: 10000000, // 10MB // The maximum width of resized images: imageMaxWidth: 1920, // The maximum height of resized images: imageMaxHeight: 1080, + // Defines the image orientation (1-8) or takes the orientation + // value from Exif data if set to true: + imageOrientation: false, // Define if resized images should be cropped or only scaled: imageCrop: false, // Disable the resize image functionality by default: @@ -95,16 +121,21 @@ previewMaxWidth: 80, // The maximum height of the preview images: previewMaxHeight: 80, + // Defines the preview orientation (1-8) or takes the orientation + // value from Exif data if set to true: + previewOrientation: true, + // Create the preview using the Exif data thumbnail: + previewThumbnail: true, // Define if preview images should be cropped or only scaled: previewCrop: false, // Define if preview images should be resized as canvas elements: - previewAsCanvas: true + previewCanvas: true }, processActions: { // Loads the image given via data.files and data.index - // as img element if the browser supports canvas. + // as img element, if the browser supports the File API. // Accepts the options fileTypes (regular expression) // and maxFileSize (integer) to limit the files to load: loadImage: function (data, options) { @@ -121,34 +152,56 @@ !loadImage( file, function (img) { - if (!img.src) { - return dfd.rejectWith(that, [data]); + if (img.src) { + data.img = img; } - data.img = img; dfd.resolveWith(that, [data]); }, options )) { - dfd.rejectWith(that, [data]); + return data; } return dfd.promise(); }, // Resizes the image given as data.canvas or data.img // and updates data.canvas or data.img with the resized image. + // Also stores the resized image as preview property. // Accepts the options maxWidth, maxHeight, minWidth, // minHeight, canvas and crop: resizeImage: function (data, options) { + if (options.disabled) { + return data; + } options = $.extend({canvas: true}, options); - var img = (options.canvas && data.canvas) || data.img, - canvas; - if (img && !options.disabled) { - canvas = loadImage.scale(img, options); - if (canvas && (canvas.width !== img.width || - canvas.height !== img.height)) { - data[canvas.getContext ? 'canvas' : 'img'] = canvas; + var that = this, + dfd = $.Deferred(), + img = (options.canvas && data.canvas) || data.img, + resolve = function (newImg) { + if (newImg && (newImg.width !== img.width || + newImg.height !== img.height)) { + data[newImg.getContext ? 'canvas' : 'img'] = newImg; + } + data.preview = newImg; + dfd.resolveWith(that, [data]); + }, + thumbnail; + if (data.exif) { + if (options.orientation === true) { + options.orientation = data.exif.get('Orientation'); + } + if (options.thumbnail) { + thumbnail = data.exif.get('Thumbnail'); + if (thumbnail) { + loadImage(thumbnail, resolve, options); + return dfd.promise(); + } } } + if (img) { + resolve(loadImage.scale(img, options)); + return dfd.promise(); + } return data; }, @@ -195,12 +248,41 @@ return dfd.promise(); }, + loadImageMetaData: function (data, options) { + if (options.disabled) { + return data; + } + var that = this, + dfd = $.Deferred(); + loadImage.parseMetaData(data.files[data.index], function (result) { + $.extend(data, result); + dfd.resolveWith(that, [data]); + }, options); + return dfd.promise(); + }, + + saveImageMetaData: function (data, options) { + if (!(data.imageHead && data.canvas && + data.canvas.toBlob && !options.disabled)) { + return data; + } + var file = data.files[data.index], + blob = new Blob([ + data.imageHead, + // Resized images always have a head size of 20 bytes, + // including the JPEG marker and a minimal JFIF header: + this._blobSlice.call(file, 20) + ], {type: file.type}); + blob.name = file.name; + data.files[data.index] = blob; + return data; + }, + // Sets the resized version of the image as a property of the // file object, must be called after "saveImage": setImage: function (data, options) { - var img = data.canvas || data.img; - if (img && !options.disabled) { - data.files[data.index][options.name] = img; + if (data.preview && !options.disabled) { + data.files[data.index][options.name || 'preview'] = data.preview; } return data; } diff --git a/app/assets/javascripts/jquery-fileupload/jquery.fileupload-jquery-ui.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-jquery-ui.js new file mode 100755 index 0000000..05dd7a6 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-jquery-ui.js @@ -0,0 +1,138 @@ +/* + * jQuery File Upload jQuery UI Plugin 8.7.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true */ +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['jquery', './jquery.fileupload-ui'], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + progress: function (e, data) { + if (data.context) { + data.context.find('.progress').progressbar( + 'option', + 'value', + parseInt(data.loaded / data.total * 100, 10) + ); + } + }, + progressall: function (e, data) { + var $this = $(this); + $this.find('.fileupload-progress') + .find('.progress').progressbar( + 'option', + 'value', + parseInt(data.loaded / data.total * 100, 10) + ).end() + .find('.progress-extended').each(function () { + $(this).html( + ($this.data('blueimp-fileupload') || + $this.data('fileupload')) + ._renderExtendedProgress(data) + ); + }); + } + }, + + _renderUpload: function (func, files) { + var node = this._super(func, files), + showIconText = $(window).width() > 480; + node.find('.progress').empty().progressbar(); + node.find('.start').button({ + icons: {primary: 'ui-icon-circle-arrow-e'}, + text: showIconText + }); + node.find('.cancel').button({ + icons: {primary: 'ui-icon-cancel'}, + text: showIconText + }); + return node; + }, + + _renderDownload: function (func, files) { + var node = this._super(func, files), + showIconText = $(window).width() > 480; + node.find('.delete').button({ + icons: {primary: 'ui-icon-trash'}, + text: showIconText + }); + return node; + }, + + _transition: function (node) { + var deferred = $.Deferred(); + if (node.hasClass('fade')) { + node.fadeToggle( + this.options.transitionDuration, + this.options.transitionEasing, + function () { + deferred.resolveWith(node); + } + ); + } else { + deferred.resolveWith(node); + } + return deferred; + }, + + _create: function () { + this._super(); + this.element + .find('.fileupload-buttonbar') + .find('.fileinput-button').each(function () { + var input = $(this).find('input:file').detach(); + $(this) + .button({icons: {primary: 'ui-icon-plusthick'}}) + .append(input); + }) + .end().find('.start') + .button({icons: {primary: 'ui-icon-circle-arrow-e'}}) + .end().find('.cancel') + .button({icons: {primary: 'ui-icon-cancel'}}) + .end().find('.delete') + .button({icons: {primary: 'ui-icon-trash'}}) + .end().find('.progress').progressbar(); + }, + + _destroy: function () { + this.element + .find('.fileupload-buttonbar') + .find('.fileinput-button').each(function () { + var input = $(this).find('input:file').detach(); + $(this) + .button('destroy') + .append(input); + }) + .end().find('.start') + .button('destroy') + .end().find('.cancel') + .button('destroy') + .end().find('.delete') + .button('destroy') + .end().find('.progress').progressbar('destroy'); + this._super(); + } + + }); + +})); diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js old mode 100755 new mode 100644 similarity index 91% rename from vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js rename to app/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js index 2f9eeed..87042c3 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Processing Plugin 1.1 + * jQuery File Upload Processing Plugin 1.2.2 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2012, Sebastian Tschan @@ -98,14 +98,20 @@ _transformProcessQueue: function (options) { var processQueue = []; $.each(options.processQueue, function () { - var settings = {}; + var settings = {}, + action = this.action, + prefix = this.prefix === true ? action : this.prefix; $.each(this, function (key, value) { if ($.type(value) === 'string' && value.charAt(0) === '@') { - settings[key] = options[value.slice(1)]; + settings[key] = options[ + value.slice(1) || (prefix ? prefix + + key.charAt(0).toUpperCase() + key.slice(1) : key) + ]; } else { settings[key] = value; } + }); processQueue.push(settings); }); @@ -127,7 +133,7 @@ if (this._processing === 0) { this._trigger('processstart'); } - $.each(data.files, function (index, file) { + $.each(data.files, function (index) { var opts = index ? $.extend({}, options) : options, func = function () { return that._processFile(opts); diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js old mode 100755 new mode 100644 similarity index 93% rename from vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js rename to app/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js index 5d22346..4006a64 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload User Interface Plugin 8.2.1 + * jQuery File Upload User Interface Plugin 8.8.5 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -19,7 +19,9 @@ define([ 'jquery', 'tmpl', - './jquery.fileupload-resize', + './jquery.fileupload-image', + './jquery.fileupload-audio', + './jquery.fileupload-video', './jquery.fileupload-validate' ], factory); } else { @@ -118,7 +120,7 @@ !$.support.transition && 'progress-animated' ) .attr('aria-valuenow', 100) - .find('.bar').css( + .children().first().css( 'width', '100%' ); @@ -137,8 +139,8 @@ if (data.context) { data.context.each(function (index) { var file = files[index] || - {error: 'Empty file upload result'}, - deferred = that._addFinishedDeferreds(); + {error: 'Empty file upload result'}; + deferred = that._addFinishedDeferreds(); that._transition($(this)).done( function () { var node = $(this); @@ -157,8 +159,9 @@ ); }); } else { - template = that._renderDownload(files) - .appendTo(that.options.filesContainer); + template = that._renderDownload(files)[ + that.options.prependFiles ? 'prependTo' : 'appendTo' + ](that.options.filesContainer); that._forceReflow(template); deferred = that._addFinishedDeferreds(); that._transition(template).done( @@ -213,8 +216,9 @@ } }); } else if (data.errorThrown !== 'abort') { - data.context = that._renderUpload(data.files) - .appendTo(that.options.filesContainer) + data.context = that._renderUpload(data.files)[ + that.options.prependFiles ? 'prependTo' : 'appendTo' + ](that.options.filesContainer) .data('data', data); that._forceReflow(data.context); deferred = that._addFinishedDeferreds(); @@ -234,14 +238,16 @@ }, // Callback for upload progress events: progress: function (e, data) { + var progress = Math.floor(data.loaded / data.total * 100); if (data.context) { - var progress = Math.floor(data.loaded / data.total * 100); - data.context.find('.progress') - .attr('aria-valuenow', progress) - .find('.bar').css( - 'width', - progress + '%' - ); + data.context.each(function () { + $(this).find('.progress') + .attr('aria-valuenow', progress) + .children().first().css( + 'width', + progress + '%' + ); + }); } }, // Callback for global upload progress events: @@ -260,7 +266,7 @@ globalProgressNode .find('.progress') .attr('aria-valuenow', progress) - .find('.bar').css( + .children().first().css( 'width', progress + '%' ); @@ -289,7 +295,7 @@ function () { $(this).find('.progress') .attr('aria-valuenow', '0') - .find('.bar').css('width', '0%'); + .children().first().css('width', '0%'); $(this).find('.progress-extended').html(' '); deferred.resolve(); } @@ -304,16 +310,19 @@ // Callback for file deletion: destroy: function (e, data) { var that = $(this).data('blueimp-fileupload') || - $(this).data('fileupload'); - if (data.url) { - $.ajax(data).done(function () { + $(this).data('fileupload'), + removeNode = function () { that._transition(data.context).done( function () { $(this).remove(); that._trigger('destroyed', e, data); } ); - }); + }; + if (data.url) { + $.ajax(data).done(removeNode); + } else { + removeNode(); } } }, @@ -453,9 +462,11 @@ _cancelHandler: function (e) { e.preventDefault(); - var template = $(e.currentTarget).closest('.template-upload'), + var template = $(e.currentTarget) + .closest('.template-upload,.template-download'), data = template.data('data') || {}; if (!data.jqXHR) { + data.context = data.context || template; data.errorThrown = 'abort'; this._trigger('fail', e, data); } else { @@ -606,6 +617,9 @@ _create: function () { this._super(); this._resetFinishedDeferreds(); + if (!$.support.fileInput) { + this._disableFileInputButton(); + } }, enable: function () { diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js old mode 100755 new mode 100644 similarity index 85% rename from vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js rename to app/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js index 2599da8..ee1c2f2 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Validation Plugin 1.0.2 + * jQuery File Upload Validation Plugin 1.1.1 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2013, Sebastian Tschan @@ -37,10 +37,10 @@ // even if the previous action was rejected: always: true, // Options taken from the global options map: - acceptFileTypes: '@acceptFileTypes', - maxFileSize: '@maxFileSize', - minFileSize: '@minFileSize', - maxNumberOfFiles: '@maxNumberOfFiles', + acceptFileTypes: '@', + maxFileSize: '@', + minFileSize: '@', + maxNumberOfFiles: '@', disabled: '@disableValidation' } ); @@ -83,16 +83,17 @@ } var dfd = $.Deferred(), settings = this.options, - file = data.files[data.index], - numberOfFiles = settings.getNumberOfFiles(); - if (numberOfFiles && $.type(options.maxNumberOfFiles) === 'number' && - numberOfFiles + data.files.length > options.maxNumberOfFiles) { + file = data.files[data.index]; + if ($.type(options.maxNumberOfFiles) === 'number' && + (settings.getNumberOfFiles() || 0) + data.files.length > + options.maxNumberOfFiles) { file.error = settings.i18n('maxNumberOfFiles'); } else if (options.acceptFileTypes && !(options.acceptFileTypes.test(file.type) || options.acceptFileTypes.test(file.name))) { file.error = settings.i18n('acceptFileTypes'); - } else if (options.maxFileSize && file.size > options.maxFileSize) { + } else if (options.maxFileSize && file.size > + options.maxFileSize) { file.error = settings.i18n('maxFileSize'); } else if ($.type(file.size) === 'number' && file.size < options.minFileSize) { diff --git a/app/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js new file mode 100644 index 0000000..c8b1019 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js @@ -0,0 +1,106 @@ +/* + * jQuery File Upload Video Preview Plugin 1.0.3 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global define, window, document */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + 'load-image', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery, + window.loadImage + ); + } +}(function ($, loadImage) { + 'use strict'; + + // Prepend to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.unshift( + { + action: 'loadVideo', + // Use the action as prefix for the "@" options: + prefix: true, + fileTypes: '@', + maxFileSize: '@', + disabled: '@disableVideoPreview' + }, + { + action: 'setVideo', + name: '@videoPreviewName', + disabled: '@disableVideoPreview' + } + ); + + // The File Upload Video Preview plugin extends the fileupload widget + // with video preview functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + // The regular expression for the types of video files to load, + // matched against the file type: + loadVideoFileTypes: /^video\/.*$/ + }, + + _videoElement: document.createElement('video'), + + processActions: { + + // Loads the video file given via data.files and data.index + // as video element if the browser supports playing it. + // Accepts the options fileTypes (regular expression) + // and maxFileSize (integer) to limit the files to load: + loadVideo: function (data, options) { + if (options.disabled) { + return data; + } + var file = data.files[data.index], + url, + video; + if (this._videoElement.canPlayType && + this._videoElement.canPlayType(file.type) && + ($.type(options.maxFileSize) !== 'number' || + file.size <= options.maxFileSize) && + (!options.fileTypes || + options.fileTypes.test(file.type))) { + url = loadImage.createObjectURL(file); + if (url) { + video = this._videoElement.cloneNode(false); + video.src = url; + video.controls = true; + data.video = video; + return data; + } + } + return data; + }, + + // Sets the video element as a property of the file object: + setVideo: function (data, options) { + if (data.video && !options.disabled) { + data.files[data.index][options.name || 'preview'] = data.video; + } + return data; + } + + } + + }); + +})); diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js b/app/assets/javascripts/jquery-fileupload/jquery.fileupload.js old mode 100755 new mode 100644 similarity index 94% rename from vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js rename to app/assets/javascripts/jquery-fileupload/jquery.fileupload.js index 03678f3..faa71a6 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.fileupload.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Plugin 5.31.1 + * jQuery File Upload Plugin 5.32.6 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -10,7 +10,7 @@ */ /*jslint nomen: true, unparam: true, regexp: true */ -/*global define, window, document, File, Blob, FormData, location */ +/*global define, window, document, location, File, Blob, FormData */ (function (factory) { 'use strict'; @@ -27,12 +27,28 @@ }(function ($) { 'use strict'; + // Detect file input support, based on + // http://viljamis.com/blog/2012/file-upload-support-on-mobile/ + $.support.fileInput = !(new RegExp( + // Handle devices which give false positives for the feature detection: + '(Android (1\\.[0156]|2\\.[01]))' + + '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' + + '|(w(eb)?OSBrowser)|(webOS)' + + '|(Kindle/(1\\.0|2\\.[05]|3\\.0))' + ).test(window.navigator.userAgent) || + // Feature detection for all other devices: + $('').prop('disabled')); + // The FileReader API is not actually used, but works as feature detection, // as e.g. Safari supports XHR file uploads via the FormData API, // but not non-multipart XHR file uploads: $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader); $.support.xhrFormDataFileUpload = !!window.FormData; + // Detect support for Blob slicing (required for chunked uploads): + $.support.blobSlice = window.Blob && (Blob.prototype.slice || + Blob.prototype.webkitSlice || Blob.prototype.mozSlice); + // The fileupload widget listens for change events on file input fields defined // via fileInput setting and paste or drop events of the given dropZone. // In addition to the default jQuery Widget methods, the fileupload widget @@ -144,13 +160,16 @@ // The add callback is invoked as soon as files are added to the fileupload // widget (via file input selection, drag & drop, paste or add API call). // If the singleFileUploads option is enabled, this callback will be - // called once for each file in the selection for XHR file uplaods, else + // called once for each file in the selection for XHR file uploads, else // once for each file selection. + // // The upload starts when the submit method is invoked on the data parameter. // The data object contains a files property holding the added files - // and allows to override plugin options as well as define ajax settings. + // and allows you to override plugin options as well as define ajax settings. + // // Listeners for this callback can also be bound the following way: // .bind('fileuploadadd', func); + // // data.submit() returns a Promise object and allows to attach additional // handlers using jQuery's Deferred callbacks: // data.submit().done(func).fail(func).always(func); @@ -233,6 +252,11 @@ 'forceIframeTransport' ], + _blobSlice: $.support.blobSlice && function () { + var slice = this.slice || this.webkitSlice || this.mozSlice; + return slice.apply(this, arguments); + }, + _BitrateTimer: function () { this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime()); this.loaded = 0; @@ -375,13 +399,15 @@ // Ignore non-multipart setting if not supported: multipart = options.multipart || !$.support.xhrFileUpload, paramName = options.paramName[0]; - options.headers = options.headers || {}; + options.headers = $.extend({}, options.headers); if (options.contentRange) { options.headers['Content-Range'] = options.contentRange; } - if (!multipart) { + if (!multipart || options.blob || !this._isInstanceOf('File', file)) { options.headers['Content-Disposition'] = 'attachment; filename="' + encodeURI(file.name) + '"'; + } + if (!multipart) { options.contentType = file.type; options.data = options.blob || file; } else if ($.support.xhrFormDataFileUpload) { @@ -414,8 +440,6 @@ }); } if (options.blob) { - options.headers['Content-Disposition'] = 'attachment; filename="' + - encodeURI(file.name) + '"'; formData.append(paramName, options.blob, file.name); } else { $.each(options.files, function (index, file) { @@ -439,13 +463,13 @@ }, _initIframeSettings: function (options) { + var targetHost = $('').prop('href', options.url).prop('host'); // Setting the dataType to iframe enables the iframe transport: options.dataType = 'iframe ' + (options.dataType || ''); // The iframe transport accepts a serialized array as form data: options.formData = this._getFormData(options); // Add redirect url to form data on cross-domain uploads: - if (options.redirect && $('').prop('href', options.url) - .prop('host') !== location.host) { + if (options.redirect && targetHost && targetHost !== location.host) { options.formData.push({ name: options.redirectParamName || 'redirect', value: options.redirect @@ -510,8 +534,10 @@ options.url = options.form.prop('action') || location.href; } // The HTTP request method must be "POST" or "PUT": - options.type = (options.type || options.form.prop('method') || '') - .toUpperCase(); + options.type = (options.type || + ($.type(options.form.prop('method')) === 'string' && + options.form.prop('method')) || '' + ).toUpperCase(); if (options.type !== 'POST' && options.type !== 'PUT' && options.type !== 'PATCH') { options.type = 'POST'; @@ -627,12 +653,13 @@ // should be uploaded in chunks, but does not invoke any // upload requests: _chunkedUpload: function (options, testOnly) { + options.uploadedBytes = options.uploadedBytes || 0; var that = this, file = options.files[0], fs = file.size, - ub = options.uploadedBytes = options.uploadedBytes || 0, + ub = options.uploadedBytes, mcs = options.maxChunkSize || fs, - slice = file.slice || file.webkitSlice || file.mozSlice, + slice = this._blobSlice, dfd = $.Deferred(), promise = dfd.promise(), jqXHR, @@ -850,7 +877,8 @@ this._slots.push(slot); pipe = slot.pipe(send); } else { - pipe = (this._sequence = this._sequence.pipe(send, send)); + this._sequence = this._sequence.pipe(send, send); + pipe = this._sequence; } // Return the piped Promise object, enhanced with an abort method, // which is delegated to the jqXHR object of the current upload, @@ -1092,17 +1120,16 @@ data.files.push(file); } }); - if (this._trigger('paste', e, data) === false || - this._onAdd(e, data) === false) { - return false; + if (this._trigger('paste', e, data) !== false) { + this._onAdd(e, data); } } }, _onDrop: function (e) { + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; var that = this, - dataTransfer = e.dataTransfer = e.originalEvent && - e.originalEvent.dataTransfer, + dataTransfer = e.dataTransfer, data = {}; if (dataTransfer && dataTransfer.files && dataTransfer.files.length) { e.preventDefault(); @@ -1116,14 +1143,16 @@ }, _onDragOver: function (e) { - var dataTransfer = e.dataTransfer = e.originalEvent && - e.originalEvent.dataTransfer; - if (dataTransfer) { - if (this._trigger('dragover', e) === false) { - return false; - } - if ($.inArray('Files', dataTransfer.types) !== -1) { - dataTransfer.dropEffect = 'copy'; + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var dataTransfer = e.dataTransfer, + data = { + dropEffect: 'copy', + preventDefault: true + }; + if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 && + this._trigger('dragover', e, data) !== false) { + dataTransfer.dropEffect = data.dropEffect; + if (data.preventDefault) { e.preventDefault(); } } @@ -1139,9 +1168,11 @@ paste: this._onPaste }); } - this._on(this.options.fileInput, { - change: this._onChange - }); + if ($.support.fileInput) { + this._on(this.options.fileInput, { + change: this._onChange + }); + } }, _destroyEventHandlers: function () { @@ -1275,6 +1306,10 @@ if (aborted) { return; } + if (!files.length) { + dfd.reject(); + return; + } data.files = files; jqXHR = that._onSend(null, data).then( function (result, textStatus, jqXHR) { diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js b/app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js old mode 100755 new mode 100644 similarity index 91% rename from vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js rename to app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js index e04e7a0..073c5fb --- a/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +++ b/app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js @@ -1,5 +1,5 @@ /* - * jQuery Iframe Transport Plugin 1.6.2 + * jQuery Iframe Transport Plugin 1.7 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2011, Sebastian Tschan @@ -170,7 +170,15 @@ }); // The iframe transport returns the iframe content document as response. - // The following adds converters from iframe to text, json, html, and script: + // The following adds converters from iframe to text, json, html, xml + // and script. + // Please note that the Content-Type for JSON responses has to be text/plain + // or text/html, if the browser doesn't include application/json in the + // Accept header, else IE will show a download dialog. + // The Content-Type for XML responses on the other hand has to be always + // application/xml or text/xml, so IE properly parses the XML response. + // See also + // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation $.ajaxSetup({ converters: { 'iframe text': function (iframe) { @@ -182,6 +190,12 @@ 'iframe html': function (iframe) { return iframe && $(iframe[0].body).html(); }, + 'iframe xml': function (iframe) { + var xmlDoc = iframe && iframe[0]; + return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc : + $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) || + $(xmlDoc.body).html()); + }, 'iframe script': function (iframe) { return iframe && $.globalEval($(iframe[0].body).text()); } diff --git a/vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js b/app/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js similarity index 100% rename from vendor/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js rename to app/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js diff --git a/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js b/app/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js similarity index 99% rename from vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js rename to app/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js index fd2948f..2d37089 100644 --- a/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +++ b/app/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js @@ -1,5 +1,5 @@ /* - * jQuery UI Widget 1.10.1+amd + * jQuery UI Widget 1.10.3+amd * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2013 jQuery Foundation and other contributors diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/index.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/index.js new file mode 100644 index 0000000..c3bba58 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/index.js @@ -0,0 +1,6 @@ +//= require ./load-image +//= require ./load-image-orientation +//= require ./load-image-meta +//= require ./load-image-ios +//= require ./load-image-exif +//= require ./load-image-exif-map diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-exif-map.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-exif-map.js new file mode 100644 index 0000000..ef8c6c7 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-exif-map.js @@ -0,0 +1,385 @@ +/* + * JavaScript Load Image Exif Map 1.0.1 + * https://github.com/blueimp/JavaScript-Load-Image + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Exif tags mapping based on + * https://github.com/jseidelin/exif-js + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['load-image', 'load-image-exif'], factory); + } else { + // Browser globals: + factory(window.loadImage); + } +}(function (loadImage) { + 'use strict'; + + var tags, + map, + prop; + + loadImage.ExifMap.prototype.tags = { + // ================= + // TIFF tags (IFD0): + // ================= + 0x0100: 'ImageWidth', + 0x0101: 'ImageHeight', + 0x8769: 'ExifIFDPointer', + 0x8825: 'GPSInfoIFDPointer', + 0xA005: 'InteroperabilityIFDPointer', + 0x0102: 'BitsPerSample', + 0x0103: 'Compression', + 0x0106: 'PhotometricInterpretation', + 0x0112: 'Orientation', + 0x0115: 'SamplesPerPixel', + 0x011C: 'PlanarConfiguration', + 0x0212: 'YCbCrSubSampling', + 0x0213: 'YCbCrPositioning', + 0x011A: 'XResolution', + 0x011B: 'YResolution', + 0x0128: 'ResolutionUnit', + 0x0111: 'StripOffsets', + 0x0116: 'RowsPerStrip', + 0x0117: 'StripByteCounts', + 0x0201: 'JPEGInterchangeFormat', + 0x0202: 'JPEGInterchangeFormatLength', + 0x012D: 'TransferFunction', + 0x013E: 'WhitePoint', + 0x013F: 'PrimaryChromaticities', + 0x0211: 'YCbCrCoefficients', + 0x0214: 'ReferenceBlackWhite', + 0x0132: 'DateTime', + 0x010E: 'ImageDescription', + 0x010F: 'Make', + 0x0110: 'Model', + 0x0131: 'Software', + 0x013B: 'Artist', + 0x8298: 'Copyright', + // ================== + // Exif Sub IFD tags: + // ================== + 0x9000: 'ExifVersion', // EXIF version + 0xA000: 'FlashpixVersion', // Flashpix format version + 0xA001: 'ColorSpace', // Color space information tag + 0xA002: 'PixelXDimension', // Valid width of meaningful image + 0xA003: 'PixelYDimension', // Valid height of meaningful image + 0xA500: 'Gamma', + 0x9101: 'ComponentsConfiguration', // Information about channels + 0x9102: 'CompressedBitsPerPixel', // Compressed bits per pixel + 0x927C: 'MakerNote', // Any desired information written by the manufacturer + 0x9286: 'UserComment', // Comments by user + 0xA004: 'RelatedSoundFile', // Name of related sound file + 0x9003: 'DateTimeOriginal', // Date and time when the original image was generated + 0x9004: 'DateTimeDigitized', // Date and time when the image was stored digitally + 0x9290: 'SubSecTime', // Fractions of seconds for DateTime + 0x9291: 'SubSecTimeOriginal', // Fractions of seconds for DateTimeOriginal + 0x9292: 'SubSecTimeDigitized', // Fractions of seconds for DateTimeDigitized + 0x829A: 'ExposureTime', // Exposure time (in seconds) + 0x829D: 'FNumber', + 0x8822: 'ExposureProgram', // Exposure program + 0x8824: 'SpectralSensitivity', // Spectral sensitivity + 0x8827: 'PhotographicSensitivity', // EXIF 2.3, ISOSpeedRatings in EXIF 2.2 + 0x8828: 'OECF', // Optoelectric conversion factor + 0x8830: 'SensitivityType', + 0x8831: 'StandardOutputSensitivity', + 0x8832: 'RecommendedExposureIndex', + 0x8833: 'ISOSpeed', + 0x8834: 'ISOSpeedLatitudeyyy', + 0x8835: 'ISOSpeedLatitudezzz', + 0x9201: 'ShutterSpeedValue', // Shutter speed + 0x9202: 'ApertureValue', // Lens aperture + 0x9203: 'BrightnessValue', // Value of brightness + 0x9204: 'ExposureBias', // Exposure bias + 0x9205: 'MaxApertureValue', // Smallest F number of lens + 0x9206: 'SubjectDistance', // Distance to subject in meters + 0x9207: 'MeteringMode', // Metering mode + 0x9208: 'LightSource', // Kind of light source + 0x9209: 'Flash', // Flash status + 0x9214: 'SubjectArea', // Location and area of main subject + 0x920A: 'FocalLength', // Focal length of the lens in mm + 0xA20B: 'FlashEnergy', // Strobe energy in BCPS + 0xA20C: 'SpatialFrequencyResponse', + 0xA20E: 'FocalPlaneXResolution', // Number of pixels in width direction per FPRUnit + 0xA20F: 'FocalPlaneYResolution', // Number of pixels in height direction per FPRUnit + 0xA210: 'FocalPlaneResolutionUnit', // Unit for measuring the focal plane resolution + 0xA214: 'SubjectLocation', // Location of subject in image + 0xA215: 'ExposureIndex', // Exposure index selected on camera + 0xA217: 'SensingMethod', // Image sensor type + 0xA300: 'FileSource', // Image source (3 == DSC) + 0xA301: 'SceneType', // Scene type (1 == directly photographed) + 0xA302: 'CFAPattern', // Color filter array geometric pattern + 0xA401: 'CustomRendered', // Special processing + 0xA402: 'ExposureMode', // Exposure mode + 0xA403: 'WhiteBalance', // 1 = auto white balance, 2 = manual + 0xA404: 'DigitalZoomRatio', // Digital zoom ratio + 0xA405: 'FocalLengthIn35mmFilm', + 0xA406: 'SceneCaptureType', // Type of scene + 0xA407: 'GainControl', // Degree of overall image gain adjustment + 0xA408: 'Contrast', // Direction of contrast processing applied by camera + 0xA409: 'Saturation', // Direction of saturation processing applied by camera + 0xA40A: 'Sharpness', // Direction of sharpness processing applied by camera + 0xA40B: 'DeviceSettingDescription', + 0xA40C: 'SubjectDistanceRange', // Distance to subject + 0xA420: 'ImageUniqueID', // Identifier assigned uniquely to each image + 0xA430: 'CameraOwnerName', + 0xA431: 'BodySerialNumber', + 0xA432: 'LensSpecification', + 0xA433: 'LensMake', + 0xA434: 'LensModel', + 0xA435: 'LensSerialNumber', + // ============== + // GPS Info tags: + // ============== + 0x0000: 'GPSVersionID', + 0x0001: 'GPSLatitudeRef', + 0x0002: 'GPSLatitude', + 0x0003: 'GPSLongitudeRef', + 0x0004: 'GPSLongitude', + 0x0005: 'GPSAltitudeRef', + 0x0006: 'GPSAltitude', + 0x0007: 'GPSTimeStamp', + 0x0008: 'GPSSatellites', + 0x0009: 'GPSStatus', + 0x000A: 'GPSMeasureMode', + 0x000B: 'GPSDOP', + 0x000C: 'GPSSpeedRef', + 0x000D: 'GPSSpeed', + 0x000E: 'GPSTrackRef', + 0x000F: 'GPSTrack', + 0x0010: 'GPSImgDirectionRef', + 0x0011: 'GPSImgDirection', + 0x0012: 'GPSMapDatum', + 0x0013: 'GPSDestLatitudeRef', + 0x0014: 'GPSDestLatitude', + 0x0015: 'GPSDestLongitudeRef', + 0x0016: 'GPSDestLongitude', + 0x0017: 'GPSDestBearingRef', + 0x0018: 'GPSDestBearing', + 0x0019: 'GPSDestDistanceRef', + 0x001A: 'GPSDestDistance', + 0x001B: 'GPSProcessingMethod', + 0x001C: 'GPSAreaInformation', + 0x001D: 'GPSDateStamp', + 0x001E: 'GPSDifferential', + 0x001F: 'GPSHPositioningError' + }; + + loadImage.ExifMap.prototype.stringValues = { + ExposureProgram: { + 0: 'Undefined', + 1: 'Manual', + 2: 'Normal program', + 3: 'Aperture priority', + 4: 'Shutter priority', + 5: 'Creative program', + 6: 'Action program', + 7: 'Portrait mode', + 8: 'Landscape mode' + }, + MeteringMode: { + 0: 'Unknown', + 1: 'Average', + 2: 'CenterWeightedAverage', + 3: 'Spot', + 4: 'MultiSpot', + 5: 'Pattern', + 6: 'Partial', + 255: 'Other' + }, + LightSource: { + 0: 'Unknown', + 1: 'Daylight', + 2: 'Fluorescent', + 3: 'Tungsten (incandescent light)', + 4: 'Flash', + 9: 'Fine weather', + 10: 'Cloudy weather', + 11: 'Shade', + 12: 'Daylight fluorescent (D 5700 - 7100K)', + 13: 'Day white fluorescent (N 4600 - 5400K)', + 14: 'Cool white fluorescent (W 3900 - 4500K)', + 15: 'White fluorescent (WW 3200 - 3700K)', + 17: 'Standard light A', + 18: 'Standard light B', + 19: 'Standard light C', + 20: 'D55', + 21: 'D65', + 22: 'D75', + 23: 'D50', + 24: 'ISO studio tungsten', + 255: 'Other' + }, + Flash: { + 0x0000: 'Flash did not fire', + 0x0001: 'Flash fired', + 0x0005: 'Strobe return light not detected', + 0x0007: 'Strobe return light detected', + 0x0009: 'Flash fired, compulsory flash mode', + 0x000D: 'Flash fired, compulsory flash mode, return light not detected', + 0x000F: 'Flash fired, compulsory flash mode, return light detected', + 0x0010: 'Flash did not fire, compulsory flash mode', + 0x0018: 'Flash did not fire, auto mode', + 0x0019: 'Flash fired, auto mode', + 0x001D: 'Flash fired, auto mode, return light not detected', + 0x001F: 'Flash fired, auto mode, return light detected', + 0x0020: 'No flash function', + 0x0041: 'Flash fired, red-eye reduction mode', + 0x0045: 'Flash fired, red-eye reduction mode, return light not detected', + 0x0047: 'Flash fired, red-eye reduction mode, return light detected', + 0x0049: 'Flash fired, compulsory flash mode, red-eye reduction mode', + 0x004D: 'Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected', + 0x004F: 'Flash fired, compulsory flash mode, red-eye reduction mode, return light detected', + 0x0059: 'Flash fired, auto mode, red-eye reduction mode', + 0x005D: 'Flash fired, auto mode, return light not detected, red-eye reduction mode', + 0x005F: 'Flash fired, auto mode, return light detected, red-eye reduction mode' + }, + SensingMethod: { + 1: 'Undefined', + 2: 'One-chip color area sensor', + 3: 'Two-chip color area sensor', + 4: 'Three-chip color area sensor', + 5: 'Color sequential area sensor', + 7: 'Trilinear sensor', + 8: 'Color sequential linear sensor' + }, + SceneCaptureType: { + 0: 'Standard', + 1: 'Landscape', + 2: 'Portrait', + 3: 'Night scene' + }, + SceneType: { + 1: 'Directly photographed' + }, + CustomRendered: { + 0: 'Normal process', + 1: 'Custom process' + }, + WhiteBalance: { + 0: 'Auto white balance', + 1: 'Manual white balance' + }, + GainControl: { + 0: 'None', + 1: 'Low gain up', + 2: 'High gain up', + 3: 'Low gain down', + 4: 'High gain down' + }, + Contrast: { + 0: 'Normal', + 1: 'Soft', + 2: 'Hard' + }, + Saturation: { + 0: 'Normal', + 1: 'Low saturation', + 2: 'High saturation' + }, + Sharpness: { + 0: 'Normal', + 1: 'Soft', + 2: 'Hard' + }, + SubjectDistanceRange: { + 0: 'Unknown', + 1: 'Macro', + 2: 'Close view', + 3: 'Distant view' + }, + FileSource: { + 3: 'DSC' + }, + ComponentsConfiguration: { + 0: '', + 1: 'Y', + 2: 'Cb', + 3: 'Cr', + 4: 'R', + 5: 'G', + 6: 'B' + }, + Orientation: { + 1: 'top-left', + 2: 'top-right', + 3: 'bottom-right', + 4: 'bottom-left', + 5: 'left-top', + 6: 'right-top', + 7: 'right-bottom', + 8: 'left-bottom' + } + }; + + loadImage.ExifMap.prototype.getText = function (id) { + var value = this.get(id); + switch (id) { + case 'LightSource': + case 'Flash': + case 'MeteringMode': + case 'ExposureProgram': + case 'SensingMethod': + case 'SceneCaptureType': + case 'SceneType': + case 'CustomRendered': + case 'WhiteBalance': + case 'GainControl': + case 'Contrast': + case 'Saturation': + case 'Sharpness': + case 'SubjectDistanceRange': + case 'FileSource': + case 'Orientation': + return this.stringValues[id][value]; + case 'ExifVersion': + case 'FlashpixVersion': + return String.fromCharCode(value[0], value[1], value[2], value[3]); + case 'ComponentsConfiguration': + return this.stringValues[id][value[0]] + + this.stringValues[id][value[1]] + + this.stringValues[id][value[2]] + + this.stringValues[id][value[3]]; + case 'GPSVersionID': + return value[0] + '.' + value[1] + '.' + value[2] + '.' + value[3]; + } + return String(value); + }; + + tags = loadImage.ExifMap.prototype.tags; + map = loadImage.ExifMap.prototype.map; + + // Map the tag names to tags: + for (prop in tags) { + if (tags.hasOwnProperty(prop)) { + map[tags[prop]] = prop; + } + } + + loadImage.ExifMap.prototype.getAll = function () { + var map = {}, + prop, + id; + for (prop in this) { + if (this.hasOwnProperty(prop)) { + id = tags[prop]; + if (id) { + map[id] = this.getText(id); + } + } + } + return map; + }; + +})); diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-exif.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-exif.js new file mode 100644 index 0000000..347369b --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-exif.js @@ -0,0 +1,299 @@ +/* + * JavaScript Load Image Exif Parser 1.0.0 + * https://github.com/blueimp/JavaScript-Load-Image + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint unparam: true */ +/*global define, window, console */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['load-image', 'load-image-meta'], factory); + } else { + // Browser globals: + factory(window.loadImage); + } +}(function (loadImage) { + 'use strict'; + + loadImage.ExifMap = function () { + return this; + }; + + loadImage.ExifMap.prototype.map = { + 'Orientation': 0x0112 + }; + + loadImage.ExifMap.prototype.get = function (id) { + return this[id] || this[this.map[id]]; + }; + + loadImage.getExifThumbnail = function (dataView, offset, length) { + var hexData, + i, + b; + if (!length || offset + length > dataView.byteLength) { + console.log('Invalid Exif data: Invalid thumbnail data.'); + return; + } + hexData = []; + for (i = 0; i < length; i += 1) { + b = dataView.getUint8(offset + i); + hexData.push((b < 16 ? '0' : '') + b.toString(16)); + } + return 'data:image/jpeg,%' + hexData.join('%'); + }; + + loadImage.exifTagTypes = { + // byte, 8-bit unsigned int: + 1: { + getValue: function (dataView, dataOffset) { + return dataView.getUint8(dataOffset); + }, + size: 1 + }, + // ascii, 8-bit byte: + 2: { + getValue: function (dataView, dataOffset) { + return String.fromCharCode(dataView.getUint8(dataOffset)); + }, + size: 1, + ascii: true + }, + // short, 16 bit int: + 3: { + getValue: function (dataView, dataOffset, littleEndian) { + return dataView.getUint16(dataOffset, littleEndian); + }, + size: 2 + }, + // long, 32 bit int: + 4: { + getValue: function (dataView, dataOffset, littleEndian) { + return dataView.getUint32(dataOffset, littleEndian); + }, + size: 4 + }, + // rational = two long values, first is numerator, second is denominator: + 5: { + getValue: function (dataView, dataOffset, littleEndian) { + return dataView.getUint32(dataOffset, littleEndian) / + dataView.getUint32(dataOffset + 4, littleEndian); + }, + size: 8 + }, + // slong, 32 bit signed int: + 9: { + getValue: function (dataView, dataOffset, littleEndian) { + return dataView.getInt32(dataOffset, littleEndian); + }, + size: 4 + }, + // srational, two slongs, first is numerator, second is denominator: + 10: { + getValue: function (dataView, dataOffset, littleEndian) { + return dataView.getInt32(dataOffset, littleEndian) / + dataView.getInt32(dataOffset + 4, littleEndian); + }, + size: 8 + } + }; + // undefined, 8-bit byte, value depending on field: + loadImage.exifTagTypes[7] = loadImage.exifTagTypes[1]; + + loadImage.getExifValue = function (dataView, tiffOffset, offset, type, length, littleEndian) { + var tagType = loadImage.exifTagTypes[type], + tagSize, + dataOffset, + values, + i, + str, + c; + if (!tagType) { + console.log('Invalid Exif data: Invalid tag type.'); + return; + } + tagSize = tagType.size * length; + // Determine if the value is contained in the dataOffset bytes, + // or if the value at the dataOffset is a pointer to the actual data: + dataOffset = tagSize > 4 ? + tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8); + if (dataOffset + tagSize > dataView.byteLength) { + console.log('Invalid Exif data: Invalid data offset.'); + return; + } + if (length === 1) { + return tagType.getValue(dataView, dataOffset, littleEndian); + } + values = []; + for (i = 0; i < length; i += 1) { + values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian); + } + if (tagType.ascii) { + str = ''; + // Concatenate the chars: + for (i = 0; i < values.length; i += 1) { + c = values[i]; + // Ignore the terminating NULL byte(s): + if (c === '\u0000') { + break; + } + str += c; + } + return str; + } + return values; + }; + + loadImage.parseExifTag = function (dataView, tiffOffset, offset, littleEndian, data) { + var tag = dataView.getUint16(offset, littleEndian); + data.exif[tag] = loadImage.getExifValue( + dataView, + tiffOffset, + offset, + dataView.getUint16(offset + 2, littleEndian), // tag type + dataView.getUint32(offset + 4, littleEndian), // tag length + littleEndian + ); + }; + + loadImage.parseExifTags = function (dataView, tiffOffset, dirOffset, littleEndian, data) { + var tagsNumber, + dirEndOffset, + i; + if (dirOffset + 6 > dataView.byteLength) { + console.log('Invalid Exif data: Invalid directory offset.'); + return; + } + tagsNumber = dataView.getUint16(dirOffset, littleEndian); + dirEndOffset = dirOffset + 2 + 12 * tagsNumber; + if (dirEndOffset + 4 > dataView.byteLength) { + console.log('Invalid Exif data: Invalid directory size.'); + return; + } + for (i = 0; i < tagsNumber; i += 1) { + this.parseExifTag( + dataView, + tiffOffset, + dirOffset + 2 + 12 * i, // tag offset + littleEndian, + data + ); + } + // Return the offset to the next directory: + return dataView.getUint32(dirEndOffset, littleEndian); + }; + + loadImage.parseExifData = function (dataView, offset, length, data, options) { + if (options.disableExif) { + return; + } + var tiffOffset = offset + 10, + littleEndian, + dirOffset, + thumbnailData; + // Check for the ASCII code for "Exif" (0x45786966): + if (dataView.getUint32(offset + 4) !== 0x45786966) { + // No Exif data, might be XMP data instead + return; + } + if (tiffOffset + 8 > dataView.byteLength) { + console.log('Invalid Exif data: Invalid segment size.'); + return; + } + // Check for the two null bytes: + if (dataView.getUint16(offset + 8) !== 0x0000) { + console.log('Invalid Exif data: Missing byte alignment offset.'); + return; + } + // Check the byte alignment: + switch (dataView.getUint16(tiffOffset)) { + case 0x4949: + littleEndian = true; + break; + case 0x4D4D: + littleEndian = false; + break; + default: + console.log('Invalid Exif data: Invalid byte alignment marker.'); + return; + } + // Check for the TIFF tag marker (0x002A): + if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) { + console.log('Invalid Exif data: Missing TIFF marker.'); + return; + } + // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal: + dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian); + // Create the exif object to store the tags: + data.exif = new loadImage.ExifMap(); + // Parse the tags of the main image directory and retrieve the + // offset to the next directory, usually the thumbnail directory: + dirOffset = loadImage.parseExifTags( + dataView, + tiffOffset, + tiffOffset + dirOffset, + littleEndian, + data + ); + if (dirOffset && !options.disableExifThumbnail) { + thumbnailData = {exif: {}}; + dirOffset = loadImage.parseExifTags( + dataView, + tiffOffset, + tiffOffset + dirOffset, + littleEndian, + thumbnailData + ); + // Check for JPEG Thumbnail offset: + if (thumbnailData.exif[0x0201]) { + data.exif.Thumbnail = loadImage.getExifThumbnail( + dataView, + tiffOffset + thumbnailData.exif[0x0201], + thumbnailData.exif[0x0202] // Thumbnail data length + ); + } + } + // Check for Exif Sub IFD Pointer: + if (data.exif[0x8769] && !options.disableExifSub) { + loadImage.parseExifTags( + dataView, + tiffOffset, + tiffOffset + data.exif[0x8769], // directory offset + littleEndian, + data + ); + } + // Check for GPS Info IFD Pointer: + if (data.exif[0x8825] && !options.disableExifGps) { + loadImage.parseExifTags( + dataView, + tiffOffset, + tiffOffset + data.exif[0x8825], // directory offset + littleEndian, + data + ); + } + }; + + // Registers the Exif parser for the APP1 JPEG meta data segment: + loadImage.metaDataParsers.jpeg[0xffe1].push(loadImage.parseExifData); + + // Adds the following properties to the parseMetaData callback data: + // * exif: The exif tags, parsed by the parseExifData method + + // Adds the following options to the parseMetaData method: + // * disableExif: Disables Exif parsing. + // * disableExifThumbnail: Disables parsing of the Exif Thumbnail. + // * disableExifSub: Disables parsing of the Exif Sub IFD. + // * disableExifGps: Disables parsing of the Exif GPS Info IFD. + +})); diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-ios.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-ios.js new file mode 100644 index 0000000..6f8e4fd --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-ios.js @@ -0,0 +1,181 @@ +/* + * JavaScript Load Image iOS scaling fixes 1.0.3 + * https://github.com/blueimp/JavaScript-Load-Image + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * iOS image scaling fixes based on + * https://github.com/stomita/ios-imagefile-megapixel + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, bitwise: true */ +/*global define, window, document */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['load-image'], factory); + } else { + // Browser globals: + factory(window.loadImage); + } +}(function (loadImage) { + 'use strict'; + + // Only apply fixes on the iOS platform: + if (!window.navigator || !window.navigator.platform || + !(/iP(hone|od|ad)/).test(window.navigator.platform)) { + return; + } + + var originalRenderMethod = loadImage.renderImageToCanvas; + + // Detects subsampling in JPEG images: + loadImage.detectSubsampling = function (img) { + var canvas, + context; + if (img.width * img.height > 1024 * 1024) { // only consider mexapixel images + canvas = document.createElement('canvas'); + canvas.width = canvas.height = 1; + context = canvas.getContext('2d'); + context.drawImage(img, -img.width + 1, 0); + // subsampled image becomes half smaller in rendering size. + // check alpha channel value to confirm image is covering edge pixel or not. + // if alpha value is 0 image is not covering, hence subsampled. + return context.getImageData(0, 0, 1, 1).data[3] === 0; + } + return false; + }; + + // Detects vertical squash in JPEG images: + loadImage.detectVerticalSquash = function (img, subsampled) { + var naturalHeight = img.naturalHeight || img.height, + canvas = document.createElement('canvas'), + context = canvas.getContext('2d'), + data, + sy, + ey, + py, + alpha; + if (subsampled) { + naturalHeight /= 2; + } + canvas.width = 1; + canvas.height = naturalHeight; + context.drawImage(img, 0, 0); + data = context.getImageData(0, 0, 1, naturalHeight).data; + // search image edge pixel position in case it is squashed vertically: + sy = 0; + ey = naturalHeight; + py = naturalHeight; + while (py > sy) { + alpha = data[(py - 1) * 4 + 3]; + if (alpha === 0) { + ey = py; + } else { + sy = py; + } + py = (ey + sy) >> 1; + } + return (py / naturalHeight) || 1; + }; + + // Renders image to canvas while working around iOS image scaling bugs: + // https://github.com/blueimp/JavaScript-Load-Image/issues/13 + loadImage.renderImageToCanvas = function ( + canvas, + img, + sourceX, + sourceY, + sourceWidth, + sourceHeight, + destX, + destY, + destWidth, + destHeight + ) { + if (img._type === 'image/jpeg') { + var context = canvas.getContext('2d'), + tmpCanvas = document.createElement('canvas'), + tileSize = 1024, + tmpContext = tmpCanvas.getContext('2d'), + subsampled, + vertSquashRatio, + tileX, + tileY; + tmpCanvas.width = tileSize; + tmpCanvas.height = tileSize; + context.save(); + subsampled = loadImage.detectSubsampling(img); + if (subsampled) { + sourceX /= 2; + sourceY /= 2; + sourceWidth /= 2; + sourceHeight /= 2; + } + vertSquashRatio = loadImage.detectVerticalSquash(img, subsampled); + if (subsampled || vertSquashRatio !== 1) { + sourceY *= vertSquashRatio; + destWidth = Math.ceil(tileSize * destWidth / sourceWidth); + destHeight = Math.ceil( + tileSize * destHeight / sourceHeight / vertSquashRatio + ); + destY = 0; + tileY = 0; + while (tileY < sourceHeight) { + destX = 0; + tileX = 0; + while (tileX < sourceWidth) { + tmpContext.clearRect(0, 0, tileSize, tileSize); + tmpContext.drawImage( + img, + sourceX, + sourceY, + sourceWidth, + sourceHeight, + -tileX, + -tileY, + sourceWidth, + sourceHeight + ); + context.drawImage( + tmpCanvas, + 0, + 0, + tileSize, + tileSize, + destX, + destY, + destWidth, + destHeight + ); + tileX += tileSize; + destX += destWidth; + } + tileY += tileSize; + destY += destHeight; + } + context.restore(); + return canvas; + } + } + return originalRenderMethod( + canvas, + img, + sourceX, + sourceY, + sourceWidth, + sourceHeight, + destX, + destY, + destWidth, + destHeight + ); + }; + +})); diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-meta.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-meta.js new file mode 100644 index 0000000..ab45210 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-meta.js @@ -0,0 +1,137 @@ +/* + * JavaScript Load Image Meta 1.0.1 + * https://github.com/blueimp/JavaScript-Load-Image + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Image meta data handling implementation + * based on the help and contribution of + * Achim Stöhr. + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint continue:true */ +/*global define, window, DataView, Blob, Uint8Array, console */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['load-image'], factory); + } else { + // Browser globals: + factory(window.loadImage); + } +}(function (loadImage) { + 'use strict'; + + var hasblobSlice = window.Blob && (Blob.prototype.slice || + Blob.prototype.webkitSlice || Blob.prototype.mozSlice); + + loadImage.blobSlice = hasblobSlice && function () { + var slice = this.slice || this.webkitSlice || this.mozSlice; + return slice.apply(this, arguments); + }; + + loadImage.metaDataParsers = { + jpeg: { + 0xffe1: [] // APP1 marker + } + }; + + // Parses image meta data and calls the callback with an object argument + // with the following properties: + // * imageHead: The complete image head as ArrayBuffer (Uint8Array for IE10) + // The options arguments accepts an object and supports the following properties: + // * maxMetaDataSize: Defines the maximum number of bytes to parse. + // * disableImageHead: Disables creating the imageHead property. + loadImage.parseMetaData = function (file, callback, options) { + options = options || {}; + var that = this, + // 256 KiB should contain all EXIF/ICC/IPTC segments: + maxMetaDataSize = options.maxMetaDataSize || 262144, + data = {}, + noMetaData = !(window.DataView && file && file.size >= 12 && + file.type === 'image/jpeg' && loadImage.blobSlice); + if (noMetaData || !loadImage.readFile( + loadImage.blobSlice.call(file, 0, maxMetaDataSize), + function (e) { + // Note on endianness: + // Since the marker and length bytes in JPEG files are always + // stored in big endian order, we can leave the endian parameter + // of the DataView methods undefined, defaulting to big endian. + var buffer = e.target.result, + dataView = new DataView(buffer), + offset = 2, + maxOffset = dataView.byteLength - 4, + headLength = offset, + markerBytes, + markerLength, + parsers, + i; + // Check for the JPEG marker (0xffd8): + if (dataView.getUint16(0) === 0xffd8) { + while (offset < maxOffset) { + markerBytes = dataView.getUint16(offset); + // Search for APPn (0xffeN) and COM (0xfffe) markers, + // which contain application-specific meta-data like + // Exif, ICC and IPTC data and text comments: + if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || + markerBytes === 0xfffe) { + // The marker bytes (2) are always followed by + // the length bytes (2), indicating the length of the + // marker segment, which includes the length bytes, + // but not the marker bytes, so we add 2: + markerLength = dataView.getUint16(offset + 2) + 2; + if (offset + markerLength > dataView.byteLength) { + console.log('Invalid meta data: Invalid segment size.'); + break; + } + parsers = loadImage.metaDataParsers.jpeg[markerBytes]; + if (parsers) { + for (i = 0; i < parsers.length; i += 1) { + parsers[i].call( + that, + dataView, + offset, + markerLength, + data, + options + ); + } + } + offset += markerLength; + headLength = offset; + } else { + // Not an APPn or COM marker, probably safe to + // assume that this is the end of the meta data + break; + } + } + // Meta length must be longer than JPEG marker (2) + // plus APPn marker (2), followed by length bytes (2): + if (!options.disableImageHead && headLength > 6) { + if (buffer.slice) { + data.imageHead = buffer.slice(0, headLength); + } else { + // Workaround for IE10, which does not yet + // support ArrayBuffer.slice: + data.imageHead = new Uint8Array(buffer) + .subarray(0, headLength); + } + } + } else { + console.log('Invalid JPEG file: Missing JPEG marker.'); + } + callback(data); + }, + 'readAsArrayBuffer' + )) { + callback(data); + } + }; + +})); diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-orientation.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-orientation.js new file mode 100644 index 0000000..61a0da7 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image-orientation.js @@ -0,0 +1,159 @@ +/* + * JavaScript Load Image Orientation 1.0.0 + * https://github.com/blueimp/JavaScript-Load-Image + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['load-image'], factory); + } else { + // Browser globals: + factory(window.loadImage); + } +}(function (loadImage) { + 'use strict'; + + var originalHasCanvasOptionMethod = loadImage.hasCanvasOption; + + // This method is used to determine if the target image + // should be a canvas element: + loadImage.hasCanvasOption = function (options) { + return originalHasCanvasOptionMethod(options) || options.orientation; + }; + + // Transform image orientation based on + // the given EXIF orientation option: + loadImage.transformCoordinates = function (canvas, options) { + var ctx = canvas.getContext('2d'), + width = canvas.width, + height = canvas.height, + orientation = options.orientation; + if (!orientation) { + return; + } + if (orientation > 4) { + canvas.width = height; + canvas.height = width; + } + switch (orientation) { + case 2: + // horizontal flip + ctx.translate(width, 0); + ctx.scale(-1, 1); + break; + case 3: + // 180° rotate left + ctx.translate(width, height); + ctx.rotate(Math.PI); + break; + case 4: + // vertical flip + ctx.translate(0, height); + ctx.scale(1, -1); + break; + case 5: + // vertical flip + 90 rotate right + ctx.rotate(0.5 * Math.PI); + ctx.scale(1, -1); + break; + case 6: + // 90° rotate right + ctx.rotate(0.5 * Math.PI); + ctx.translate(0, -height); + break; + case 7: + // horizontal flip + 90 rotate right + ctx.rotate(0.5 * Math.PI); + ctx.translate(width, -height); + ctx.scale(-1, 1); + break; + case 8: + // 90° rotate left + ctx.rotate(-0.5 * Math.PI); + ctx.translate(-width, 0); + break; + } + }; + + // Transforms coordinate and dimension options + // based on the given orientation option: + loadImage.getTransformedOptions = function (options) { + if (!options.orientation || options.orientation === 1) { + return options; + } + var newOptions = {}, + i; + for (i in options) { + if (options.hasOwnProperty(i)) { + newOptions[i] = options[i]; + } + } + switch (options.orientation) { + case 2: + // horizontal flip + newOptions.left = options.right; + newOptions.right = options.left; + break; + case 3: + // 180° rotate left + newOptions.left = options.right; + newOptions.top = options.bottom; + newOptions.right = options.left; + newOptions.bottom = options.top; + break; + case 4: + // vertical flip + newOptions.top = options.bottom; + newOptions.bottom = options.top; + break; + case 5: + // vertical flip + 90 rotate right + newOptions.left = options.top; + newOptions.top = options.left; + newOptions.right = options.bottom; + newOptions.bottom = options.right; + break; + case 6: + // 90° rotate right + newOptions.left = options.top; + newOptions.top = options.right; + newOptions.right = options.bottom; + newOptions.bottom = options.left; + break; + case 7: + // horizontal flip + 90 rotate right + newOptions.left = options.bottom; + newOptions.top = options.right; + newOptions.right = options.top; + newOptions.bottom = options.left; + break; + case 8: + // 90° rotate left + newOptions.left = options.bottom; + newOptions.top = options.left; + newOptions.right = options.top; + newOptions.bottom = options.right; + break; + } + if (options.orientation > 4) { + newOptions.maxWidth = options.maxHeight; + newOptions.maxHeight = options.maxWidth; + newOptions.minWidth = options.minHeight; + newOptions.minHeight = options.minWidth; + newOptions.sourceWidth = options.sourceHeight; + newOptions.sourceHeight = options.sourceWidth; + } + return newOptions; + }; + +})); diff --git a/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image.js b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image.js new file mode 100644 index 0000000..c7fd674 --- /dev/null +++ b/app/assets/javascripts/jquery-fileupload/vendor/load-image/load-image.js @@ -0,0 +1,276 @@ +/* + * JavaScript Load Image 1.9.0 + * https://github.com/blueimp/JavaScript-Load-Image + * + * Copyright 2011, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true */ +/*global define, window, document, URL, webkitURL, Blob, File, FileReader */ + +(function ($) { + 'use strict'; + + // Loads an image for a given File object. + // Invokes the callback with an img or optional canvas + // element (if supported by the browser) as parameter: + var loadImage = function (file, callback, options) { + var img = document.createElement('img'), + url, + oUrl; + img.onerror = callback; + img.onload = function () { + if (oUrl && !(options && options.noRevoke)) { + loadImage.revokeObjectURL(oUrl); + } + if (callback) { + callback(loadImage.scale(img, options)); + } + }; + if (loadImage.isInstanceOf('Blob', file) || + // Files are also Blob instances, but some browsers + // (Firefox 3.6) support the File API but not Blobs: + loadImage.isInstanceOf('File', file)) { + url = oUrl = loadImage.createObjectURL(file); + // Store the file type for resize processing: + img._type = file.type; + } else if (typeof file === 'string') { + url = file; + if (options && options.crossOrigin) { + img.crossOrigin = options.crossOrigin; + } + } else { + return false; + } + if (url) { + img.src = url; + return img; + } + return loadImage.readFile(file, function (e) { + var target = e.target; + if (target && target.result) { + img.src = target.result; + } else { + if (callback) { + callback(e); + } + } + }); + }, + // The check for URL.revokeObjectURL fixes an issue with Opera 12, + // which provides URL.createObjectURL but doesn't properly implement it: + urlAPI = (window.createObjectURL && window) || + (window.URL && URL.revokeObjectURL && URL) || + (window.webkitURL && webkitURL); + + loadImage.isInstanceOf = function (type, obj) { + // Cross-frame instanceof check + return Object.prototype.toString.call(obj) === '[object ' + type + ']'; + }; + + // Transform image coordinates, allows to override e.g. + // the canvas orientation based on the orientation option, + // gets canvas, options passed as arguments: + loadImage.transformCoordinates = function () { + return; + }; + + // Returns transformed options, allows to override e.g. + // coordinate and dimension options based on the orientation: + loadImage.getTransformedOptions = function (options) { + return options; + }; + + // Canvas render method, allows to override the + // rendering e.g. to work around issues on iOS: + loadImage.renderImageToCanvas = function ( + canvas, + img, + sourceX, + sourceY, + sourceWidth, + sourceHeight, + destX, + destY, + destWidth, + destHeight + ) { + canvas.getContext('2d').drawImage( + img, + sourceX, + sourceY, + sourceWidth, + sourceHeight, + destX, + destY, + destWidth, + destHeight + ); + return canvas; + }; + + // This method is used to determine if the target image + // should be a canvas element: + loadImage.hasCanvasOption = function (options) { + return options.canvas || options.crop; + }; + + // Scales and/or crops the given image (img or canvas HTML element) + // using the given options. + // Returns a canvas object if the browser supports canvas + // and the hasCanvasOption method returns true or a canvas + // object is passed as image, else the scaled image: + loadImage.scale = function (img, options) { + options = options || {}; + var canvas = document.createElement('canvas'), + useCanvas = img.getContext || + (loadImage.hasCanvasOption(options) && canvas.getContext), + width = img.naturalWidth || img.width, + height = img.naturalHeight || img.height, + destWidth = width, + destHeight = height, + maxWidth, + maxHeight, + minWidth, + minHeight, + sourceWidth, + sourceHeight, + sourceX, + sourceY, + tmp, + scaleUp = function () { + var scale = Math.max( + (minWidth || destWidth) / destWidth, + (minHeight || destHeight) / destHeight + ); + if (scale > 1) { + destWidth = Math.ceil(destWidth * scale); + destHeight = Math.ceil(destHeight * scale); + } + }, + scaleDown = function () { + var scale = Math.min( + (maxWidth || destWidth) / destWidth, + (maxHeight || destHeight) / destHeight + ); + if (scale < 1) { + destWidth = Math.ceil(destWidth * scale); + destHeight = Math.ceil(destHeight * scale); + } + }; + if (useCanvas) { + options = loadImage.getTransformedOptions(options); + sourceX = options.left || 0; + sourceY = options.top || 0; + if (options.sourceWidth) { + sourceWidth = options.sourceWidth; + if (options.right !== undefined && options.left === undefined) { + sourceX = width - sourceWidth - options.right; + } + } else { + sourceWidth = width - sourceX - (options.right || 0); + } + if (options.sourceHeight) { + sourceHeight = options.sourceHeight; + if (options.bottom !== undefined && options.top === undefined) { + sourceY = height - sourceHeight - options.bottom; + } + } else { + sourceHeight = height - sourceY - (options.bottom || 0); + } + destWidth = sourceWidth; + destHeight = sourceHeight; + } + maxWidth = options.maxWidth; + maxHeight = options.maxHeight; + minWidth = options.minWidth; + minHeight = options.minHeight; + if (useCanvas && maxWidth && maxHeight && options.crop) { + destWidth = maxWidth; + destHeight = maxHeight; + tmp = sourceWidth / sourceHeight - maxWidth / maxHeight; + if (tmp < 0) { + sourceHeight = maxHeight * sourceWidth / maxWidth; + if (options.top === undefined && options.bottom === undefined) { + sourceY = (height - sourceHeight) / 2; + } + } else if (tmp > 0) { + sourceWidth = maxWidth * sourceHeight / maxHeight; + if (options.left === undefined && options.right === undefined) { + sourceX = (width - sourceWidth) / 2; + } + } + } else { + if (options.contain || options.cover) { + minWidth = maxWidth = maxWidth || minWidth; + minHeight = maxHeight = maxHeight || minHeight; + } + if (options.cover) { + scaleDown(); + scaleUp(); + } else { + scaleUp(); + scaleDown(); + } + } + if (useCanvas) { + canvas.width = destWidth; + canvas.height = destHeight; + loadImage.transformCoordinates( + canvas, + options + ); + return loadImage.renderImageToCanvas( + canvas, + img, + sourceX, + sourceY, + sourceWidth, + sourceHeight, + 0, + 0, + destWidth, + destHeight + ); + } + img.width = destWidth; + img.height = destHeight; + return img; + }; + + loadImage.createObjectURL = function (file) { + return urlAPI ? urlAPI.createObjectURL(file) : false; + }; + + loadImage.revokeObjectURL = function (url) { + return urlAPI ? urlAPI.revokeObjectURL(url) : false; + }; + + // Loads a given File object via FileReader interface, + // invokes the callback with the event object (load or error). + // The result can be read via event.target.result: + loadImage.readFile = function (file, callback, method) { + if (window.FileReader) { + var fileReader = new FileReader(); + fileReader.onload = fileReader.onerror = callback; + method = method || 'readAsDataURL'; + if (fileReader[method]) { + fileReader[method](file); + return fileReader; + } + } + return false; + }; + + if (typeof define === 'function' && define.amd) { + define(function () { + return loadImage; + }); + } else { + $.loadImage = loadImage; + } +}(this)); diff --git a/vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js b/app/assets/javascripts/jquery-fileupload/vendor/tmpl.js similarity index 82% rename from vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js rename to app/assets/javascripts/jquery-fileupload/vendor/tmpl.js index c8b4b86..bb3d4cd 100644 --- a/vendor/assets/javascripts/jquery-fileupload/vendor/tmpl.js +++ b/app/assets/javascripts/jquery-fileupload/vendor/tmpl.js @@ -1,5 +1,5 @@ /* - * JavaScript Templates 2.1.0 + * JavaScript Templates 2.4.0 * https://github.com/blueimp/JavaScript-Templates * * Copyright 2011, Sebastian Tschan @@ -12,7 +12,7 @@ * http://ejohn.org/blog/javascript-micro-templating/ */ -/*jslint evil: true, regexp: true */ +/*jslint evil: true, regexp: true, unparam: true */ /*global document, define */ (function ($) { @@ -34,21 +34,21 @@ tmpl.load = function (id) { return document.getElementById(id).innerHTML; }; - tmpl.regexp = /([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g; + tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g; tmpl.func = function (s, p1, p2, p3, p4, p5) { - if (p1) { // whitespace, quote and backspace in interpolation context + if (p1) { // whitespace, quote and backspace in HTML context return { "\n": "\\n", "\r": "\\r", "\t": "\\t", " " : " " - }[s] || "\\" + s; + }[p1] || "\\" + p1; } if (p2) { // interpolation: {%=prop%}, or unescaped: {%#prop%} if (p2 === "=") { return "'+_e(" + p3 + ")+'"; } - return "'+(" + p3 + "||'')+'"; + return "'+(" + p3 + "==null?'':" + p3 + ")+'"; } if (p4) { // evaluation start tag: {% return "';"; @@ -66,7 +66,7 @@ "'" : "'" }; tmpl.encode = function (s) { - return String(s || "").replace( + return (s == null ? "" : "" + s).replace( tmpl.encReg, function (c) { return tmpl.encMap[c] || ""; @@ -74,7 +74,7 @@ ); }; tmpl.arg = "o"; - tmpl.helper = ",print=function(s,e){_s+=e&&(s||'')||_e(s);}" + + tmpl.helper = ",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" + ",include=function(s,d){_s+=tmpl(s,d);}"; if (typeof define === "function" && define.amd) { define(function () { diff --git a/app/assets/stylesheets/jquery.fileupload-noscript.scss b/app/assets/stylesheets/jquery.fileupload-noscript.scss new file mode 100644 index 0000000..b7268e2 --- /dev/null +++ b/app/assets/stylesheets/jquery.fileupload-noscript.scss @@ -0,0 +1,23 @@ +@charset 'UTF-8'; +/* + * jQuery File Upload Plugin NoScript CSS 1.0.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +.fileinput-button input { + position: static; + opacity: 1; + filter: none; + transform: none; + font-size: inherit; + direction: inherit; +} +.fileinput-button span { + display: none; +} diff --git a/app/assets/stylesheets/jquery.fileupload-ui-noscript.scss b/app/assets/stylesheets/jquery.fileupload-ui-noscript.scss new file mode 100644 index 0000000..87f110c --- /dev/null +++ b/app/assets/stylesheets/jquery.fileupload-ui-noscript.scss @@ -0,0 +1,17 @@ +@charset "UTF-8"; +/* + * jQuery File Upload UI Plugin NoScript CSS 8.8.5 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2012, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +.fileinput-button i, +.fileupload-buttonbar .delete, +.fileupload-buttonbar .toggle { + display: none; +} diff --git a/vendor/assets/stylesheets/jquery.fileupload-ui.scss b/app/assets/stylesheets/jquery.fileupload-ui.scss old mode 100755 new mode 100644 similarity index 60% rename from vendor/assets/stylesheets/jquery.fileupload-ui.scss rename to app/assets/stylesheets/jquery.fileupload-ui.scss index 72bfcb6..afee839 --- a/vendor/assets/stylesheets/jquery.fileupload-ui.scss +++ b/app/assets/stylesheets/jquery.fileupload-ui.scss @@ -1,6 +1,6 @@ -@charset "UTF-8"; +@charset 'UTF-8'; /* - * jQuery File Upload UI Plugin CSS 8.0 + * jQuery File Upload UI Plugin CSS 8.8.5 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -10,41 +10,30 @@ * http://www.opensource.org/licenses/MIT */ -.fileinput-button { - position: relative; - overflow: hidden; -} -.fileinput-button input { - position: absolute; - top: 0; - right: 0; - margin: 0; - opacity: 0; - filter: alpha(opacity=0); - transform: translate(-300px, 0) scale(4); - font-size: 23px; - direction: ltr; - cursor: pointer; -} .fileupload-buttonbar .btn, .fileupload-buttonbar .toggle { margin-bottom: 5px; } +.progress-animated .progress-bar, .progress-animated .bar { - background: url(../img/progressbar.gif) !important; + background: image_url('progressbar.gif') !important; filter: none; } .fileupload-loading { float: right; width: 32px; height: 32px; - background: url(../img/loading.gif) center no-repeat; + background: image_url('loading.gif') center no-repeat; background-size: contain; display: none; } .fileupload-processing .fileupload-loading { display: block; } +.files audio, +.files video { + max-width: 300px; +} @media (max-width: 767px) { .fileupload-buttonbar .toggle, @@ -56,4 +45,8 @@ width: 80px; word-wrap: break-word; } + .files audio, + .files video { + max-width: 80px; + } } diff --git a/app/assets/stylesheets/jquery.fileupload.scss b/app/assets/stylesheets/jquery.fileupload.scss new file mode 100644 index 0000000..965960c --- /dev/null +++ b/app/assets/stylesheets/jquery.fileupload.scss @@ -0,0 +1,28 @@ +@charset 'UTF-8'; +/* + * jQuery File Upload Plugin CSS 1.0.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2013, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +.fileinput-button { + position: relative; + overflow: hidden; +} +.fileinput-button input { + position: absolute; + top: 0; + right: 0; + margin: 0; + opacity: 0; + filter: alpha(opacity=0); + transform: translate(-300px, 0) scale(4); + font-size: 23px; + direction: ltr; + cursor: pointer; +} diff --git a/jquery-fileupload-rails.gemspec b/jquery-fileupload-rails.gemspec index 78b5549..485b955 100644 --- a/jquery-fileupload-rails.gemspec +++ b/jquery-fileupload-rails.gemspec @@ -13,12 +13,12 @@ Gem::Specification.new do |s| s.rubyforge_project = "jquery-fileupload-rails" - s.files = Dir["lib/**/*"] + Dir["vendor/**/*"] + ["Rakefile", "README.md"] + s.files = Dir["lib/**/*"] + Dir["app/**/*"] + ["Rakefile", "README.md"] s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.add_dependency 'railties', '>= 3.1' s.add_dependency 'actionpack', '>= 3.1' - s.add_development_dependency 'rails', '>= 3.1' + s.add_development_dependency 'rails', '>= 3.1' end diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js deleted file mode 100644 index c782f1e..0000000 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +++ /dev/null @@ -1,227 +0,0 @@ -/* - * jQuery File Upload File Processing Plugin 1.2.3 - * https://github.com/blueimp/jQuery-File-Upload - * - * Copyright 2012, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * http://www.opensource.org/licenses/MIT - */ - -/*jslint nomen: true, unparam: true, regexp: true */ -/*global define, window, document */ - -(function (factory) { - 'use strict'; - if (typeof define === 'function' && define.amd) { - // Register as an anonymous AMD module: - define([ - 'jquery', - 'load-image', - 'canvas-to-blob', - './jquery.fileupload' - ], factory); - } else { - // Browser globals: - factory( - window.jQuery, - window.loadImage - ); - } -}(function ($, loadImage) { - 'use strict'; - - // The File Upload FP version extends the fileupload widget - // with file processing functionality: - $.widget('blueimp.fileupload', $.blueimp.fileupload, { - - options: { - // The list of file processing actions: - process: [ - /* - { - action: 'load', - fileTypes: /^image\/(gif|jpeg|png)$/, - maxFileSize: 20000000 // 20MB - }, - { - action: 'resize', - maxWidth: 1920, - maxHeight: 1200, - minWidth: 800, - minHeight: 600 - }, - { - action: 'save' - } - */ - ], - - // The add callback is invoked as soon as files are added to the - // fileupload widget (via file input selection, drag & drop or add - // API call). See the basic file upload widget for more information: - add: function (e, data) { - if (data.autoUpload || (data.autoUpload !== false && - ($(this).data('blueimp-fileupload') || - $(this).data('fileupload')).options.autoUpload)) { - $(this).fileupload('process', data).done(function () { - data.submit(); - }); - } - } - }, - - processActions: { - // Loads the image given via data.files and data.index - // as img element if the browser supports canvas. - // Accepts the options fileTypes (regular expression) - // and maxFileSize (integer) to limit the files to load: - load: function (data, options) { - var that = this, - file = data.files[data.index], - dfd = $.Deferred(); - if (window.HTMLCanvasElement && - window.HTMLCanvasElement.prototype.toBlob && - ($.type(options.maxFileSize) !== 'number' || - file.size < options.maxFileSize) && - (!options.fileTypes || - options.fileTypes.test(file.type))) { - loadImage( - file, - function (img) { - if (!img.src) { - return dfd.rejectWith(that, [data]); - } - data.img = img; - dfd.resolveWith(that, [data]); - } - ); - } else { - dfd.rejectWith(that, [data]); - } - return dfd.promise(); - }, - // Resizes the image given as data.img and updates - // data.canvas with the resized image as canvas element. - // Accepts the options maxWidth, maxHeight, minWidth and - // minHeight to scale the given image: - resize: function (data, options) { - var img = data.img, - canvas; - options = $.extend({canvas: true}, options); - if (img) { - canvas = loadImage.scale(img, options); - if (canvas.width !== img.width || - canvas.height !== img.height) { - data.canvas = canvas; - } - } - return data; - }, - // Saves the processed image given as data.canvas - // inplace at data.index of data.files: - save: function (data, options) { - // Do nothing if no processing has happened: - if (!data.canvas) { - return data; - } - var that = this, - file = data.files[data.index], - name = file.name, - dfd = $.Deferred(), - callback = function (blob) { - if (!blob.name) { - if (file.type === blob.type) { - blob.name = file.name; - } else if (file.name) { - blob.name = file.name.replace( - /\..+$/, - '.' + blob.type.substr(6) - ); - } - } - // Store the created blob at the position - // of the original file in the files list: - data.files[data.index] = blob; - dfd.resolveWith(that, [data]); - }; - // Use canvas.mozGetAsFile directly, to retain the filename, as - // Gecko doesn't support the filename option for FormData.append: - if (data.canvas.mozGetAsFile) { - callback(data.canvas.mozGetAsFile( - (/^image\/(jpeg|png)$/.test(file.type) && name) || - ((name && name.replace(/\..+$/, '')) || - 'blob') + '.png', - file.type - )); - } else { - data.canvas.toBlob(callback, file.type); - } - return dfd.promise(); - } - }, - - // Resizes the file at the given index and stores the created blob at - // the original position of the files list, returns a Promise object: - _processFile: function (files, index, options) { - var that = this, - dfd = $.Deferred().resolveWith(that, [{ - files: files, - index: index - }]), - chain = dfd.promise(); - that._processing += 1; - $.each(options.process, function (i, settings) { - chain = chain.pipe(function (data) { - return that.processActions[settings.action] - .call(this, data, settings); - }); - }); - chain.always(function () { - that._processing -= 1; - if (that._processing === 0) { - that.element - .removeClass('fileupload-processing'); - } - }); - if (that._processing === 1) { - that.element.addClass('fileupload-processing'); - } - return chain; - }, - - // Processes the files given as files property of the data parameter, - // returns a Promise object that allows to bind a done handler, which - // will be invoked after processing all files (inplace) is done: - process: function (data) { - var that = this, - options = $.extend({}, this.options, data); - if (options.process && options.process.length && - this._isXHRUpload(options)) { - $.each(data.files, function (index, file) { - that._processingQueue = that._processingQueue.pipe( - function () { - var dfd = $.Deferred(); - that._processFile(data.files, index, options) - .always(function () { - dfd.resolveWith(that); - }); - return dfd.promise(); - } - ); - }); - } - return this._processingQueue; - }, - - _create: function () { - this._super(); - this._processing = 0; - this._processingQueue = $.Deferred().resolveWith(this) - .promise(); - } - - }); - -})); diff --git a/vendor/assets/javascripts/jquery-fileupload/locale.js b/vendor/assets/javascripts/jquery-fileupload/locale.js deleted file mode 100644 index ea64b0a..0000000 --- a/vendor/assets/javascripts/jquery-fileupload/locale.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * jQuery File Upload Plugin Localization Example 6.5.1 - * https://github.com/blueimp/jQuery-File-Upload - * - * Copyright 2012, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * http://www.opensource.org/licenses/MIT - */ - -/*global window */ - -window.locale = { - "fileupload": { - "errors": { - "maxFileSize": "File is too big", - "minFileSize": "File is too small", - "acceptFileTypes": "Filetype not allowed", - "maxNumberOfFiles": "Max number of files exceeded", - "uploadedBytes": "Uploaded bytes exceed file size", - "emptyResult": "Empty file upload result" - }, - "error": "Error", - "start": "Start", - "cancel": "Cancel", - "destroy": "Delete" - } -}; diff --git a/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js b/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js deleted file mode 100644 index 0155d38..0000000 --- a/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js +++ /dev/null @@ -1,228 +0,0 @@ -/* - * JavaScript Load Image 1.3.1 - * https://github.com/blueimp/JavaScript-Load-Image - * - * Copyright 2011, Sebastian Tschan - * https://blueimp.net - * - * iOS image scaling fixes based on - * https://github.com/stomita/ios-imagefile-megapixel - * - * Licensed under the MIT license: - * http://www.opensource.org/licenses/MIT - */ - -/*jslint nomen: true, bitwise: true */ -/*global window, document, URL, webkitURL, Blob, File, FileReader, define */ - -(function ($) { - 'use strict'; - - // Loads an image for a given File object. - // Invokes the callback with an img or optional canvas - // element (if supported by the browser) as parameter: - var loadImage = function (file, callback, options) { - var img = document.createElement('img'), - url, - oUrl; - img.onerror = callback; - img.onload = function () { - if (oUrl && !(options && options.noRevoke)) { - loadImage.revokeObjectURL(oUrl); - } - callback(loadImage.scale(img, options)); - }; - if ((window.Blob && file instanceof Blob) || - // Files are also Blob instances, but some browsers - // (Firefox 3.6) support the File API but not Blobs: - (window.File && file instanceof File)) { - url = oUrl = loadImage.createObjectURL(file); - // Store the file type for resize processing: - img._type = file.type; - } else { - url = file; - } - if (url) { - img.src = url; - return img; - } - return loadImage.readFile(file, function (e) { - var target = e.target; - if (target && target.result) { - img.src = target.result; - } else { - callback(e); - } - }); - }, - // The check for URL.revokeObjectURL fixes an issue with Opera 12, - // which provides URL.createObjectURL but doesn't properly implement it: - urlAPI = (window.createObjectURL && window) || - (window.URL && URL.revokeObjectURL && URL) || - (window.webkitURL && webkitURL); - - // Detects subsampling in JPEG images: - loadImage.detectSubsampling = function (img) { - var iw = img.width, - ih = img.height, - canvas, - ctx; - if (iw * ih > 1024 * 1024) { // only consider mexapixel images - canvas = document.createElement('canvas'); - canvas.width = canvas.height = 1; - ctx = canvas.getContext('2d'); - ctx.drawImage(img, -iw + 1, 0); - // subsampled image becomes half smaller in rendering size. - // check alpha channel value to confirm image is covering edge pixel or not. - // if alpha value is 0 image is not covering, hence subsampled. - return ctx.getImageData(0, 0, 1, 1).data[3] === 0; - } - return false; - }; - - // Detects vertical squash in JPEG images: - loadImage.detectVerticalSquash = function (img, ih) { - var canvas = document.createElement('canvas'), - ctx = canvas.getContext('2d'), - data, - sy, - ey, - py, - alpha; - canvas.width = 1; - canvas.height = ih; - ctx.drawImage(img, 0, 0); - data = ctx.getImageData(0, 0, 1, ih).data; - // search image edge pixel position in case it is squashed vertically: - sy = 0; - ey = ih; - py = ih; - while (py > sy) { - alpha = data[(py - 1) * 4 + 3]; - if (alpha === 0) { - ey = py; - } else { - sy = py; - } - py = (ey + sy) >> 1; - } - return (py / ih) || 1; - }; - - // Renders image to canvas while working around iOS image scaling bugs: - // https://github.com/blueimp/JavaScript-Load-Image/issues/13 - loadImage.renderImageToCanvas = function (img, canvas, width, height) { - var iw = img.width, - ih = img.height, - ctx = canvas.getContext('2d'), - vertSquashRatio, - d = 1024, // size of tiling canvas - tmpCanvas = document.createElement('canvas'), - tmpCtx, - dw, - dh, - dx, - dy, - sx, - sy; - ctx.save(); - if (loadImage.detectSubsampling(img)) { - iw /= 2; - ih /= 2; - } - vertSquashRatio = loadImage.detectVerticalSquash(img, ih); - tmpCanvas.width = tmpCanvas.height = d; - tmpCtx = tmpCanvas.getContext('2d'); - dw = Math.ceil(d * width / iw); - dh = Math.ceil(d * height / ih / vertSquashRatio); - dy = 0; - sy = 0; - while (sy < ih) { - dx = 0; - sx = 0; - while (sx < iw) { - tmpCtx.clearRect(0, 0, d, d); - tmpCtx.drawImage(img, -sx, -sy); - ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh); - sx += d; - dx += dw; - } - sy += d; - dy += dh; - } - ctx.restore(); - tmpCanvas = tmpCtx = null; - }; - - // Scales the given image (img or canvas HTML element) - // using the given options. - // Returns a canvas object if the browser supports canvas - // and the canvas option is true or a canvas object is passed - // as image, else the scaled image: - loadImage.scale = function (img, options) { - options = options || {}; - var canvas = document.createElement('canvas'), - width = img.width, - height = img.height, - scale = Math.max( - (options.minWidth || width) / width, - (options.minHeight || height) / height - ); - if (scale > 1) { - width = Math.ceil(width * scale); - height = Math.ceil(height * scale); - } - scale = Math.min( - (options.maxWidth || width) / width, - (options.maxHeight || height) / height - ); - if (scale < 1) { - width = Math.ceil(width * scale); - height = Math.ceil(height * scale); - } - if (img.getContext || (options.canvas && canvas.getContext)) { - canvas.width = width; - canvas.height = height; - if (img._type === 'image/jpeg') { - loadImage - .renderImageToCanvas(img, canvas, width, height); - } else { - canvas.getContext('2d') - .drawImage(img, 0, 0, width, height); - } - return canvas; - } - img.width = width; - img.height = height; - return img; - }; - - loadImage.createObjectURL = function (file) { - return urlAPI ? urlAPI.createObjectURL(file) : false; - }; - - loadImage.revokeObjectURL = function (url) { - return urlAPI ? urlAPI.revokeObjectURL(url) : false; - }; - - // Loads a given File object via FileReader interface, - // invokes the callback with the event object (load or error). - // The result can be read via event.target.result: - loadImage.readFile = function (file, callback) { - if (window.FileReader && FileReader.prototype.readAsDataURL) { - var fileReader = new FileReader(); - fileReader.onload = fileReader.onerror = callback; - fileReader.readAsDataURL(file); - return fileReader; - } - return false; - }; - - if (typeof define === 'function' && define.amd) { - define(function () { - return loadImage; - }); - } else { - $.loadImage = loadImage; - } -}(this));