PageSourceSearch

https://bip.piotrkowkujawski.pl/js/lib_extension/jQueryFileUpload/js/jquery.fileupload-audio.js

js piotrkowkujawski.pl collected 2026-10-02 19:20:26 UTC 3,532 bytes, 112 lines download raw bytes

1/*
2 * jQuery File Upload Audio 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: 'loadAudio',
44            // Use the action as prefix for the "@" options:
45            prefix: true,
46            fileTypes: '@',
47            maxFileSize: '@',
48            disabled: '@disableAudioPreview'
49        },
50        {
51            action: 'setAudio',
52            name: '@audioPreviewName',
53            disabled: '@disableAudioPreview'
54        }
55    );
56
57    // The File Upload Audio Preview plugin extends the fileupload widget
58    // with audio preview functionality:
59    $.widget('blueimp.fileupload', $.blueimp.fileupload, {
60
61        options: {
62            // The regular expression for the types of audio files to load,
63            // matched against the file type:
64            loadAudioFileTypes: /^audio\/.*$/
65        },
66
67        _audioElement: document.createElement('audio'),
68
69        processActions: {
70
71            // Loads the audio file given via data.files and data.index
72            // as audio 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            loadAudio: function (data, options) {
76                if (options.disabled) {
77                    return data;
78                }
79                var file = data.files[data.index],
80                    url,
81                    audio;
82                if (this._audioElement.canPlayType &&
83                        this._audioElement.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                        audio = this._audioElement.cloneNode(false);
91                        audio.src = url;
92                        audio.controls = true;
93                        data.audio = audio;
94                        return data;
95                    }
96                }
97                return data;
98            },
99
100            // Sets the audio element as a property of the file object:
101            setAudio: function (data, options) {
102                if (data.audio && !options.disabled) {
103                    data.files[data.index][options.name || 'preview'] = data.audio;
104                }
105                return data;
106            }
107
108        }
109
110    });
111
112}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.