Skip to content

Commit

Permalink
Remove obsolete and streamline code due to the new redirect option an…
Browse files Browse the repository at this point in the history
…d the HTML5 download attribute for the file download links.
  • Loading branch information
blueimp committed Feb 13, 2012
1 parent 6e997bd commit 1d1c1a2
Showing 1 changed file with 19 additions and 36 deletions.
55 changes: 19 additions & 36 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin JS Example 6.4
* jQuery File Upload Plugin JS Example 6.5
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand All @@ -18,6 +18,16 @@ $(function () {
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();

// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/cors/result.html?%s'
)
);

if (window.location.hostname === 'blueimp.github.com') {
// Demo settings:
$('#fileupload').fileupload('option', {
Expand All @@ -41,42 +51,15 @@ $(function () {
}
} else {
// Load existing files:
$.getJSON($('#fileupload').prop('action'), function (result) {
if (result && result.length) {
$('#fileupload').fileupload('option', 'done')
.call($('#fileupload')[0], null, {result: result});
}
$('#fileupload').each(function () {
var that = this;
$.getJSON(this.action, function (result) {
if (result && result.length) {
$(that).fileupload('option', 'done')
.call(that, null, {result: result});
}
});
});
}

// Enable iframe cross-domain access via redirect page:
var redirectPage = window.location.href.replace(
/\/[^\/]*$/,
'/cors/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);
}
);

});

0 comments on commit 1d1c1a2

Please sign in to comment.