PageSourceSearch

https://hobbyfan.com.tw/Public/Home/js/ajaxfileupload.js

js hobbyfan.com.tw collected 2026-10-07 18:47:51 UTC 7,053 bytes, 211 lines download raw bytes

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

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.