Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
776 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
 * http://www.opensource.org/licenses/MIT
10
 */
11
 
12
/* jshint nomen:false */
13
/* global define, require, window, document */
14
 
15
(function (factory) {
16
    'use strict';
17
    if (typeof define === 'function' && define.amd) {
18
        // Register as an anonymous AMD module:
19
        define([
20
            'jquery',
21
            'load-image',
22
            './jquery.fileupload-process'
23
        ], factory);
24
    } else if (typeof exports === 'object') {
25
        // Node/CommonJS:
26
        factory(
27
            require('jquery'),
28
            require('load-image')
29
        );
30
    } else {
31
        // Browser globals:
32
        factory(
33
            window.jQuery,
34
            window.loadImage
35
        );
36
    }
37
}(function ($, loadImage) {
38
    'use strict';
39
 
40
    // Prepend to the default processQueue:
41
    $.blueimp.fileupload.prototype.options.processQueue.unshift(
42
        {
43
            action: 'loadVideo',
44
            // Use the action as prefix for the "@" options:
45
            prefix: true,
46
            fileTypes: '@',
47
            maxFileSize: '@',
48
            disabled: '@disableVideoPreview'
49
        },
50
        {
51
            action: 'setVideo',
52
            name: '@videoPreviewName',
53
            disabled: '@disableVideoPreview'
54
        }
55
    );
56
 
57
    // The File Upload Video Preview plugin extends the fileupload widget
58
    // with video preview functionality:
59
    $.widget('blueimp.fileupload', $.blueimp.fileupload, {
60
 
61
        options: {
62
            // The regular expression for the types of video files to load,
63
            // matched against the file type:
64
            loadVideoFileTypes: /^video\/.*$/
65
        },
66
 
67
        _videoElement: document.createElement('video'),
68
 
69
        processActions: {
70
 
71
            // Loads the video file given via data.files and data.index
72
            // as video element if the browser supports playing it.
73
            // Accepts the options fileTypes (regular expression)
74
            // and maxFileSize (integer) to limit the files to load:
75
            loadVideo: function (data, options) {
76
                if (options.disabled) {
77
                    return data;
78
                }
79
                var file = data.files[data.index],
80
                    url,
81
                    video;
82
                if (this._videoElement.canPlayType &&
83
                        this._videoElement.canPlayType(file.type) &&
84
                        ($.type(options.maxFileSize) !== 'number' ||
85
                            file.size <= options.maxFileSize) &&
86
                        (!options.fileTypes ||
87
                            options.fileTypes.test(file.type))) {
88
                    url = loadImage.createObjectURL(file);
89
                    if (url) {
90
                        video = this._videoElement.cloneNode(false);
91
                        video.src = url;
92
                        video.controls = true;
93
                        data.video = video;
94
                        return data;
95
                    }
96
                }
97
                return data;
98
            },
99
 
100
            // Sets the video element as a property of the file object:
101
            setVideo: function (data, options) {
102
                if (data.video && !options.disabled) {
103
                    data.files[data.index][options.name || 'preview'] = data.video;
104
                }
105
                return data;
106
            }
107
 
108
        }
109
 
110
    });
111
 
112
}));