Support for legacy browsers

This commit is contained in:
Simon Birnbach 2012-03-16 19:58:28 +01:00
parent b949619d04
commit 9377b75350
3 changed files with 183 additions and 95 deletions

View File

@ -30,6 +30,7 @@ OC_Util::checkLoggedIn();
// Load the files we need
OC_Util::addStyle( "files", "files" );
OC_Util::addScript( "files", "jquery.iframe-transport" );
OC_Util::addScript( "files", "jquery.fileupload" );
OC_Util::addScript( "files", "files" );
OC_Util::addScript( 'files', 'filelist' );

View File

@ -150,87 +150,6 @@ $(document).ready(function() {
return false;
});
/*
$('.file_upload_start').live('change',function(){
var form=$(this).closest('form');
var that=this;
var uploadId=form.attr('data-upload-id');
var files=this.files;
var target=form.children('iframe');
var totalSize=0;
if(files){
for(var i=0;i<files.length;i++){
totalSize+=files[i].size;
if(FileList.deleteFiles && FileList.deleteFiles.indexOf(files[i].name)!=-1){//finish delete if we are uploading a deleted file
FileList.finishDelete(function(){
$(that).change();
});
return;
}
}
}
if(totalSize>$('#max_upload').val()){
$( "#uploadsize-message" ).dialog({
modal: true,
buttons: {
Close: function() {
$( this ).dialog( "close" );
}
}
});
}else{
target.load(function(){
var response=jQuery.parseJSON(target.contents().find('body').text());
//set mimetype and if needed filesize
if(response){
if(response[0] != undefined && response[0].status == 'success'){
for(var i=0;i<response.length;i++){
var file=response[i];
$('tr').filterAttr('data-file',file.name).data('mime',file.mime);
if(size=='Pending'){
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
}
FileList.loadingDone(file.name);
}
}
else{
$('#notification').text(t('files',response.data.message));
$('#notification').fadeIn();
$('#fileList > tr').not('[data-mime]').fadeOut();
$('#fileList > tr').not('[data-mime]').remove();
}
}
});
form.submit();
var date=new Date();
if(files){
for(var i=0;i<files.length;i++){
if(files[i].size>0){
var size=files[i].size;
}else{
var size=t('files','Pending');
}
if(files){
FileList.addFile(files[i].name,size,date,true);
}
}
}else{
var filename=this.value.split('\\').pop(); //ie prepends C:\fakepath\ in front of the filename
FileList.addFile(filename,'Pending',date,true);
}
//clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading
var clone=form.clone();
uploadId++;
clone.attr('data-upload-id',uploadId);
clone.attr('target','file_upload_target_'+uploadId);
clone.children('iframe').attr('name','file_upload_target_'+uploadId)
clone.insertBefore(form);
form.hide();
}
});
*/
// drag&drop support using jquery.fileupload
$(function() {
$('.file_upload_start').fileupload({
@ -279,21 +198,24 @@ $(document).ready(function() {
}
},
done: function(e, data) {
var response=jQuery.parseJSON(data.result);
var response;
if(data.dataType == 'iframe ') {
response = jQuery.parseJSON(data.result[0].body.innerText);
} else {
response=jQuery.parseJSON(data.result);
}
if(response[0] != undefined && response[0].status == 'success') {
for(var i=0;i<data.files.length;i++){
var file=data.files[i];
if(file.size>0){
var size=file.size;
}else{
var size=t('files','Pending');
}
$('tr').filterAttr('data-file',file.name).data('mime',file.mime);
if(size=='Pending'){
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
}
FileList.loadingDone(file.name);
var file=response[0];
if(file.size>0){
var size=file.size;
}else{
var size=t('files','Pending');
}
$('tr').filterAttr('data-file',file.name).data('mime',file.type);
if(size=='Pending'){
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
}
FileList.loadingDone(file.name);
} else {
$('#notification').text(t('files', response.data.message));
$('#notification').fadeIn();
@ -302,10 +224,10 @@ $(document).ready(function() {
}
},
fail: function(e, data) {
console.debug('Fail', data);
// TODO: cancel upload & display error notification
},
progress: function(e, data) {
// TODO: show nice progress bar
}
})
});

View File

@ -0,0 +1,165 @@
/*
* jQuery Iframe Transport Plugin 1.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
/*jslint unparam: true, nomen: true */
/*global define, window, document */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define(['jquery'], factory);
} else {
// Browser globals:
factory(window.jQuery);
}
}(function ($) {
'use strict';
// Helper variable to create unique names for the transport iframes:
var counter = 0;
// The iframe transport accepts three additional options:
// options.fileInput: a jQuery collection of file input fields
// options.paramName: the parameter name for the file form data,
// overrides the name property of the file input field(s)
// options.formData: an array of objects with name and value properties,
// equivalent to the return data of .serializeArray(), e.g.:
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
$.ajaxTransport('iframe', function (options) {
if (options.async && (options.type === 'POST' || options.type === 'GET')) {
var form,
iframe;
return {
send: function (_, completeCallback) {
form = $('<form style="display:none;"></form>');
// javascript:false as initial iframe src
// prevents warning popups on HTTPS in IE6.
// IE versions below IE8 cannot set the name property of
// elements that have already been added to the DOM,
// so we set the name along with the iframe HTML markup:
iframe = $(
'<iframe src="javascript:false;" name="iframe-transport-' +
(counter += 1) + '"></iframe>'
).bind('load', function () {
var fileInputClones;
iframe
.unbind('load')
.bind('load', function () {
var response;
// Wrap in a try/catch block to catch exceptions thrown
// when trying to access cross-domain iframe contents:
try {
response = iframe.contents();
// Google Chrome and Firefox do not throw an
// exception when calling iframe.contents() on
// cross-domain requests, so we unify the response:
if (!response.length || !response[0].firstChild) {
throw new Error();
}
} catch (e) {
response = undefined;
}
// The complete callback returns the
// iframe content document as response object:
completeCallback(
200,
'success',
{'iframe': response}
);
// Fix for IE endless progress bar activity bug
// (happens on form submits to iframe targets):
$('<iframe src="javascript:false;"></iframe>')
.appendTo(form);
form.remove();
});
form
.prop('target', iframe.prop('name'))
.prop('action', options.url)
.prop('method', options.type);
if (options.formData) {
$.each(options.formData, function (index, field) {
$('<input type="hidden"/>')
.prop('name', field.name)
.val(field.value)
.appendTo(form);
});
}
if (options.fileInput && options.fileInput.length &&
options.type === 'POST') {
fileInputClones = options.fileInput.clone();
// Insert a clone for each file input field:
options.fileInput.after(function (index) {
return fileInputClones[index];
});
if (options.paramName) {
options.fileInput.each(function () {
$(this).prop('name', options.paramName);
});
}
// Appending the file input fields to the hidden form
// removes them from their original location:
form
.append(options.fileInput)
.prop('enctype', 'multipart/form-data')
// enctype must be set as encoding for IE:
.prop('encoding', 'multipart/form-data');
}
form.submit();
// Insert the file input fields at their original location
// by replacing the clones with the originals:
if (fileInputClones && fileInputClones.length) {
options.fileInput.each(function (index, input) {
var clone = $(fileInputClones[index]);
$(input).prop('name', clone.prop('name'));
clone.replaceWith(input);
});
}
});
form.append(iframe).appendTo(document.body);
},
abort: function () {
if (iframe) {
// javascript:false as iframe src aborts the request
// and prevents warning popups on HTTPS in IE6.
// concat is used to avoid the "Script URL" JSLint error:
iframe
.unbind('load')
.prop('src', 'javascript'.concat(':false;'));
}
if (form) {
form.remove();
}
}
};
}
});
// The iframe transport returns the iframe content document as response.
// The following adds converters from iframe to text, json, html, and script:
$.ajaxSetup({
converters: {
'iframe text': function (iframe) {
return $(iframe[0].body).text();
},
'iframe json': function (iframe) {
return $.parseJSON($(iframe[0].body).text());
},
'iframe html': function (iframe) {
return $(iframe[0].body).html();
},
'iframe script': function (iframe) {
return $.globalEval($(iframe[0].body).text());
}
}
});
}));