hjg
2024-07-09 30304784e82d4bba24121328da8eb8490aec4f4f
提交 | 用户 | 时间
58d006 1 /*
A 2  * jQuery File Upload Plugin JS Example 8.9.1
3  * https://github.com/blueimp/jQuery-File-Upload
4  *
5  * Copyright 2010, Sebastian Tschan
6  * https://blueimp.net
7  *
8  * Licensed under the MIT license:
9  * http://www.opensource.org/licenses/MIT
10  */
11
12 /* global $, window */
13
14 $(function () {
15     'use strict';
16
17     // Initialize the jQuery File Upload widget:
18     $('#fileupload').fileupload({
19         // Uncomment the following to send cross-domain cookies:
20         //xhrFields: {withCredentials: true},
21         url: 'server/php/'
22     });
23
24     // Enable iframe cross-domain access via redirect option:
25     $('#fileupload').fileupload(
26         'option',
27         'redirect',
28         window.location.href.replace(
29             /\/[^\/]*$/,
30             '/cors/result.html?%s'
31         )
32     );
33
34     if (window.location.hostname === 'blueimp.github.io') {
35         // Demo settings:
36         $('#fileupload').fileupload('option', {
37             url: '//jquery-file-upload.appspot.com/',
38             // Enable image resizing, except for Android and Opera,
39             // which actually support image resizing, but fail to
40             // send Blob objects via XHR requests:
41             disableImageResize: /Android(?!.*Chrome)|Opera/
42                 .test(window.navigator.userAgent),
43             maxFileSize: 5000000,
44             acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
45         });
46         // Upload server status check for browsers with CORS support:
47         if ($.support.cors) {
48             $.ajax({
49                 url: '//jquery-file-upload.appspot.com/',
50                 type: 'HEAD'
51             }).fail(function () {
52                 $('<div class="alert alert-danger"/>')
53                     .text('Upload server currently unavailable - ' +
54                             new Date())
55                     .appendTo('#fileupload');
56             });
57         }
58     } else {
59         // Load existing files:
60         $('#fileupload').addClass('fileupload-processing');
61         $.ajax({
62             // Uncomment the following to send cross-domain cookies:
63             //xhrFields: {withCredentials: true},
64             url: $('#fileupload').fileupload('option', 'url'),
65             dataType: 'json',
66             context: $('#fileupload')[0]
67         }).always(function () {
68             $(this).removeClass('fileupload-processing');
69         }).done(function (result) {
70             $(this).fileupload('option', 'done')
71                 .call(this, $.Event('done'), {result: result});
72         });
73     }
74
75 });