diff options
author | friendica <info@friendica.com> | 2014-01-19 14:08:21 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-01-19 14:08:21 -0800 |
commit | f3a7bf913f3bb03c1601b105271daf77df4e3bbb (patch) | |
tree | b7a2c2ddcf1440f2df61c5bace571a76e13e3e18 /library/jqupload/js/jquery.fileupload-validate.js | |
parent | 724ad4505628d493b43b4f585512d67dc0b4ee76 (diff) | |
download | volse-hubzilla-f3a7bf913f3bb03c1601b105271daf77df4e3bbb.tar.gz volse-hubzilla-f3a7bf913f3bb03c1601b105271daf77df4e3bbb.tar.bz2 volse-hubzilla-f3a7bf913f3bb03c1601b105271daf77df4e3bbb.zip |
add the jquery file uploader. Have been suggesting this as a replacement for the valum uploaders for quite some time - as there is client resize ability and no license incompatibilities. It still requires integration.
Diffstat (limited to 'library/jqupload/js/jquery.fileupload-validate.js')
-rw-r--r-- | library/jqupload/js/jquery.fileupload-validate.js | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/library/jqupload/js/jquery.fileupload-validate.js b/library/jqupload/js/jquery.fileupload-validate.js new file mode 100644 index 000000000..f93a18fa2 --- /dev/null +++ b/library/jqupload/js/jquery.fileupload-validate.js @@ -0,0 +1,119 @@ +/* + * jQuery File Upload Validation Plugin 1.1.2 + * 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 + */ + +/* global define, window */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define([ + 'jquery', + './jquery.fileupload-process' + ], factory); + } else { + // Browser globals: + factory( + window.jQuery + ); + } +}(function ($) { + 'use strict'; + + // Append to the default processQueue: + $.blueimp.fileupload.prototype.options.processQueue.push( + { + action: 'validate', + // Always trigger this action, + // even if the previous action was rejected: + always: true, + // Options taken from the global options map: + acceptFileTypes: '@', + maxFileSize: '@', + minFileSize: '@', + maxNumberOfFiles: '@', + disabled: '@disableValidation' + } + ); + + // The File Upload Validation plugin extends the fileupload widget + // with file validation functionality: + $.widget('blueimp.fileupload', $.blueimp.fileupload, { + + options: { + /* + // The regular expression for allowed file types, matches + // against either file type or file name: + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, + // The maximum allowed file size in bytes: + maxFileSize: 10000000, // 10 MB + // The minimum allowed file size in bytes: + minFileSize: undefined, // No minimal file size + // The limit of files to be uploaded: + maxNumberOfFiles: 10, + */ + + // Function returning the current number of files, + // has to be overriden for maxNumberOfFiles validation: + getNumberOfFiles: $.noop, + + // Error and info messages: + messages: { + maxNumberOfFiles: 'Maximum number of files exceeded', + acceptFileTypes: 'File type not allowed', + maxFileSize: 'File is too large', + minFileSize: 'File is too small' + } + }, + + processActions: { + + validate: function (data, options) { + if (options.disabled) { + return data; + } + var dfd = $.Deferred(), + settings = this.options, + file = data.files[data.index], + fileSize; + if (options.minFileSize || options.maxFileSize) { + fileSize = file.size; + } + 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 (fileSize > options.maxFileSize) { + file.error = settings.i18n('maxFileSize'); + } else if ($.type(fileSize) === 'number' && + fileSize < options.minFileSize) { + file.error = settings.i18n('minFileSize'); + } else { + delete file.error; + } + if (file.error || data.files.error) { + data.files.error = true; + dfd.rejectWith(this, [data]); + } else { + dfd.resolveWith(this, [data]); + } + return dfd.promise(); + } + + } + + }); + +})); |