share/docs.previews.js
function(el) {
  var mirrorEl = document.createElement('div');
  mirrorEl.className = 'preview-code';
  mirrorEl.style.position = 'absolute';
  mirrorEl.style.left = '-9999px';
  bodyEl.appendChild(mirrorEl);
  var maxHeight = parseInt(
    window.getComputedStyle(el).getPropertyValue('max-height'),
    10);
  var codeDidChange = function(ev) {
    mirrorEl.textContent = this.value + '\n';
    var height = mirrorEl.offsetHeight + 2; // Account for borders.
    if (height >= maxHeight) {
      this.style.overflow = 'auto';
    } else {
      this.style.overflow = 'hidden';
    }
    this.style.height = (mirrorEl.offsetHeight + 2) + 'px';
  };
  el.addEventListener('keypress', codeDidChange);
  el.addEventListener('keyup', codeDidChange);
  codeDidChange.call(el);
}
function(el) {
  var mirrorEl = document.createElement('div');
  mirrorEl.className = 'preview-code';
  mirrorEl.style.position = 'absolute';
  mirrorEl.style.left = '-9999px';
  bodyEl.appendChild(mirrorEl);
  var maxHeight = parseInt(
    window.getComputedStyle(el).getPropertyValue('max-height'),
    10);
  var codeDidChange = function(ev) {
    mirrorEl.textContent = this.value + '\n';
    var height = mirrorEl.offsetHeight + 2; // Account for borders.
    if (height >= maxHeight) {
      this.style.overflow = 'auto';
    } else {
      this.style.overflow = 'hidden';
    }
    this.style.height = (mirrorEl.offsetHeight + 2) + 'px';
  };
  el.addEventListener('keypress', codeDidChange);
  el.addEventListener('keyup', codeDidChange);
  codeDidChange.call(el);
}
function ( el ) { var mirrorEl = document . createElement ( 'div' ) ; mirrorEl . className = 'preview-code' ; mirrorEl . style . position = 'absolute' ; mirrorEl . style . left = '-9999px' ; bodyEl . appendChild ( mirrorEl ) ; var maxHeight = parseInt ( window . getComputedStyle ( el ) . getPropertyValue ( 'max-height' ) , 10 ) ; var codeDidChange = function ( ev ) { mirrorEl . textContent = this . value + '\n' ; var height = mirrorEl . offsetHeight + 2 ; // Account for borders. if ( height >= maxHeight ) { this . style . overflow = 'auto' ; } else { this . style . overflow = 'hidden' ; } this . style . height = ( mirrorEl . offsetHeight + 2 ) + 'px' ; } ; el . addEventListener ( 'keypress' , codeDidChange ) ; el . addEventListener ( 'keyup' , codeDidChange ) ; codeDidChange . call ( el ) ; }
Add an element with the same styles and content as the textarea to calculate the height of the textarea content.
Add an element with the same styles and content as the textarea to calculate the height of the textarea content .