Subversion-Projekte lars-tiefland.webanos.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
4 lars 1
/*
2
 * jQuery File Upload Video Preview Plugin
3
 * https://github.com/blueimp/jQuery-File-Upload
4
 *
5
 * Copyright 2013, Sebastian Tschan
6
 * https://blueimp.net
7
 *
8
 * Licensed under the MIT license:
9
 * https://opensource.org/licenses/MIT
10
 */
11
 
12
/* global define, require */
13
 
14
(function (factory) {
15
  'use strict';
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') {
20
    // Node/CommonJS:
21
    factory(
22
      require('jquery'),
23
      require('blueimp-load-image/js/load-image'),
24
      require('./jquery.fileupload-process')
25
    );
26
  } else {
27
    // Browser globals:
28
    factory(window.jQuery, window.loadImage);
29
  }
30
})(function ($, loadImage) {
31
  'use strict';
32
 
33
  // Prepend to the default processQueue:
34
  $.blueimp.fileupload.prototype.options.processQueue.unshift(
35
    {
36
      action: 'loadVideo',
37
      // Use the action as prefix for the "@" options:
38
      prefix: true,
39
      fileTypes: '@',
40
      maxFileSize: '@',
41
      disabled: '@disableVideoPreview'
42
    },
43
    {
44
      action: 'setVideo',
45
      name: '@videoPreviewName',
46
      disabled: '@disableVideoPreview'
47
    }
48
  );
49
 
50
  // The File Upload Video Preview plugin extends the fileupload widget
51
  // with video preview functionality:
52
  $.widget('blueimp.fileupload', $.blueimp.fileupload, {
53
    options: {
54
      // The regular expression for the types of video files to load,
55
      // matched against the file type:
56
      loadVideoFileTypes: /^video\/.*$/
57
    },
58
 
59
    _videoElement: document.createElement('video'),
60
 
61
    processActions: {
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) {
68
          return data;
69
        }
70
        var file = data.files[data.index],
71
          url,
72
          video;
73
        if (
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))
79
        ) {
80
          url = loadImage.createObjectURL(file);
81
          if (url) {
82
            video = this._videoElement.cloneNode(false);
83
            video.src = url;
84
            video.controls = true;
85
            data.video = video;
86
            return data;
87
          }
88
        }
89
        return data;
90
      },
91
 
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;
96
        }
97
        return data;
98
      }
99
    }
100
  });
101
});