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