Index: openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection-debug.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection-debug.js,v diff -u -r1.3 -r1.4 --- openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection-debug.js 8 Sep 2007 14:22:01 -0000 1.3 +++ openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection-debug.js 9 Apr 2009 17:03:49 -0000 1.4 @@ -1,8 +1,8 @@ /* -Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt -version: 2.3.0 +version: 2.7.0 */ /** * The Connection Manager provides a simplified interface to the XMLHttpRequest @@ -33,9 +33,9 @@ * @type array */ _msxml_progid:[ + 'Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.3.0', - 'MSXML2.XMLHTTP', - 'Microsoft.XMLHTTP' + 'MSXML2.XMLHTTP' ], /** @@ -69,10 +69,7 @@ _use_default_post_header:true, /** - * @description Determines if a default header of - * Content-Type of 'application/x-www-form-urlencoded' - * will be added to client HTTP headers sent for POST - * transactions. + * @description The default header used for POST transactions. * @property _default_post_header * @private * @static @@ -81,6 +78,16 @@ _default_post_header:'application/x-www-form-urlencoded; charset=UTF-8', /** + * @description The default header used for transactions involving the + * use of HTML forms. + * @property _default_form_header + * @private + * @static + * @type boolean + */ + _default_form_header:'application/x-www-form-urlencoded', + + /** * @description Determines if a default header of * 'X-Requested-With: XMLHttpRequest' * will be added to each transaction. @@ -227,8 +234,9 @@ document, 'click', function(e){ - var obj = YAHOO.util.Event.getTarget(e); - if(obj.type == 'submit'){ + var obj = YAHOO.util.Event.getTarget(e), + name = obj.nodeName.toLowerCase(); + if((name === 'input' || name === 'button') && (obj.type && obj.type.toLowerCase() == 'submit')){ YAHOO.util.Connect._submitElementValue = encodeURIComponent(obj.name) + "=" + encodeURIComponent(obj.value); } }); @@ -329,7 +337,7 @@ }, /** - * @description Member to enable or disable the default POST header. + * @description Member to override the default POST header. * @method setDefaultPostHeader * @public * @static @@ -338,12 +346,17 @@ */ setDefaultPostHeader:function(b) { - this._use_default_post_header = b; - YAHOO.log('Use default POST header set to ' + b, 'info', 'Connection'); + if(typeof b == 'string'){ + this._default_post_header = b; + YAHOO.log('Default POST header set to ' + b, 'info', 'Connection'); + } + else if(typeof b == 'boolean'){ + this._use_default_post_header = b; + } }, /** - * @description Member to enable or disable the default POST header. + * @description Member to override the default transaction header.. * @method setDefaultXhrHeader * @public * @static @@ -352,8 +365,13 @@ */ setDefaultXhrHeader:function(b) { - this._use_default_xhr_header = b; - YAHOO.log('Use default transaction header set to ' + b, 'info', 'Connection'); + if(typeof b == 'string'){ + this._default_xhr_header = b; + YAHOO.log('Default XHR header set to ' + b, 'info', 'Connection'); + } + else{ + this._use_default_xhr_header = b; + } }, /** @@ -397,14 +415,14 @@ for(var i=0; i= 200 && httpStatus < 300 || httpStatus === 1223){ - responseObject = this.createResponseObject(o, callback.argument); - if(callback.success){ + responseObject = this.createResponseObject(o, args); + if(callback && callback.success){ if(!callback.scope){ callback.success(responseObject); YAHOO.log('Success callback. HTTP code is ' + httpStatus, 'info', 'Connection'); @@ -690,8 +715,8 @@ case 12031: case 12152: // Connection closed by server. case 13030: // See above comments for variable status. - responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort?isAbort:false)); - if(callback.failure){ + responseObject = this.createExceptionObject(o.tId, args, (isAbort?isAbort:false)); + if(callback && callback.failure){ if(!callback.scope){ callback.failure(responseObject); YAHOO.log('Failure callback. Exception detected. Status code is ' + httpStatus, 'warn', 'Connection'); @@ -701,10 +726,11 @@ YAHOO.log('Failure callback with scope. Exception detected. Status code is ' + httpStatus, 'warn', 'Connection'); } } + break; default: - responseObject = this.createResponseObject(o, callback.argument); - if(callback.failure){ + responseObject = this.createResponseObject(o, args); + if(callback && callback.failure){ if(!callback.scope){ callback.failure(responseObject); YAHOO.log('Failure callback. HTTP status code is ' + httpStatus, 'warn', 'Connection'); @@ -769,7 +795,7 @@ obj.responseText = o.conn.responseText; obj.responseXML = o.conn.responseXML; - if(typeof callbackArg !== undefined){ + if(callbackArg){ obj.argument = callbackArg; } @@ -829,19 +855,11 @@ * automatically sent with each transaction. * @return {void} */ - initHeader:function(label,value,isDefault) + initHeader:function(label, value, isDefault) { var headerObj = (isDefault)?this._default_headers:this._http_headers; + headerObj[label] = value; - if(headerObj[label] === undefined){ - headerObj[label] = value; - } - else{ - // Concatenate multiple values, comma-delimited, - // for the same header label, - headerObj[label] = value + "," + headerObj[label]; - } - if(isDefault){ this._has_default_headers = true; } @@ -861,8 +879,9 @@ */ setHeader:function(o) { + var prop; if(this._has_default_headers){ - for(var prop in this._default_headers){ + for(prop in this._default_headers){ if(YAHOO.lang.hasOwnProperty(this._default_headers, prop)){ o.conn.setRequestHeader(prop, this._default_headers[prop]); YAHOO.log('Default HTTP header ' + prop + ' set with value of ' + this._default_headers[prop], 'info', 'Connection'); @@ -871,7 +890,7 @@ } if(this._has_http_headers){ - for(var prop in this._http_headers){ + for(prop in this._http_headers){ if(YAHOO.lang.hasOwnProperty(this._http_headers, prop)){ o.conn.setRequestHeader(prop, this._http_headers[prop]); YAHOO.log('HTTP header ' + prop + ' set with value of ' + this._http_headers[prop], 'info', 'Connection'); @@ -912,8 +931,13 @@ */ setForm:function(formId, isUpload, secureUri) { + var oForm, oElement, oName, oValue, oDisabled, + hasSubmit = false, + data = [], item = 0, + i,len,j,jlen,opt; + this.resetFormState(); - var oForm; + if(typeof formId == 'string'){ // Determine if the argument is a form id or a form name. // Note form name usage is deprecated by supported @@ -938,7 +962,8 @@ if(isUpload){ // Create iframe in preparation for file upload. - var io = this.createFrame(secureUri?secureUri:null); + this.createFrame(secureUri?secureUri:null); + // Set form reference and file upload properties to true. this._isFormSubmit = true; this._isFileUpload = true; @@ -948,40 +973,46 @@ } - var oElement, oName, oValue, oDisabled; - var hasSubmit = false; - // Iterate over the form elements collection to construct the // label-value pairs. - for (var i=0; i -1) { + opt = oElement.options[oElement.selectedIndex]; + data[item++] = oName + encodeURIComponent( + (opt.attributes.value && opt.attributes.value.specified) ? opt.value : opt.text); + } + break; case 'select-multiple': - for(var j=0; j -1) { + for(j=oElement.selectedIndex, jlen=oElement.options.length; j'); // IE will throw a security exception in an SSL environment if the // iframe source is undefined. if(typeof secureUri == 'boolean'){ io.src = 'javascript:false'; } - else if(typeof secureURI == 'string'){ - // Deprecated - io.src = secureUri; - } } else{ io = document.createElement('iframe'); @@ -1088,15 +1114,16 @@ */ appendPostData:function(postData) { - var formElements = []; - var postMessage = postData.split('&'); - for(var i=0; i < postMessage.length; i++){ - var delimitPos = postMessage[i].indexOf('='); + var formElements = [], + postMessage = postData.split('&'), + i, delimitPos; + for(i=0; i < postMessage.length; i++){ + delimitPos = postMessage[i].indexOf('='); if(delimitPos != -1){ formElements[i] = document.createElement('input'); formElements[i].type = 'hidden'; - formElements[i].name = postMessage[i].substring(0,delimitPos); - formElements[i].value = postMessage[i].substring(delimitPos+1); + formElements[i].name = decodeURIComponent(postMessage[i].substring(0,delimitPos)); + formElements[i].value = decodeURIComponent(postMessage[i].substring(delimitPos+1)); this._formNode.appendChild(formElements[i]); } } @@ -1120,10 +1147,12 @@ // Each iframe has an id prefix of "yuiIO" followed // by the unique transaction id. - var frameId = 'yuiIO' + o.tId; - var uploadEncoding = 'multipart/form-data'; - var io = document.getElementById(frameId); - var oConn = this; + var frameId = 'yuiIO' + o.tId, + uploadEncoding = 'multipart/form-data', + io = document.getElementById(frameId), + oConn = this, + args = (callback && callback.argument)?callback.argument:null, + oElements,i,prop,obj; // Track original HTML form attribute values. var rawFormAttributes = @@ -1139,7 +1168,7 @@ this._formNode.setAttribute('method', 'POST'); this._formNode.setAttribute('target', frameId); - if(this._formNode.encoding){ + if(YAHOO.env.ua.ie){ // IE does not respect property enctype for HTML forms. // Instead it uses the property - "encoding". this._formNode.setAttribute('encoding', uploadEncoding); @@ -1149,18 +1178,18 @@ } if(postData){ - var oElements = this.appendPostData(postData); + oElements = this.appendPostData(postData); } // Start file upload. this._formNode.submit(); // Fire global custom event -- startEvent - this.startEvent.fire(o); + this.startEvent.fire(o, args); if(o.startEvent){ // Fire transaction custom event -- startEvent - o.startEvent.fire(o); + o.startEvent.fire(o, args); } // Start polling if a callback is present and the timeout @@ -1171,14 +1200,14 @@ // Remove HTML elements created by appendPostData if(oElements && oElements.length > 0){ - for(var i=0; i < oElements.length; i++){ + for(i=0; i < oElements.length; i++){ this._formNode.removeChild(oElements[i]); } } // Restore HTML form attributes to their original // values prior to file upload. - for(var prop in rawFormAttributes){ + for(prop in rawFormAttributes){ if(YAHOO.lang.hasOwnProperty(rawFormAttributes, prop)){ if(rawFormAttributes[prop]){ this._formNode.setAttribute(prop, rawFormAttributes[prop]); @@ -1203,16 +1232,17 @@ } // Fire global custom event -- completeEvent - oConn.completeEvent.fire(o); + oConn.completeEvent.fire(o, args); if(o.completeEvent){ // Fire transaction custom event -- completeEvent - o.completeEvent.fire(o); + o.completeEvent.fire(o, args); } - var obj = {}; - obj.tId = o.tId; - obj.argument = callback.argument; + obj = { + tId : o.tId, + argument : callback.argument + }; try { @@ -1234,23 +1264,16 @@ } } - // Fire global custom event -- completeEvent + // Fire global custom event -- uploadEvent oConn.uploadEvent.fire(obj); if(o.uploadEvent){ - // Fire transaction custom event -- completeEvent + // Fire transaction custom event -- uploadEvent o.uploadEvent.fire(obj); } - if(YAHOO.util.Event){ - YAHOO.util.Event.removeListener(io, "load", uploadCallback); - } - else if(window.detachEvent){ - io.detachEvent('onload', uploadCallback); - } - else{ - io.removeEventListener('load', uploadCallback, false); - } + YAHOO.util.Event.removeListener(io, "load", uploadCallback); + setTimeout( function(){ document.body.removeChild(io); @@ -1260,15 +1283,7 @@ }; // Bind the onload handler to the iframe to detect the file upload response. - if(YAHOO.util.Event){ - YAHOO.util.Event.addListener(io, "load", uploadCallback); - } - else if(window.attachEvent){ - io.attachEvent('onload', uploadCallback); - } - else{ - io.addEventListener('load', uploadCallback, false); - } + YAHOO.util.Event.addListener(io, "load", uploadCallback); }, /** @@ -1284,8 +1299,10 @@ abort:function(o, callback, isTimeout) { var abortStatus; + var args = (callback && callback.argument)?callback.argument:null; - if(o.conn){ + + if(o && o.conn){ if(this.isCallInProgress(o)){ // Issue abort request o.conn.abort(); @@ -1301,11 +1318,14 @@ abortStatus = true; } } - else if(o.isUpload === true){ + else if(o && o.isUpload === true){ var frameId = 'yuiIO' + o.tId; var io = document.getElementById(frameId); if(io){ + // Remove all listeners on the iframe prior to + // its destruction. + YAHOO.util.Event.removeListener(io, "load"); // Destroy the iframe facilitating the transaction. document.body.removeChild(io); YAHOO.log('File upload iframe destroyed. Id is:' + frameId, 'info', 'Connection'); @@ -1324,26 +1344,22 @@ if(abortStatus === true){ // Fire global custom event -- abortEvent - this.abortEvent.fire(o); + this.abortEvent.fire(o, args); if(o.abortEvent){ // Fire transaction custom event -- abortEvent - o.abortEvent.fire(o); + o.abortEvent.fire(o, args); } this.handleTransactionResponse(o, callback, true); YAHOO.log('Transaction ' + o.tId + ' aborted.', 'info', 'Connection'); } - else{ - YAHOO.log('Transaction ' + o.tId + ' abort call failed. Connection object no longer exists.', 'warn', 'Connection'); - } return abortStatus; }, /** - * Public method to check if the transaction is still being processed. - * + * @description Determines if the transaction is still being processed. * @method isCallInProgress * @public * @static @@ -1376,14 +1392,15 @@ */ releaseObject:function(o) { - //dereference the XHR instance. - if(o.conn){ + if(o && o.conn){ + //dereference the XHR instance. o.conn = null; + + YAHOO.log('Connection object for transaction ' + o.tId + ' destroyed.', 'info', 'Connection'); + + //dereference the connection object. + o = null; } - YAHOO.log('Connection object for transaction ' + o.tId + ' destroyed.', 'info', 'Connection'); - //dereference the connection object. - o = null; } }; - -YAHOO.register("connection", YAHOO.util.Connect, {version: "2.3.0", build: "442"}); +YAHOO.register("connection", YAHOO.util.Connect, {version: "2.7.0", build: "1799"});