2024年4月26日发(作者:)
:
({
createUploadIframe: function(id, uri)
{
//create frame
var frameId = 'jUploadFrame' + id;
if(XObject) {
var io = Element('');
if(typeof uri== 'boolean'){
= 'javascript:false';
}
else if(typeof uri== 'string'){
= uri;
}
}
else {
var io = Element('iframe');
= frameId;
= frameId;
}
on = 'absolute';
= '-1000px';
= '-1000px';
Child(io);
return io
},
createUploadForm: function(id, fileElementId)
{
//create form
var formId = 'jUploadForm' + id;
var fileId = 'jUploadFile' + id;
var form = $('
');var oldElement = $('#' + fileElementId);
var newElement = $(oldElement).clone();
$(oldElement).attr('id', fileId);
$(oldElement).before(newElement);
$(oldElement).appendTo(form);
//set attributes
$(form).css('position', 'absolute');
$(form).css('top', '-1200px');
$(form).css('left', '-1200px');
$(form).appendTo('body');
return form;
},
addOtherRequestsToForm: function(form,data)
{
// add extra parameter
var originalElement = $('');
for (var key in data) {
name = key;
value = data[key];
var cloneElement = ();
({'name':name,'value':value});
$(cloneElement).appendTo(form);
}
return form;
},
ajaxFileUpload: function(s) {
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
s = ({}, ttings, s);
var id = new Date().getTime()
var form = UploadForm(id, ementId);
if ( ) form = erRequestsToForm(form,);
var io = UploadIframe(id, uri);
var frameId = 'jUploadFrame' + id;
var formId = 'jUploadForm' + id;
// Watch for a new set of requests
if ( && ! ++ )
{
r( "ajaxStart" );
}
var requestDone = false;
// Create the request object
var xml = {}
if ( )
r("ajaxSend", [xml, s]);
// Wait for a response to come back
var uploadCallback = function(isTimeout)
{
var io = mentById(frameId);
try
{
if(tWindow)
{
seText = ?TML:null;
seXML = ument?ument:nt;
}else if(tDocument)
{
seText = ?TML:null;
seXML = ument?ument:nt;
}
}catch(e)
{
Error(s, xml, null, e);
}
if ( xml || isTimeout == "timeout")
{
requestDone = true;
var status;
try {
status = isTimeout != "timeout" ? "success" : "error";
// Make sure that the request was successful or notmodified
if ( status != "error" )
{
// process the data (runs the xml through httpData regardless of callback)
var data = HttpData( xml, pe );
// If a local callback was specified, fire it and pass it the data
if ( s )
s( data, status );
// Fire the global callback
if( )
r( "ajaxSuccess", [xml, s] );
} else
Error(s, xml, status);
} catch(e)
{
status = "error";
Error(s, xml, status, e);
}
// The request was completed
if( )
r( "ajaxComplete", [xml, s] );
// Handle the global AJAX counter
if ( && ! -- )
r( "ajaxStop" );
// Process result
if ( te )
te(xml, status);
jQuery(io).unbind()
setTimeout(function()
{ try
{
$(io).remove();
$(form).remove();
} catch(e)
{
Error(s, xml, null, e);
}
}, 100)
xml = null
}
}
// Timeout checker
if ( t > 0 )
{
setTimeout(function(){
// Check to see if the request is still happening
if( !requestDone ) uploadCallback( "timeout" );
}, t);
}
try
{
// var io = $('#' + frameId);
var form = $('#' + formId);
$(form).attr('action', );
$(form).attr('method', 'POST');
$(form).attr('target', frameId);
if(ng)
{
ng = 'multipart/form-data';
}
else
{
e = 'multipart/form-data';
}
$(form).submit();
} catch(e)
{
Error(s, xml, null, e);
}
if(Event){
mentById(frameId).attachEvent('onload', uploadCallback);
}
else{
mentById(frameId).addEventListener('load', uploadCallback, false);
}
return {abort: function () {}};
},
uploadHttpData: function( r, type ) {
var data = !type;
data = type == "xml" || data ? seXML : seText;
// If the type is "script", eval it in global context
if ( type == "script" )
Eval( data );
// Get the JavaScript object, if JSON is used.
if ( type == "json" )
eval( "data = " + data );
// evaluate scripts within html
if ( type == "html" )
jQuery("
//alert($('param', data).each(function(){alert($(this).attr('value'));}));
return data;
}
})


发布评论