[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/2in3/2.9.0/build/yui2-connectioncore/ -> yui2-connectioncore.js (source)

   1  YUI.add('yui2-connectioncore', function(Y) {
   2      var YAHOO    = Y.YUI2;
   3      /*
   4  Copyright (c) 2011, Yahoo! Inc. All rights reserved.
   5  Code licensed under the BSD License:
   6  http://developer.yahoo.com/yui/license.html
   7  version: 2.9.0
   8  */
   9  /**
  10   * The Connection Manager provides a simplified interface to the XMLHttpRequest
  11   * object.  It handles cross-browser instantiantion of XMLHttpRequest, negotiates the
  12   * interactive states and server response, returning the results to a pre-defined
  13   * callback you create.
  14   *
  15   * @namespace YAHOO.util
  16   * @module connection
  17   * @requires yahoo
  18   * @requires event
  19   */
  20  
  21  /**
  22   * The Connection Manager singleton provides methods for creating and managing
  23   * asynchronous transactions.
  24   *
  25   * @class YAHOO.util.Connect
  26   */
  27  
  28  YAHOO.util.Connect =
  29  {
  30    /**
  31     * @description Array of MSFT ActiveX ids for XMLHttpRequest.
  32     * @property _msxml_progid
  33     * @private
  34     * @static
  35     * @type array
  36     */
  37      _msxml_progid:[
  38          'Microsoft.XMLHTTP',
  39          'MSXML2.XMLHTTP.3.0',
  40          'MSXML2.XMLHTTP'
  41          ],
  42  
  43    /**
  44     * @description Object literal of HTTP header(s)
  45     * @property _http_header
  46     * @private
  47     * @static
  48     * @type object
  49     */
  50      _http_headers:{},
  51  
  52    /**
  53     * @description Determines if HTTP headers are set.
  54     * @property _has_http_headers
  55     * @private
  56     * @static
  57     * @type boolean
  58     */
  59      _has_http_headers:false,
  60  
  61   /**
  62    * @description Determines if a default header of
  63    * Content-Type of 'application/x-www-form-urlencoded'
  64    * will be added to any client HTTP headers sent for POST
  65    * transactions.
  66    * @property _use_default_post_header
  67    * @private
  68    * @static
  69    * @type boolean
  70    */
  71      _use_default_post_header:true,
  72  
  73   /**
  74    * @description The default header used for POST transactions.
  75    * @property _default_post_header
  76    * @private
  77    * @static
  78    * @type boolean
  79    */
  80      _default_post_header:'application/x-www-form-urlencoded; charset=UTF-8',
  81  
  82   /**
  83    * @description The default header used for transactions involving the
  84    * use of HTML forms.
  85    * @property _default_form_header
  86    * @private
  87    * @static
  88    * @type boolean
  89    */
  90      _default_form_header:'application/x-www-form-urlencoded',
  91  
  92   /**
  93    * @description Determines if a default header of
  94    * 'X-Requested-With: XMLHttpRequest'
  95    * will be added to each transaction.
  96    * @property _use_default_xhr_header
  97    * @private
  98    * @static
  99    * @type boolean
 100    */
 101      _use_default_xhr_header:true,
 102  
 103   /**
 104    * @description The default header value for the label
 105    * "X-Requested-With".  This is sent with each
 106    * transaction, by default, to identify the
 107    * request as being made by YUI Connection Manager.
 108    * @property _default_xhr_header
 109    * @private
 110    * @static
 111    * @type boolean
 112    */
 113      _default_xhr_header:'XMLHttpRequest',
 114  
 115   /**
 116    * @description Determines if custom, default headers
 117    * are set for each transaction.
 118    * @property _has_default_header
 119    * @private
 120    * @static
 121    * @type boolean
 122    */
 123      _has_default_headers:true,
 124  
 125   /**
 126     * @description Property modified by setForm() to determine if the data
 127     * should be submitted as an HTML form.
 128     * @property _isFormSubmit
 129     * @private
 130     * @static
 131     * @type boolean
 132     */
 133      _isFormSubmit:false,
 134  
 135   /**
 136    * @description Determines if custom, default headers
 137    * are set for each transaction.
 138    * @property _has_default_header
 139    * @private
 140    * @static
 141    * @type boolean
 142    */
 143      _default_headers:{},
 144  
 145   /**
 146    * @description Collection of polling references to the polling mechanism in handleReadyState.
 147    * @property _poll
 148    * @private
 149    * @static
 150    * @type object
 151    */
 152      _poll:{},
 153  
 154   /**
 155    * @description Queue of timeout values for each transaction callback with a defined timeout value.
 156    * @property _timeOut
 157    * @private
 158    * @static
 159    * @type object
 160    */
 161      _timeOut:{},
 162  
 163    /**
 164     * @description The polling frequency, in milliseconds, for HandleReadyState.
 165     * when attempting to determine a transaction's XHR readyState.
 166     * The default is 50 milliseconds.
 167     * @property _polling_interval
 168     * @private
 169     * @static
 170     * @type int
 171     */
 172       _polling_interval:50,
 173  
 174    /**
 175     * @description A transaction counter that increments the transaction id for each transaction.
 176     * @property _transaction_id
 177     * @private
 178     * @static
 179     * @type int
 180     */
 181       _transaction_id:0,
 182  
 183    /**
 184     * @description Custom event that fires at the start of a transaction
 185     * @property startEvent
 186     * @private
 187     * @static
 188     * @type CustomEvent
 189     */
 190      startEvent: new YAHOO.util.CustomEvent('start'),
 191  
 192    /**
 193     * @description Custom event that fires when a transaction response has completed.
 194     * @property completeEvent
 195     * @private
 196     * @static
 197     * @type CustomEvent
 198     */
 199      completeEvent: new YAHOO.util.CustomEvent('complete'),
 200  
 201    /**
 202     * @description Custom event that fires when handleTransactionResponse() determines a
 203     * response in the HTTP 2xx range.
 204     * @property successEvent
 205     * @private
 206     * @static
 207     * @type CustomEvent
 208     */
 209      successEvent: new YAHOO.util.CustomEvent('success'),
 210  
 211    /**
 212     * @description Custom event that fires when handleTransactionResponse() determines a
 213     * response in the HTTP 4xx/5xx range.
 214     * @property failureEvent
 215     * @private
 216     * @static
 217     * @type CustomEvent
 218     */
 219      failureEvent: new YAHOO.util.CustomEvent('failure'),
 220  
 221    /**
 222     * @description Custom event that fires when a transaction is successfully aborted.
 223     * @property abortEvent
 224     * @private
 225     * @static
 226     * @type CustomEvent
 227     */
 228      abortEvent: new YAHOO.util.CustomEvent('abort'),
 229  
 230    /**
 231     * @description A reference table that maps callback custom events members to its specific
 232     * event name.
 233     * @property _customEvents
 234     * @private
 235     * @static
 236     * @type object
 237     */
 238      _customEvents:
 239      {
 240          onStart:['startEvent', 'start'],
 241          onComplete:['completeEvent', 'complete'],
 242          onSuccess:['successEvent', 'success'],
 243          onFailure:['failureEvent', 'failure'],
 244          onUpload:['uploadEvent', 'upload'],
 245          onAbort:['abortEvent', 'abort']
 246      },
 247  
 248    /**
 249     * @description Member to add an ActiveX id to the existing xml_progid array.
 250     * In the event(unlikely) a new ActiveX id is introduced, it can be added
 251     * without internal code modifications.
 252     * @method setProgId
 253     * @public
 254     * @static
 255     * @param {string} id The ActiveX id to be added to initialize the XHR object.
 256     * @return void
 257     */
 258      setProgId:function(id)
 259      {
 260          this._msxml_progid.unshift(id);
 261      },
 262  
 263    /**
 264     * @description Member to override the default POST header.
 265     * @method setDefaultPostHeader
 266     * @public
 267     * @static
 268     * @param {boolean} b Set and use default header - true or false .
 269     * @return void
 270     */
 271      setDefaultPostHeader:function(b)
 272      {
 273          if(typeof b == 'string'){
 274              this._default_post_header = b;
 275              this._use_default_post_header = true;
 276  
 277          }
 278          else if(typeof b == 'boolean'){
 279              this._use_default_post_header = b;
 280          }
 281      },
 282  
 283    /**
 284     * @description Member to override the default transaction header..
 285     * @method setDefaultXhrHeader
 286     * @public
 287     * @static
 288     * @param {boolean} b Set and use default header - true or false .
 289     * @return void
 290     */
 291      setDefaultXhrHeader:function(b)
 292      {
 293          if(typeof b == 'string'){
 294              this._default_xhr_header = b;
 295          }
 296          else{
 297              this._use_default_xhr_header = b;
 298          }
 299      },
 300  
 301    /**
 302     * @description Member to modify the default polling interval.
 303     * @method setPollingInterval
 304     * @public
 305     * @static
 306     * @param {int} i The polling interval in milliseconds.
 307     * @return void
 308     */
 309      setPollingInterval:function(i)
 310      {
 311          if(typeof i == 'number' && isFinite(i)){
 312              this._polling_interval = i;
 313          }
 314      },
 315  
 316    /**
 317     * @description Instantiates a XMLHttpRequest object and returns an object with two properties:
 318     * the XMLHttpRequest instance and the transaction id.
 319     * @method createXhrObject
 320     * @private
 321     * @static
 322     * @param {int} transactionId Property containing the transaction id for this transaction.
 323     * @return object
 324     */
 325      createXhrObject:function(transactionId)
 326      {
 327          var obj,http,i;
 328          try
 329          {
 330              // Instantiates XMLHttpRequest in non-IE browsers and assigns to http.
 331              http = new XMLHttpRequest();
 332              //  Object literal with http and tId properties
 333              obj = { conn:http, tId:transactionId, xhr: true };
 334          }
 335          catch(e)
 336          {
 337              for(i=0; i<this._msxml_progid.length; ++i){
 338                  try
 339                  {
 340                      // Instantiates XMLHttpRequest for IE and assign to http
 341                      http = new ActiveXObject(this._msxml_progid[i]);
 342                      //  Object literal with conn and tId properties
 343                      obj = { conn:http, tId:transactionId, xhr: true };
 344                      break;
 345                  }
 346                  catch(e1){}
 347              }
 348          }
 349          finally
 350          {
 351              return obj;
 352          }
 353      },
 354  
 355    /**
 356     * @description This method is called by asyncRequest to create a
 357     * valid connection object for the transaction.  It also passes a
 358     * transaction id and increments the transaction id counter.
 359     * @method getConnectionObject
 360     * @private
 361     * @static
 362     * @return {object}
 363     */
 364      getConnectionObject:function(t)
 365      {
 366          var o, tId = this._transaction_id;
 367  
 368          try
 369          {
 370              if(!t){
 371                  o = this.createXhrObject(tId);
 372              }
 373              else{
 374                  o = {tId:tId};
 375                  if(t==='xdr'){
 376                      o.conn = this._transport;
 377                      o.xdr = true;
 378                  }
 379                  else if(t==='upload'){
 380                      o.upload = true;
 381                  }
 382              }
 383  
 384              if(o){
 385                  this._transaction_id++;
 386              }
 387          }
 388          catch(e){}
 389          return o;
 390      },
 391  
 392    /**
 393     * @description Method for initiating an asynchronous request via the XHR object.
 394     * @method asyncRequest
 395     * @public
 396     * @static
 397     * @param {string} method HTTP transaction method
 398     * @param {string} uri Fully qualified path of resource
 399     * @param {callback} callback User-defined callback function or object
 400     * @param {string} postData POST body
 401     * @return {object} Returns the connection object
 402     */
 403      asyncRequest:function(method, uri, callback, postData)
 404      {
 405          var args = callback&&callback.argument?callback.argument:null,
 406              YCM = this,
 407              o, t;
 408  
 409          if(this._isFileUpload){
 410              t = 'upload';
 411          }
 412          else if(callback && callback.xdr){
 413              t = 'xdr';
 414          }
 415  
 416          o = this.getConnectionObject(t);
 417          if(!o){
 418              return null;
 419          }
 420          else{
 421  
 422              // Intialize any transaction-specific custom events, if provided.
 423              if(callback && callback.customevents){
 424                  this.initCustomEvents(o, callback);
 425              }
 426  
 427              if(this._isFormSubmit){
 428                  if(this._isFileUpload){
 429                      window.setTimeout(function(){YCM.uploadFile(o, callback, uri, postData);}, 10);
 430                      return o;
 431                  }
 432  
 433                  // If the specified HTTP method is GET, setForm() will return an
 434                  // encoded string that is concatenated to the uri to
 435                  // create a querystring.
 436                  if(method.toUpperCase() == 'GET'){
 437                      if(this._sFormData.length !== 0){
 438                          // If the URI already contains a querystring, append an ampersand
 439                          // and then concatenate _sFormData to the URI.
 440                          uri += ((uri.indexOf('?') == -1)?'?':'&') + this._sFormData;
 441                      }
 442                  }
 443                  else if(method.toUpperCase() == 'POST'){
 444                      // If POST data exist in addition to the HTML form data,
 445                      // it will be concatenated to the form data.
 446                      postData = postData?this._sFormData + "&" + postData:this._sFormData;
 447                  }
 448              }
 449  
 450              if(method.toUpperCase() == 'GET' && (callback && callback.cache === false)){
 451                  // If callback.cache is defined and set to false, a
 452                  // timestamp value will be added to the querystring.
 453                  uri += ((uri.indexOf('?') == -1)?'?':'&') + "rnd=" + new Date().valueOf().toString();
 454              }
 455  
 456              // Each transaction will automatically include a custom header of
 457              // "X-Requested-With: XMLHttpRequest" to identify the request as
 458              // having originated from Connection Manager.
 459              if(this._use_default_xhr_header){
 460                  if(!this._default_headers['X-Requested-With']){
 461                      this.initHeader('X-Requested-With', this._default_xhr_header, true);
 462                  }
 463              }
 464  
 465              //If the transaction method is POST and the POST header value is set to true
 466              //or a custom value, initalize the Content-Type header to this value.
 467              if((method.toUpperCase() === 'POST' && this._use_default_post_header) && this._isFormSubmit === false){
 468                  this.initHeader('Content-Type', this._default_post_header);
 469              }
 470  
 471              if(o.xdr){
 472                  this.xdr(o, method, uri, callback, postData);
 473                  return o;
 474              }
 475  
 476              o.conn.open(method, uri, true);
 477              //Initialize all default and custom HTTP headers,
 478              if(this._has_default_headers || this._has_http_headers){
 479                  this.setHeader(o);
 480              }
 481  
 482              this.handleReadyState(o, callback);
 483              o.conn.send(postData || '');
 484  
 485              // Reset the HTML form data and state properties as
 486              // soon as the data are submitted.
 487              if(this._isFormSubmit === true){
 488                  this.resetFormState();
 489              }
 490  
 491              // Fire global custom event -- startEvent
 492              this.startEvent.fire(o, args);
 493  
 494              if(o.startEvent){
 495                  // Fire transaction custom event -- startEvent
 496                  o.startEvent.fire(o, args);
 497              }
 498  
 499              return o;
 500          }
 501      },
 502  
 503    /**
 504     * @description This method creates and subscribes custom events,
 505     * specific to each transaction
 506     * @method initCustomEvents
 507     * @private
 508     * @static
 509     * @param {object} o The connection object
 510     * @param {callback} callback The user-defined callback object
 511     * @return {void}
 512     */
 513      initCustomEvents:function(o, callback)
 514      {
 515          var prop;
 516          // Enumerate through callback.customevents members and bind/subscribe
 517          // events that match in the _customEvents table.
 518          for(prop in callback.customevents){
 519              if(this._customEvents[prop][0]){
 520                  // Create the custom event
 521                  o[this._customEvents[prop][0]] = new YAHOO.util.CustomEvent(this._customEvents[prop][1], (callback.scope)?callback.scope:null);
 522  
 523                  // Subscribe the custom event
 524                  o[this._customEvents[prop][0]].subscribe(callback.customevents[prop]);
 525              }
 526          }
 527      },
 528  
 529    /**
 530     * @description This method serves as a timer that polls the XHR object's readyState
 531     * property during a transaction, instead of binding a callback to the
 532     * onreadystatechange event.  Upon readyState 4, handleTransactionResponse
 533     * will process the response, and the timer will be cleared.
 534     * @method handleReadyState
 535     * @private
 536     * @static
 537     * @param {object} o The connection object
 538     * @param {callback} callback The user-defined callback object
 539     * @return {void}
 540     */
 541  
 542      handleReadyState:function(o, callback)
 543  
 544      {
 545          var oConn = this,
 546              args = (callback && callback.argument)?callback.argument:null;
 547  
 548          if(callback && callback.timeout){
 549              this._timeOut[o.tId] = window.setTimeout(function(){ oConn.abort(o, callback, true); }, callback.timeout);
 550          }
 551  
 552          this._poll[o.tId] = window.setInterval(
 553              function(){
 554                  if(o.conn && o.conn.readyState === 4){
 555  
 556                      // Clear the polling interval for the transaction
 557                      // and remove the reference from _poll.
 558                      window.clearInterval(oConn._poll[o.tId]);
 559                      delete oConn._poll[o.tId];
 560  
 561                      if(callback && callback.timeout){
 562                          window.clearTimeout(oConn._timeOut[o.tId]);
 563                          delete oConn._timeOut[o.tId];
 564                      }
 565  
 566                      // Fire global custom event -- completeEvent
 567                      oConn.completeEvent.fire(o, args);
 568  
 569                      if(o.completeEvent){
 570                          // Fire transaction custom event -- completeEvent
 571                          o.completeEvent.fire(o, args);
 572                      }
 573  
 574                      oConn.handleTransactionResponse(o, callback);
 575                  }
 576              }
 577          ,this._polling_interval);
 578      },
 579  
 580    /**
 581     * @description This method attempts to interpret the server response and
 582     * determine whether the transaction was successful, or if an error or
 583     * exception was encountered.
 584     * @method handleTransactionResponse
 585     * @private
 586     * @static
 587     * @param {object} o The connection object
 588     * @param {object} callback The user-defined callback object
 589     * @param {boolean} isAbort Determines if the transaction was terminated via abort().
 590     * @return {void}
 591     */
 592      handleTransactionResponse:function(o, callback, isAbort)
 593      {
 594          var httpStatus, responseObject,
 595              args = (callback && callback.argument)?callback.argument:null,
 596              xdrS = (o.r && o.r.statusText === 'xdr:success')?true:false,
 597              xdrF = (o.r && o.r.statusText === 'xdr:failure')?true:false,
 598              xdrA = isAbort;
 599  
 600          try
 601          {
 602              if((o.conn.status !== undefined && o.conn.status !== 0) || xdrS){
 603                  // XDR requests will not have HTTP status defined. The
 604                  // statusText property will define the response status
 605                  // set by the Flash transport.
 606                  httpStatus = o.conn.status;
 607              }
 608              else if(xdrF && !xdrA){
 609                  // Set XDR transaction failure to a status of 0, which
 610                  // resolves as an HTTP failure, instead of an exception.
 611                  httpStatus = 0;
 612              }
 613              else{
 614                  httpStatus = 13030;
 615              }
 616          }
 617          catch(e){
 618  
 619               // 13030 is a custom code to indicate the condition -- in Mozilla/FF --
 620               // when the XHR object's status and statusText properties are
 621               // unavailable, and a query attempt throws an exception.
 622              httpStatus = 13030;
 623          }
 624  
 625          if((httpStatus >= 200 && httpStatus < 300) || httpStatus === 1223 || xdrS){
 626              responseObject = o.xdr ? o.r : this.createResponseObject(o, args);
 627              if(callback && callback.success){
 628                  if(!callback.scope){
 629                      callback.success(responseObject);
 630                  }
 631                  else{
 632                      // If a scope property is defined, the callback will be fired from
 633                      // the context of the object.
 634                      callback.success.apply(callback.scope, [responseObject]);
 635                  }
 636              }
 637  
 638              // Fire global custom event -- successEvent
 639              this.successEvent.fire(responseObject);
 640  
 641              if(o.successEvent){
 642                  // Fire transaction custom event -- successEvent
 643                  o.successEvent.fire(responseObject);
 644              }
 645          }
 646          else{
 647              switch(httpStatus){
 648                  // The following cases are wininet.dll error codes that may be encountered.
 649                  case 12002: // Server timeout
 650                  case 12029: // 12029 to 12031 correspond to dropped connections.
 651                  case 12030:
 652                  case 12031:
 653                  case 12152: // Connection closed by server.
 654                  case 13030: // See above comments for variable status.
 655                      // XDR transactions will not resolve to this case, since the
 656                      // response object is already built in the xdr response.
 657                      responseObject = this.createExceptionObject(o.tId, args, (isAbort?isAbort:false));
 658                      if(callback && callback.failure){
 659                          if(!callback.scope){
 660                              callback.failure(responseObject);
 661                          }
 662                          else{
 663                              callback.failure.apply(callback.scope, [responseObject]);
 664                          }
 665                      }
 666  
 667                      break;
 668                  default:
 669                      responseObject = (o.xdr) ? o.response : this.createResponseObject(o, args);
 670                      if(callback && callback.failure){
 671                          if(!callback.scope){
 672                              callback.failure(responseObject);
 673                          }
 674                          else{
 675                              callback.failure.apply(callback.scope, [responseObject]);
 676                          }
 677                      }
 678              }
 679  
 680              // Fire global custom event -- failureEvent
 681              this.failureEvent.fire(responseObject);
 682  
 683              if(o.failureEvent){
 684                  // Fire transaction custom event -- failureEvent
 685                  o.failureEvent.fire(responseObject);
 686              }
 687  
 688          }
 689  
 690          this.releaseObject(o);
 691          responseObject = null;
 692      },
 693  
 694    /**
 695     * @description This method evaluates the server response, creates and returns the results via
 696     * its properties.  Success and failure cases will differ in the response
 697     * object's property values.
 698     * @method createResponseObject
 699     * @private
 700     * @static
 701     * @param {object} o The connection object
 702     * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback
 703     * @return {object}
 704     */
 705      createResponseObject:function(o, callbackArg)
 706      {
 707          var obj = {}, headerObj = {},
 708              i, headerStr, header, delimitPos;
 709  
 710          try
 711          {
 712              headerStr = o.conn.getAllResponseHeaders();
 713              header = headerStr.split('\n');
 714              for(i=0; i<header.length; i++){
 715                  delimitPos = header[i].indexOf(':');
 716                  if(delimitPos != -1){
 717                      headerObj[header[i].substring(0,delimitPos)] = YAHOO.lang.trim(header[i].substring(delimitPos+2));
 718                  }
 719              }
 720          }
 721          catch(e){}
 722  
 723          obj.tId = o.tId;
 724          // Normalize IE's response to HTTP 204 when Win error 1223.
 725          obj.status = (o.conn.status == 1223)?204:o.conn.status;
 726          // Normalize IE's statusText to "No Content" instead of "Unknown".
 727          obj.statusText = (o.conn.status == 1223)?"No Content":o.conn.statusText;
 728          obj.getResponseHeader = headerObj;
 729          obj.getAllResponseHeaders = headerStr;
 730          obj.responseText = o.conn.responseText;
 731          obj.responseXML = o.conn.responseXML;
 732  
 733          if(callbackArg){
 734              obj.argument = callbackArg;
 735          }
 736  
 737          return obj;
 738      },
 739  
 740    /**
 741     * @description If a transaction cannot be completed due to dropped or closed connections,
 742     * there may be not be enough information to build a full response object.
 743     * The failure callback will be fired and this specific condition can be identified
 744     * by a status property value of 0.
 745     *
 746     * If an abort was successful, the status property will report a value of -1.
 747     *
 748     * @method createExceptionObject
 749     * @private
 750     * @static
 751     * @param {int} tId The Transaction Id
 752     * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback
 753     * @param {boolean} isAbort Determines if the exception case is caused by a transaction abort
 754     * @return {object}
 755     */
 756      createExceptionObject:function(tId, callbackArg, isAbort)
 757      {
 758          var COMM_CODE = 0,
 759              COMM_ERROR = 'communication failure',
 760              ABORT_CODE = -1,
 761              ABORT_ERROR = 'transaction aborted',
 762              obj = {};
 763  
 764          obj.tId = tId;
 765          if(isAbort){
 766              obj.status = ABORT_CODE;
 767              obj.statusText = ABORT_ERROR;
 768          }
 769          else{
 770              obj.status = COMM_CODE;
 771              obj.statusText = COMM_ERROR;
 772          }
 773  
 774          if(callbackArg){
 775              obj.argument = callbackArg;
 776          }
 777  
 778          return obj;
 779      },
 780  
 781    /**
 782     * @description Method that initializes the custom HTTP headers for the each transaction.
 783     * @method initHeader
 784     * @public
 785     * @static
 786     * @param {string} label The HTTP header label
 787     * @param {string} value The HTTP header value
 788     * @param {string} isDefault Determines if the specific header is a default header
 789     * automatically sent with each transaction.
 790     * @return {void}
 791     */
 792      initHeader:function(label, value, isDefault)
 793      {
 794          var headerObj = (isDefault)?this._default_headers:this._http_headers;
 795  
 796          headerObj[label] = value;
 797          if(isDefault){
 798              this._has_default_headers = true;
 799          }
 800          else{
 801              this._has_http_headers = true;
 802          }
 803      },
 804  
 805  
 806    /**
 807     * @description Accessor that sets the HTTP headers for each transaction.
 808     * @method setHeader
 809     * @private
 810     * @static
 811     * @param {object} o The connection object for the transaction.
 812     * @return {void}
 813     */
 814      setHeader:function(o)
 815      {
 816          var prop;
 817          if(this._has_default_headers){
 818              for(prop in this._default_headers){
 819                  if(YAHOO.lang.hasOwnProperty(this._default_headers, prop)){
 820                      o.conn.setRequestHeader(prop, this._default_headers[prop]);
 821                  }
 822              }
 823          }
 824  
 825          if(this._has_http_headers){
 826              for(prop in this._http_headers){
 827                  if(YAHOO.lang.hasOwnProperty(this._http_headers, prop)){
 828                      o.conn.setRequestHeader(prop, this._http_headers[prop]);
 829                  }
 830              }
 831  
 832              this._http_headers = {};
 833              this._has_http_headers = false;
 834          }
 835      },
 836  
 837    /**
 838     * @description Resets the default HTTP headers object
 839     * @method resetDefaultHeaders
 840     * @public
 841     * @static
 842     * @return {void}
 843     */
 844      resetDefaultHeaders:function(){
 845          this._default_headers = {};
 846          this._has_default_headers = false;
 847      },
 848  
 849    /**
 850     * @description Method to terminate a transaction, if it has not reached readyState 4.
 851     * @method abort
 852     * @public
 853     * @static
 854     * @param {object} o The connection object returned by asyncRequest.
 855     * @param {object} callback  User-defined callback object.
 856     * @param {string} isTimeout boolean to indicate if abort resulted from a callback timeout.
 857     * @return {boolean}
 858     */
 859      abort:function(o, callback, isTimeout)
 860      {
 861          var abortStatus,
 862              args = (callback && callback.argument)?callback.argument:null;
 863              o = o || {};
 864  
 865          if(o.conn){
 866              if(o.xhr){
 867                  if(this.isCallInProgress(o)){
 868                      // Issue abort request
 869                      o.conn.abort();
 870  
 871                      window.clearInterval(this._poll[o.tId]);
 872                      delete this._poll[o.tId];
 873  
 874                      if(isTimeout){
 875                          window.clearTimeout(this._timeOut[o.tId]);
 876                          delete this._timeOut[o.tId];
 877                      }
 878  
 879                      abortStatus = true;
 880                  }
 881              }
 882              else if(o.xdr){
 883                  o.conn.abort(o.tId);
 884                  abortStatus = true;
 885              }
 886          }
 887          else if(o.upload){
 888              var frameId = 'yuiIO' + o.tId;
 889              var io = document.getElementById(frameId);
 890  
 891              if(io){
 892                  // Remove all listeners on the iframe prior to
 893                  // its destruction.
 894                  YAHOO.util.Event.removeListener(io, "load");
 895                  // Destroy the iframe facilitating the transaction.
 896                  document.body.removeChild(io);
 897  
 898                  if(isTimeout){
 899                      window.clearTimeout(this._timeOut[o.tId]);
 900                      delete this._timeOut[o.tId];
 901                  }
 902  
 903                  abortStatus = true;
 904              }
 905          }
 906          else{
 907              abortStatus = false;
 908          }
 909  
 910          if(abortStatus === true){
 911              // Fire global custom event -- abortEvent
 912              this.abortEvent.fire(o, args);
 913  
 914              if(o.abortEvent){
 915                  // Fire transaction custom event -- abortEvent
 916                  o.abortEvent.fire(o, args);
 917              }
 918  
 919              this.handleTransactionResponse(o, callback, true);
 920          }
 921  
 922          return abortStatus;
 923      },
 924  
 925    /**
 926     * @description Determines if the transaction is still being processed.
 927     * @method isCallInProgress
 928     * @public
 929     * @static
 930     * @param {object} o The connection object returned by asyncRequest
 931     * @return {boolean}
 932     */
 933      isCallInProgress:function(o)
 934      {
 935          o = o || {};
 936          // if the XHR object assigned to the transaction has not been dereferenced,
 937          // then check its readyState status.  Otherwise, return false.
 938          if(o.xhr && o.conn){
 939              return o.conn.readyState !== 4 && o.conn.readyState !== 0;
 940          }
 941          else if(o.xdr && o.conn){
 942              return o.conn.isCallInProgress(o.tId);
 943          }
 944          else if(o.upload === true){
 945              return document.getElementById('yuiIO' + o.tId)?true:false;
 946          }
 947          else{
 948              return false;
 949          }
 950      },
 951  
 952    /**
 953     * @description Dereference the XHR instance and the connection object after the transaction is completed.
 954     * @method releaseObject
 955     * @private
 956     * @static
 957     * @param {object} o The connection object
 958     * @return {void}
 959     */
 960      releaseObject:function(o)
 961      {
 962          if(o && o.conn){
 963              //dereference the XHR instance.
 964              o.conn = null;
 965  
 966  
 967              //dereference the connection object.
 968              o = null;
 969          }
 970      }
 971  };
 972  
 973  YAHOO.register("connection_core", YAHOO.util.Connect, {version: "2.9.0", build: "2800"});
 974  
 975  }, '2.9.0' ,{"requires": ["yui2-yahoo", "yui2-event"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1