Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7550 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Problems inserting TBODY in IE

Reported by: l0co Assigned to: Tobie
Priority: normal Milestone: 1.x
Component: Prototype Version: edge
Severity: normal Keywords: 1.5.2
Cc:

Description

I've encountered problem with inserting TR and TBODY to the table with Insertion.After object using Internet Explorer 6.0.2900.2180. When in Firefox everything works ok (using different part of code), performing following code simply doesn't work with IE:

<script language="JavaScript" type="text/javascript" src="prototype.js"></script>

<table id="t" border="1">
  <tbody id="row1">
    <tr id="tr1">
      <td>aa</td>
    </tr>
  </tbody>
</table>


<script language="JavaScript">
  function rm() {
    var child = document.getElementById('row1');
    new Insertion.After(child,'<tbody id="row2"><tr><td>22</td></tr></tbody>');
    //new Insertion.After(child,'<tr><td>11</td></tr>');
  }
</script>

<a href="#" onclick="rm()">test</a>

I've noticed that the author had the same problems as I, inserting separated condition for TBODY and TR element to the IE table in Abstract.Insertion.initialize, but his solutions doesn't work in this case (at least in my environment). The code doing this in prototype.js is below:

  ..
  (if we are in IE and we are inserting TBODY or TR)
  this.insertContent(this.contentFromAnonymousTable());
  ..

  contentFromAnonymousTable: function() {
    var div = document.createElement('div');
    div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>';
    return $A(div.childNodes[0].childNodes[0].childNodes);
  }

I don't understand exactly why such resolution has been implemented, but I've discovered that IE always inserts TBODY after table element and we are here too far in the childNodes to insert content into the source table. The following code works properly for my test sample, even for TR inserting (commented in the sample):

  contentFromAnonymousTable: function() {
    var div = document.createElement('div');
    div.innerHTML = '<table>' + this.content + '</table>';
    return $A(div.childNodes[0].childNodes);
  }

Can sombody explain what exactly is happening here? Interested thing is that when we are inserting just TR, and we check the name of the element returned from contentFromAnonymousTable, we get TBODY anyway.

Change History

03/24/07 21:33:26 changed by Tobie

  • summary changed from [PATCH] Inserting TBODY to the table with Insertion.After to Inserting TBODY to the table with Insertion.After.

05/03/07 02:12:03 changed by Tobie

  • keywords changed from prototype insertion tbody to 1.5.2.
  • owner changed from sam to Tobie.
  • summary changed from Inserting TBODY to the table with Insertion.After to Problems inserting TBODY in IE.

05/12/07 05:02:00 changed by sam

  • status changed from new to closed.
  • resolution set to fixed.

(In [6725]) Merge -r6634:HEAD from ../branches/dom.

* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]

* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]

* Make Element#readAttribute('title') work in Opera. [Tobie Langel]

* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]

* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]

* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohni?\196?\135, haraldmartin, Tobie Langel]

* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]