//c E:\myproducts_sites\test\xommon\upload\jquery.form.js.php /* * jQuery Form Plugin * version: 2.84 (12-AUG-2011) * @requires jQuery v1.3.2 or later * * Examples and documentation at: http://malsup.com/jquery/form/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ /* Usage Note: ----------- Do not use both ajaxSubmit and ajaxForm on the same form. These functions are intended to be exclusive. Use ajaxSubmit if you want to bind your own submit handler to the form. For example, $(document).ready(function() { $('#myForm').bind('submit', function(e) { e.preventDefault(); // <-- important $(this).ajaxSubmit({ target: '#output' }); }); }); Use ajaxForm when you want the plugin to manage all the event binding for you. For example, $(document).ready(function() { $('#myForm').ajaxForm({ target: '#output' }); }); When using ajaxForm, the ajaxSubmit function will be invoked for you at the appropriate time. */ function set_my_confirm_upload(txttagfind){ myApp.line=42;try{var tagfct='smcu'; var o,j=0,txtidselect0='select0'+txttagfind,y=GetId(txtidselect0,43); if(y){ //c si c`est un document uploadé alors mémoriser var last=findlast(txtidselect0); y=document.getElementsByName(txtidselect0)[last].value; o=GetId('statusline_'+txttagfind);if(o)j=o.value; if(j==5) if(!confirm('Do_you_want_set_this_actual_upload <'+y+'> ?'))return(false); else{ o=document.getElementsByName('imgphoto'+txttagfind)[last]; if(o&&o.innerHTML=='?') if(!confirm('Do_you_want_upload <'+y+'> ?'))return(false); } if(!y){//!\translate alert('Sélectionnez d`abord votre document dans la liste déroulante!'); return(false); } } myApp.line=61; var previewimage=GetId('previewimage',myApp.line++); if(!previewimage.style.height)previewimage.style.height='90px'; return(true); ////}catch(e){debug_view_e_catch(e,'display_formwithsteps.php : js_addlinetr_into_table()',myApp.line);} }catch(e){if($.isFunction(window.dbgvec))debug_view_e_catch(e,tagfct);} }//c function set_my_confirm_upload(txttagfind) //c \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ///function send_my_upload_datas(path,max_size,exts,idform,finalpath,del){ function send_my_upload_datas(path,max_size,exts,txttagfind,finalpath,del,dir_uploads){ //c lance la requête post pour charger l'image jquery.form.js.php ///alert('l:72 jquery.form.js.php'); myApp.line=150;try{var tagfct='smud'; var o,i=-1,data=new Array(); data['idx']=myApp.global; //myApp.infos;//c index de l'image data['path']=path; data['max_size']=max_size; data['exts']=exts; ///data['filetag']='file'+idform; data['tagfind']=txttagfind; data['finalpath']=finalpath; data['DIR_IMAGES']=finalpath; data['typeannounce']='motorcycle';//!\standby data['idannounce']='ah'; data['delete']='';//c delete='loaderformupload' data['upload']='upload'; data['DIR_UPLOADS']=dir_uploads;///kdirnamesameiservice; ////alert('l:86 ici jquery.forms.js.php'); //============== myApp.line=93; myDebug._alert(new Array(tagfct,myApp.line,data['idx'],data['finalpath'])); /* var x=(del&&GetId(del)?GetId(del):false); if(x){ if(confirm('Do_you_want_delete_image?')){ data[idx]['delete']=GetId(del).src; GetId(del).style.display=myApp.kcssnone; } else return(false); } */ //=========== o=GetId('statusline_'+txttagfind);if(o)o.value=i; js_set_elements_of_lineoftable(txttagfind,data['idx'],true,i);//c init line //=========== js_set_num_button(txttagfind,data['idx'],'orange',false); //=========== o=$('#'+'form_'+txttagfind); if(!o)alert('l:111 ici finalpath '+finalpath+' - '+'file_'+data['tagfind']); o.ajaxSubmit({target:'#'+'file_'+data['tagfind'],data:data}); ///return(false); ////}catch(e){debug_view_e_catch(e,'display_formwithsteps.php : send_my_upload_datas(path,max_size,exts,idform,finalpath,del)',myApp.line);} }catch(e){if($.isFunction(window.dbgvec))debug_view_e_catch(e,tagfct);} }//c function send_my_upload_datas(path,max_size,exts,idform,finalpath,del){ //c \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;(function($) { /* * ajaxSubmit() provides a mechanism for immediately submitting * an HTML form using AJAX. */ $.fn.ajaxSubmit=function(options) { // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) if (!this.length) { log('ajaxSubmit: skipping submit process - no element selected'); return this; } //============= var tagfct='$.fn.ajaxSubmit'; var x=this.attr('id').split('_'); ///// var y=this.attr('action');alert(y);//c ../../xommon/sites/display_create_simple_website.php ../../xommon/upload/ajaxupload-c.php var txttagfind=x[1]; /// E:\myproducts_sites\test\xommon\upload\jquery.form.js.php /// alert('58 ici '+txttagfind+' - jquery.form.js.php'); /* alert('txttagfind=this.attr(\'id\') : '+txttagfind);// form_upload alert(this.data); function (D,F){var G=D.split(".");G[1]=G[1]?"."+G[1]:"";if(F===g){var E=this.triggerHandler("getData"+G[1]+"!",[G[0]]);if(E===g&&this.length){E=n.data(this[0],D)}return E===g&&G[1]?this.data(G[0]):E}else{return this.trigger("setData"+G[1]+"!",[G[0],F]).each(function(){n.data(this,D,F)})}} */ var imgloader=GetId('loader'+txttagfind); if(imgloader)imgloader.style.display=myApp.kcssinline; var imgdel='';///GetId('imgdel'+this.attr('id')); //============= var method, action, url, $form=this; if (typeof options == 'function') { options={ success: options }; } method=this.attr('method'); action=this.attr('action'); url=(typeof action === 'string') ? $.trim(action) : ''; url=url || window.location.href || ''; if (url) { // clean url (don't include hash vaue) url=(url.match(/^([^#]+)/)||[])[1]; } options=$.extend(true, { url: url, success: $.ajaxSettings.success, type: method || 'GET', iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' }, options); // hook for manipulating the form data before it is extracted; // convenient for use with rich editors like tinyMCE or FCKEditor var veto={}; this.trigger('form-pre-serialize', [this, options, veto]); if (veto.veto) { log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); return this; } // provide opportunity to alter form data before it is serialized if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { log('ajaxSubmit: submit aborted via beforeSerialize callback'); return this; } var n,v,a=this.formToArray(options.semantic); if (options.data) { /// a lert('options.data: '+options.data); options.extraData=options.data; for (n in options.data) { if( $.isArray(options.data[n]) ) { for (var k in options.data[n]) { a.push( { name: n, value: options.data[n][k] } ); } } else { v=options.data[n]; v=$.isFunction(v) ? v() : v; // if value is fn, invoke it a.push( { name: n, value: v } ); } } } // give pre-submit callback an opportunity to abort the submit if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { log('ajaxSubmit: submit aborted via beforeSubmit callback'); return this; } // fire vetoable 'validate' event this.trigger('form-submit-validate', [a, this, options, veto]); if (veto.veto) { log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); return this; } var q=$.param(a); if (options.type.toUpperCase() == 'GET') { options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; options.data=null; // data is null for 'get' } else { options.data=q; // data is the query string for 'post' } var callbacks=[]; if (options.resetForm) { callbacks.push(function() { $form.resetForm(); }); } if (options.clearForm) { callbacks.push(function() { $form.clearForm(); }); } // perform a load on the target only if dataType is not provided if (!options.dataType && options.target) { var oldSuccess=options.success || function(){}; callbacks.push(function(data) { var fn=options.replaceTarget ? 'replaceWith' : 'html'; $(options.target)[fn](data).each(oldSuccess, arguments); }); } else if (options.success) { callbacks.push(options.success); } options.success=function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg var context=options.context || options; // jQuery 1.4+ supports scope context for (var i=0, max=callbacks.length; i < max; i++) { callbacks[i].apply(context, [data, status, xhr || $form, $form]); } }; // are there files to upload? var fileInputs=$('input:file', this).length > 0; var mp='multipart/form-data'; var multipart=($form.attr('enctype') == mp || $form.attr('encoding') == mp); // options.iframe allows user to force iframe mode // 06-NOV-09: now defaulting to iframe mode if file input is detected if (options.iframe !== false && (fileInputs || options.iframe || multipart)) { // hack to fix Safari hang (thanks to Tim Molendijk for this) // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d if (options.closeKeepAlive) { $.get(options.closeKeepAlive, function() { fileUpload(a); }); } else { fileUpload(a); } } else { // IE7 massage (see issue 57) if ($.browser.msie && method == 'get') { var ieMeth=$form[0].getAttribute('method'); if (typeof ieMeth === 'string') options.type=ieMeth; } $.ajax(options); } // fire 'notify' event this.trigger('form-submit-notify', [this, options]); return this; // private function for handling file uploads (hat tip to YAHOO!) function fileUpload(a) { var form=$form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle; var useProp=!!$.fn.prop; if (a) { // ensure that every serialized input is still enabled for (i=0; i < a.length; i++) { el=$(form[a[i].name]); el[ useProp ? 'prop' : 'attr' ]('disabled', false); } } if ($(':input[name=submit],:input[id=submit]', form).length) { // if there is an input with a name or id of 'submit' then we won't be // able to invoke the submit fn on the form (at least not x-browser) alert('Error: Form elements must not have name or id of "submit".'); return; } s=$.extend(true, {}, $.ajaxSettings, options); s.context=s.context || s; id='jqFormIO' + (new Date().getTime()); if (s.iframeTarget) { $io=$(s.iframeTarget); n=$io.attr('name'); if (n == null) $io.attr('name', id); else id=n; } else { $io=$(''); $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' }); } io=$io[0]; xhr={ // mock object aborted: 0, responseText: null, responseXML: null, status: 0, statusText: 'n/a', getAllResponseHeaders: function() {}, getResponseHeader: function() {}, setRequestHeader: function() {}, abort: function(status) { var e=(status === 'timeout' ? 'timeout' : 'aborted'); log('aborting upload... ' + e); this.aborted=1; $io.attr('src', s.iframeSrc); // abort op in progress xhr.error=e; s.error && s.error.call(s.context, xhr, e, status); g && $.event.trigger("ajaxError", [xhr, s, e]); s.complete && s.complete.call(s.context, xhr, e); } }; g=s.global; // trigger ajax global events so that activity/block indicators work like normal if (g && ! $.active++) { $.event.trigger("ajaxStart"); } if (g) { $.event.trigger("ajaxSend", [xhr, s]); } if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) { if (s.global) { $.active--; } return; } if (xhr.aborted) { return; } // add submitting element to data if we know it sub=form.clk; if (sub) { n=sub.name; if (n && !sub.disabled) { s.extraData=s.extraData || {}; s.extraData[n]=sub.value; if (sub.type == "image") { s.extraData[n+'.x']=form.clk_x; s.extraData[n+'.y']=form.clk_y; } } } var CLIENT_TIMEOUT_ABORT=1; var SERVER_ABORT=2; function getDoc(frame) { var doc=frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document; return doc; } // take a breath so that pending repaints get some cpu time before the upload starts function doSubmit() { // make sure form attrs are set var t=$form.attr('target'), a=$form.attr('action'); // update form attrs in IE friendly way form.setAttribute('target',id); if (!method) { form.setAttribute('method', 'POST'); } if (a != s.url) { form.setAttribute('action', s.url); } // ie borks in some cases when setting encoding if (! s.skipEncodingOverride && (!method || /post/i.test(method))) { $form.attr({ encoding: 'multipart/form-data', enctype: 'multipart/form-data' }); } // support timout if (s.timeout) { timeoutHandle=setTimeout(function() { timedOut=true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout); } // look for server aborts function checkState() { try { var state=getDoc(io).readyState; log('state=' + state); if (state.toLowerCase() == 'uninitialized') setTimeout(checkState,50); } catch(e) { log('Server abort: ' , e, ' (', e.name, ')'); cb(SERVER_ABORT); timeoutHandle && clearTimeout(timeoutHandle); timeoutHandle=undefined; } } // add "extra" data to form if provided in options var extraInputs=[]; try { if (s.extraData) { for (var n in s.extraData) { extraInputs.push( $('').attr('value',s.extraData[n]) .appendTo(form)[0]); } } if (!s.iframeTarget) { // add iframe to doc and submit the form $io.appendTo('body'); io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false); } setTimeout(checkState,15); form.submit(); } finally { // reset attrs and remove "extra" input elements form.setAttribute('action',a); if(t) { form.setAttribute('target', t); } else { $form.removeAttr('target'); } $(extraInputs).remove(); } } if (s.forceSync) { doSubmit(); } else { setTimeout(doSubmit, 10); // this lets dom updates render } var data, doc, domCheckCount=50, callbackProcessed; function cb(e) { if (xhr.aborted || callbackProcessed) { return; } try { doc=getDoc(io); } catch(ex) { log('cannot access response document: ', ex); e=SERVER_ABORT; } if (e === CLIENT_TIMEOUT_ABORT && xhr) { xhr.abort('timeout'); return; } else if (e == SERVER_ABORT && xhr) { xhr.abort('server abort'); return; } if (!doc || doc.location.href == s.iframeSrc) { // response not received yet if (!timedOut) return; } io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false); var status='success', errMsg; try { if (timedOut) { throw 'timeout'; } var isXml=s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc); log('isXml='+isXml); if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) { if (--domCheckCount) { // in some browsers (Opera) the iframe DOM is not always traversable when // the onload callback fires, so we loop a bit to accommodate log('requeing onLoad callback, DOM not available'); setTimeout(cb, 250); return; } // let this fall through because server response could be an empty document //log('Could not access iframe DOM after mutiple tries.'); //throw 'DOMException: not available'; } //log('response detected'); var docRoot=doc.body ? doc.body : doc.documentElement; xhr.responseText=docRoot ? docRoot.innerHTML : null; xhr.responseXML=doc.XMLDocument ? doc.XMLDocument : doc; if (isXml) s.dataType='xml'; xhr.getResponseHeader=function(header){ var headers={'content-type': s.dataType}; return headers[header]; }; // support for XHR 'status' & 'statusText' emulation : if (docRoot) { xhr.status=Number( docRoot.getAttribute('status') ) || xhr.status; xhr.statusText=docRoot.getAttribute('statusText') || xhr.statusText; } var dt=s.dataType || ''; var scr=/(json|script|text)/.test(dt.toLowerCase()); if (scr || s.textarea) { // see if user embedded response in textarea var ta=doc.getElementsByTagName('textarea')[0]; if (ta) { xhr.responseText=ta.value; // support for XHR 'status' & 'statusText' emulation : xhr.status=Number( ta.getAttribute('status') ) || xhr.status; xhr.statusText=ta.getAttribute('statusText') || xhr.statusText; } else if (scr) { // account for browsers injecting pre around json response var pre=doc.getElementsByTagName('pre')[0]; var b=doc.getElementsByTagName('body')[0]; if (pre) { xhr.responseText=pre.textContent ? pre.textContent : pre.innerHTML; } else if (b) { xhr.responseText=b.innerHTML; } } } else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) { xhr.responseXML=toXml(xhr.responseText); } try { data=httpData(xhr, s.dataType, s); } catch (e) { status='parsererror'; xhr.error=errMsg=(e || status); } } catch (e) { log('error caught: ',e); status='error'; xhr.error=errMsg=(e || status); } if (xhr.aborted) { log('upload aborted'); status=null; } if (xhr.status) { // we've set xhr.status status=(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error'; } // ordering of these callbacks/triggers is odd, but that's how $.ajax does it //============= ///alert('515 ici '+data); //c alert(data); //c permet de repérer les erreurs de syntaxes dans ajaxupload-c.php var err=data.split('