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

Ticket #6465: crossbrowser_innertext.diff

File crossbrowser_innertext.diff, 2.4 kB (added by Caged, 3 years ago)

Preserves innerText as a property in Firefox

  • test/unit/dom.html

    old new  
    4747<div id="testlog"> </div> 
    4848 
    4949<div> 
    50   <table
     50  <table id="atable"
    5151    <tbody id="table"> 
    5252      <tr> 
    5353        <td>Data</td> 
     
    6262  </table> 
    6363</div> 
    6464 
     65<table> 
     66  <tr> 
     67    <td id="another_cell">This is a cell</td> 
     68    <td id="cell_script">This is <script>var i = 'some string'; </script> some inner text</td> 
     69  </tr> 
     70</table> 
     71 
    6572<p class="test">Test paragraph outside of container</p> 
    6673 
    6774<div id="container"> 
     
    551558      elem.scrollTo(); 
    552559      assertEqual(Position.page(elem)[1], 0);       
    553560      window.scrollTo(0, 0); 
     561    }}, 
     562     
     563    testInnerTextEmulation: function() {with(this) { 
     564      var cell = $('another_cell'); 
     565      $('testdiv').innerText = 'javascript loves prototype'; 
     566      assertEqual('javascript loves prototype', $('testdiv').innerText); 
     567      assertEqual('This is a cell', cell.innerText); 
     568      cell.innerText = 'some inner text'; 
     569      assertEqual('This is some inner text', $('cell_script').innerText); 
     570      assertEqual('some inner text', cell.innerText); 
    554571    }} 
    555572     
    556573  }, 'testlog'); 
  • src/prototype.js

    old new  
    33var Prototype = { 
    44  Version: '<%= PROTOTYPE_VERSION %>', 
    55  BrowserFeatures: { 
    6     XPath: !!document.evaluate 
     6    XPath: !!document.evaluate, 
     7    textContent: !!(typeof HTMLElement != 'undefined' &&  
     8                 typeof HTMLElement.prototype.__defineGetter__ == 'function') 
    79  }, 
    810   
    911  ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 
  • src/dom.js

    old new  
    2020  } 
    2121} 
    2222 
     23if(Prototype.BrowserFeatures.textContent) { 
     24  HTMLElement.prototype.__defineGetter__("innerText", function () { 
     25    return this.innerHTML.stripScripts().unescapeHTML().replace(/[\n\r\s]+/g, ' '); 
     26  }); 
     27   
     28  HTMLElement.prototype.__defineSetter__('innerText', function(text) { 
     29    this.textContent = text; 
     30  }); 
     31} 
     32 
     33 
    2334document.getElementsByClassName = function(className, parentElement) { 
    2435  if (Prototype.BrowserFeatures.XPath) { 
    2536    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";