Example #1
0
  // element: null,
  // children: null,

  // isInDOM: false,
  // htmlListeners: null,

  /**
   * Description of constructor.
   * @class Short description of class.
   * Long Description of class.
   * @extends display.DisplayObject
   * @constructs
   * @param
   */
  constructor()
  {
    super();

    // Determine what the element is
    if(arguments[1] != undefined) {
      if(typeof arguments[1] == "string") {
        this.element = new Element(arguments[1]);
      } else {
        this.element = arguments[1];
      }
    } else {
      this.element = new Element('div');
    }

    if(this.element == undefined) {
      // TODO: throw error?
    }

    this.htmlListeners = {};
    this.children = new Array();

    // Wrapping element functions
    this.writeAttribute   = Bind(this.element.writeAttribute, this.element);
    this.readAttribute     = Bind(this.element.readAttribute, this.element);
    this.hide         = Bind(this.element.hide, this.element);
    this.show         = Bind(this.element.show, this.element);

  }
Example #2
0
  request(url) {
    this.url = url;
    this.method = this.options.method;
    var params = isString(this.options.parameters) ?
          this.options.parameters :
          toQueryString(this.options.parameters);

    if (!include(['get', 'post'], this.method)) {
      params += (params ? '&' : '') + "_method=" + this.method;
      this.method = 'post';
    }

    if (params && this.method === 'get') {
      this.url += (include(this.url, '?') ? '&' : '?') + params;
    }

    this.parameters = Utils.StringToQueryParams(params);

    try {
      var response = new Response(this);
      if (this.options.onCreate) this.options.onCreate(response);
      Responders.dispatch('onCreate', this, response);

      this.transport.open(this.method.toUpperCase(), this.url,
        this.options.asynchronous);

      if (this.options.asynchronous) Utils.Defer(this.respondToReadyState, this, 1);

      this.transport.onreadystatechange = Utils.Bind(this.onStateChange, this);
      this.setRequestHeaders();

      this.body = this.method == 'post' ? (this.options.postBody || params) : null;
      this.transport.send(this.body);

      /* Force Firefox to handle ready state 4 for synchronous requests */
      if (!this.options.asynchronous && this.transport.overrideMimeType)
        this.onStateChange();

    }
    catch (e) {
      this.dispatchException(e);
    }
  }