namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
/* * jQuery File Upload Image Processing Plugin 1.0 * 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.js', './canvas-to-blob.js', './jquery.fileupload.js' ], factory); } else { // Browser globals: factory( window.jQuery, window.loadImage, window.canvasToBlob ); } }(function ($, loadImage, canvasToBlob) { 'use strict'; // The File Upload IP version extends the basic fileupload widget // with image processing functionality: $.widget('blueimpIP.fileupload', $.blueimp.fileupload, { options: { // The regular expression to define which image files are to be // resized, given that the browser supports the operation: resizeSourceFileTypes: /^image\/(gif|jpeg|png)$/, // The maximum file size of images that are to be resized: resizeSourceMaxFileSize: 20000000, // 20MB // The maximum width of the resized images: resizeMaxWidth: undefined, // The maximum height of the resized images: resizeMaxHeight: undefined, // The minimum width of the resized images: resizeMinWidth: undefined, // The minimum height of the resized images: resizeMinHeight: undefined, // 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) { $(this).fileupload('resize', data).done(function () { data.submit(); }); } }, // Resizes the image file at the given index and stores the created blob // at the original position of the files list, returns a Promise object: _resizeImage: function (files, index) { var that = this, options = this.options, file = files[index], deferred = $.Deferred(), canvas, blob; loadImage( file, function (img) { var width = img.width, height = img.height; canvas = loadImage.scale(img, { maxWidth: options.resizeMaxWidth, maxHeight: options.resizeMaxHeight, minWidth: options.resizeMinWidth, minHeight: options.resizeMinHeight, canvas: true }); if (width !== canvas.width || height !== canvas.height) { canvasToBlob(canvas, 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) ); } } files[index] = blob; deferred.resolve(); }, file); } else { deferred.resolve(); } } ); return deferred.promise(); }, // Resizes the images 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 images is done: resize: function (data) { var that = this, options = $.extend({}, this.options, data), resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number'; $.each(data.files, function (index, file) { if (that._resizeSupport && (options.resizeMaxWidth || options.resizeMaxHeight || options.resizeMinWidth || options.resizeMinHeight) && (resizeAll || file.size < options.resizeSourceMaxFileSize) && options.resizeSourceFileTypes.test(file.type)) { that._processing += 1; if (that._processing === 1) { that.element.addClass('fileupload-processing'); } that._processingQueue = that._processingQueue.pipe(function () { var deferred = $.Deferred(); that._resizeImage( data.files, index ).done(function () { that._processing -= 1; if (that._processing === 0) { that.element .removeClass('fileupload-processing'); } deferred.resolve(); }); return deferred.promise(); }); } }); return this._processingQueue; }, _create: function () { $.blueimp.fileupload.prototype._create.call(this); this._processing = 0; this._processingQueue = $.Deferred().resolveWith(this).promise(); this._resizeSupport = canvasToBlob( document.createElement('canvas'), $.noop ); } }); })); |
Commits for namibiapublic/scripts/blueimp-jQuery-File-Upload/js/jquery.fileupload-ip.js
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |