forked from blueimp/jQuery-File-Upload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.js
More file actions
79 lines (71 loc) · 2.35 KB
/
application.js
File metadata and controls
79 lines (71 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* jQuery File Upload Plugin JS Example 6.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
/*jslint nomen: true, unparam: true, regexp: true */
/*global $, window, document */
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
if (window.location.hostname === 'blueimp.github.com') {
// Demo settings:
$('#fileupload').prop(
'action',
'//jquery-file-upload.appspot.com'
);
$('#fileupload').fileupload('option', {
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
});
} else {
// Load existing files:
$.getJSON($('#fileupload').prop('action'), function (files) {
var fu = $('#fileupload').data('fileupload'),
template;
fu._adjustMaxNumberOfFiles(-files.length);
template = fu._renderDownload(files)
.appendTo($('#fileupload .files'));
// Force reflow:
fu._reflow = fu._transition && template.length &&
template[0].offsetWidth;
template.addClass('in');
});
}
// Enable iframe cross-domain access via redirect page:
var redirectPage = window.location.href.replace(
/\/[^\/]*$/,
'/result.html?%s'
);
$('#fileupload').bind('fileuploadsend', function (e, data) {
if (data.dataType.substr(0, 6) === 'iframe') {
var target = $('<a/>').prop('href', data.url)[0];
if (window.location.host !== target.host) {
data.formData.push({
name: 'redirect',
value: redirectPage
});
}
}
});
// Open download dialogs via iframes,
// to prevent aborting current uploads:
$('#fileupload .files').delegate(
'a:not([rel^=gallery])',
'click',
function (e) {
e.preventDefault();
$('<iframe style="display:none;"></iframe>')
.prop('src', this.href)
.appendTo(document.body);
}
);
// Initialize the Bootstrap Image Gallery plugin:
$('#fileupload .files').imagegallery();
});