2 * jQuery File Upload Video Preview Plugin
3 * https://github.com/blueimp/jQuery-File-Upload
5 * Copyright 2013, Sebastian Tschan
8 * Licensed under the MIT license:
9 * https://opensource.org/licenses/MIT
12 /* global define, require */
16 if (typeof define === 'function' && define.amd) {
17 // Register as an anonymous AMD module:
18 define(['jquery', 'load-image', './jquery.fileupload-process'], factory);
19 } else if (typeof exports === 'object') {
23 require('blueimp-load-image/js/load-image'),
24 require('./jquery.fileupload-process')
28 factory(window.jQuery, window.loadImage);
30 })(function ($, loadImage) {
33 // Prepend to the default processQueue:
34 $.blueimp.fileupload.prototype.options.processQueue.unshift(
37 // Use the action as prefix for the "@" options:
41 disabled: '@disableVideoPreview'
45 name: '@videoPreviewName',
46 disabled: '@disableVideoPreview'
50 // The File Upload Video Preview plugin extends the fileupload widget
51 // with video preview functionality:
52 $.widget('blueimp.fileupload', $.blueimp.fileupload, {
54 // The regular expression for the types of video files to load,
55 // matched against the file type:
56 loadVideoFileTypes: /^video\/.*$/
59 _videoElement: document.createElement('video'),
62 // Loads the video file given via data.files and data.index
63 // as video element if the browser supports playing it.
64 // Accepts the options fileTypes (regular expression)
65 // and maxFileSize (integer) to limit the files to load:
66 loadVideo: function (data, options) {
67 if (options.disabled) {
70 var file = data.files[data.index],
74 this._videoElement.canPlayType &&
75 this._videoElement.canPlayType(file.type) &&
76 ($.type(options.maxFileSize) !== 'number' ||
77 file.size <= options.maxFileSize) &&
78 (!options.fileTypes || options.fileTypes.test(file.type))
80 url = loadImage.createObjectURL(file);
82 video = this._videoElement.cloneNode(false);
84 video.controls = true;
92 // Sets the video element as a property of the file object:
93 setVideo: function (data, options) {
94 if (data.video && !options.disabled) {
95 data.files[data.index][options.name || 'preview'] = data.video;