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
90 lines (81 loc) · 2.6 KB
/
application.js
File metadata and controls
90 lines (81 loc) · 2.6 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
80
81
82
83
84
85
86
87
88
89
90
/*
* jQuery File Upload Plugin JS Example 5.1.5
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://creativecommons.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 form').prop(
'action',
'//jquery-file-upload.appspot.com'
);
$('#fileupload').fileupload('option', {
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
});
} else {
// Load existing files:
$.getJSON($('#fileupload form').prop('action'), function (files) {
var fu = $('#fileupload').data('fileupload');
fu._adjustMaxNumberOfFiles(-files.length);
fu._renderDownload(files)
.appendTo($('#fileupload .files'))
.fadeIn(function () {
// Fix for IE7 and lower:
$(this).show();
});
});
}
// 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 Image Gallery widget:
$('#fileupload .files').imagegallery();
// Initialize the theme switcher:
$('#theme-switcher').change(function () {
var theme = $('#theme');
theme.prop(
'href',
theme.prop('href').replace(
/[\w\-]+\/jquery-ui.css/,
$(this).val() + '/jquery-ui.css'
)
);
});
});