1 2jQuery.extend({ 3 4 5 createUploadIframe: function(id, uri) 6 { 7 //create frame 8 var frameId = 'jUploadFrame' + id; 9 var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"'; 10 if(window.ActiveXObject) 11 { 12 if(typeof uri== 'boolean'){ 13 iframeHtml += ' src="' + 'javascript:false' + '"'; 14 15 } 16 else if(typeof uri== 'string'){ 17 iframeHtml += ' src="' + uri + '"'; 18 19 } 20 } 21 iframeHtml += ' />'; 22 jQuery(iframeHtml).appendTo(document.body); 23 24 return jQuery('#' + frameId).get(0); 25 }, 26 createUploadForm: function(id, fileElementId, data) 27 { 28 //create form 29 var formId = 'jUploadForm' + id; 30 var fileId = 'jUploadFile' + id; 31 var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"><input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" /></form>'); 32 if(data) 33 { 34 for(var i in data) 35 { 36 jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form); 37 } 38 } 39 var oldElement = jQuery('#' + fileElementId); 40 var newElement = jQuery(oldElement).clone(); 41 jQuery(oldElement).attr('id', fileId); 42 jQuery(oldElement).before(newElement); 43 jQuery(oldElement).appendTo(form); 44 45 46 47 //set attributes 48 jQuery(form).css('position', 'absolute'); 49 jQuery(form).css('top', '-1200px'); 50 jQuery(form).css('left', '-1200px'); 51 jQuery(form).appendTo('body'); 52 return form; 53 }, 54 55 ajaxFileUpload: function(s) { 56 // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout 57 s = jQuery.extend({}, jQuery.ajaxSettings, s); 58 var id = new Date().getTime() 59 var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data)); 60 var io = jQuery.createUploadIframe(id, s.secureuri); 61 var frameId = 'jUploadFrame' + id; 62 var formId = 'jUploadForm' + id; 63 // Watch for a new set of requests 64 if ( s.global && ! jQuery.active++ ) 65 { 66 jQuery.event.trigger( "ajaxStart" ); 67 } 68 var requestDone = false; 69 // Create the request object 70 var xml = {} 71 if ( s.global ) 72 jQuery.event.trigger("ajaxSend", [xml, s]); 73 // Wait for a response to come back 74 var uploadCallback = function(isTimeout) 75 { 76 var io = document.getElementById(frameId); 77 try 78 { 79 if(io.contentWindow) 80 { 81 xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; 82 xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; 83 84 }else if(io.contentDocument) 85 { 86 xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null; 87 xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document; 88 } 89 }catch(e) 90 { 91 jQuery.handleError(s, xml, null, e); 92 } 93 if ( xml || isTimeout == "timeout") 94 { 95 requestDone = true; 96 var status; 97 try { 98 status = isTimeout != "timeout" ? "success" : "error"; 99 // Make sure that the request was successful or notmodified 100 if ( status != "error" ) 101 { 102 // process the data (runs the xml through httpData regardless of callback) 103 var data = jQuery.uploadHttpData( xml, s.dataType ); 104 // If a local callback was specified, fire it and pass it the data 105 if ( s.success ) 106 s.success( data, status ); 107 108 // Fire the global callback 109 if( s.global ) 110 jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 111 } else 112 jQuery.handleError(s, xml, status); 113 } catch(e) 114 { 115 status = "error"; 116 jQuery.handleError(s, xml, status, e); 117 } 118 119 // The request was completed 120 if( s.global ) 121 jQuery.event.trigger( "ajaxComplete", [xml, s] ); 122 123 // Handle the global AJAX counter
124 if ( s.global && ! --jQuery.active ) 125 jQuery.event.trigger( "ajaxStop" ); 126 127 // Process result 128 if ( s.complete ) 129 s.complete(xml, status); 130 131 jQuery(io).unbind() 132 133 setTimeout(function() 134 { try 135 { 136 jQuery(io).remove(); 137 jQuery(form).remove(); 138 139 } catch(e) 140 { 141 jQuery.handleError(s, xml, null, e); 142 } 143 144 }, 100) 145 146 xml = null 147 148 } 149 } 150 // Timeout checker 151 if ( s.timeout > 0 ) 152 { 153 setTimeout(function(){ 154 // Check to see if the request is still happening 155 if( !requestDone ) uploadCallback( "timeout" ); 156 }, s.timeout); 157 } 158 try 159 { 160 161 var form = jQuery('#' + formId); 162 jQuery(form).attr('action', s.url); 163 jQuery(form).attr('method', 'POST'); 164 jQuery(form).attr('target', frameId); 165 if(form.encoding) 166 { 167 jQuery(form).attr('encoding', 'multipart/form-data'); 168 } 169 else 170 { 171 jQuery(form).attr('enctype', 'multipart/form-data'); 172 } 173 jQuery(form).submit(); 174 175 } catch(e) 176 { 177 jQuery.handleError(s, xml, null, e); 178 } 179 180 jQuery('#' + frameId).load(uploadCallback ); 181 return {abort: function () {}}; 182 183 }, 184 185 uploadHttpData: function( r, type ) { 186 var data = !type; 187 data = type == "xml" || data ? r.responseXML : r.responseText; 188 // If the type is "script", eval it in global context 189 if ( type == "script" ) 190 jQuery.globalEval( data ); 191 // Get the JavaScript object, if JSON is used. 192 if ( type == "json" ) 193 eval( "data = " + data ); 194 // evaluate scripts within html 195 if ( type == "html" ) 196 jQuery("<div>").html(data).evalScripts(); 197 198 return data; 199 } 200}) 201
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.